I am new to custom queries, and have a best practices question.
I have a custom query that is checking the logged in user to see if he purchased a Course we are offering using Simple Commerce. If he has, then the page content is displayed. If not, he is automatically redirected to another page. So far, it’s working fine.
What I’d like to know is the best practice for using this query in my templates. The only thing I can think of is to put the query into every template of every course. Are there any other alternatives? Can I, or is there any advantage, or disadvantage to putting the first part (before the page content) in a snippet or embed?
And one more question. If I use this query, I don’t think I also need to use the Access options under the templates, since I will now be restricting by member_id and purchase, instead of member group. Does that sound correct?
Thank you
Susan
{html-header}
</head>
{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}
<body>
page content is displayed
{if:else}
{redirect="anotherpage/"}
{/if}
{/exp:query}
{embed="olm_embeds/footer"}
</body>
</html>