1

I have add to cart buttons like this:

<a href="{entry_id_path='weekend-courses/add-to-cart'}" >Book now</a>

'weekend-courses/add-to-cart' contains only this:

{if logged_out}
  {redirect='account/login/return/weekend-courses/'}
{/if}

{if logged_in}
  {exp:cartthrob:add_to_cart entry_id="{segment_3}" quantity="1" return="weekend-courses/checkout/{segment_3}"}
{/if}

Clicking the book now link adds an item to the cart and goes to weekend-courses/checkout/{segment_3} when I am logged-in AND when I am logged-out.

Changing to this

{if logged_out}
  {redirect='account/login/return/weekend-courses/'}
{/if}

{if logged_in}
  <p>Logged in</p>
{/if}

Works as expected.

Any ideas why this isn't working as expected?

2
  • Are you using pre-EE2.9? May 25, 2016 at 16:56
  • Nope. It's EE 2.11.1
    – Tim Print
    May 25, 2016 at 22:03

2 Answers 2

0

I'm almost positive this is a parse order issue with ExpressionEngine, not anything CartThrob can change. I agree with James's comment, that EE 2.9+ parse order might work better for this. You might consider adding your logic around the "book now" button, and using another template which just has "add to cart" logic.

0
0

Fixed this with Switchee

{exp:switchee variable = "global:member_id" parse="inward"} 
    {case value="1"}
        {exp:cartthrob:add_to_cart entry_id="{segment_3}" quantity="1" return="weekend-courses/checkout/{segment_3}"}
    {/case}
    {case value="0"}
        {redirect='account/login/return/weekend-courses/'}
    {/case}
{/exp:switchee}

That's working fine. Thanks for the suggestions James & Matt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.