I’m building a site where users can register as a member, and then purchase an online course with Simple Commerce. I thought I had the following query behaving as I needed and only show the course content in each template to members who had purchased the course, but now find that it only works if there is only one course. With the following query and one course, whose item_id is 4, if the member purchased the course, they can view the content of the template. If they have not purchased this course, but have purchased another one, they are redirected to their account page. And if they have not purchased any courses, they are redirected to the page where they can purchase a course.
All fine, but when I add a 2nd course, with item_id of 5, and the member has purchased both courses, the course content for the 2nd course does not display using the same query, but with the item_id changed to 5. Instead the member is redirected to their account page. So, the content of both courses display if the item_id is 4, but neither display if item_id is 5.
{exp:query sql="SELECT * FROM exp_simple_commerce_purchases
JOIN exp_simple_commerce_items ON exp_simple_commerce_items.item_id = exp_simple_commerce_purchases.item_id
JOIN exp_channel_data ON exp_simple_commerce_items.entry_id = exp_channel_data.entry_id
WHERE exp_simple_commerce_purchases.member_id = '<?php echo $this->EE->session->userdata['member_id'];?>'"}
{if item_id == 4}
Content will go here.
{if:else}
{redirect="courses/account"}
{if no_results}
{redirect="courses/"}
{/if}
{/exp:query}I also tried substituting {if item_id == 4} with each of the following, and get the same results:
{if entry_id == 176}
{if field_id_9 == 'Course 1'}
If I use either of the above code, the content displays, but if I change the id’s to those of Course 2, I am redirected instead of displayed the content.
Could I get some help on what I am missing?
Thanks
Susan