Database check for products bought by a user?

  • Posts: 224
  • Thank you received: 8
5 years 11 months ago #291974

Hello,
I would like to use conditional content extension (regular labs) to show/hide contents on the website based on product bought by the user.
Thsi extension has a cutom PHP settings and the description reads like this:
Enter a piece of PHP code to evaluate. The code must return the value true or false.
For instance:
return ( $user->name == 'Peter van Westen' );


So my question is it is possible to check in the DB if the user has bought a certain product, and if yes could you suggest the necessary PHP sintax to use that extension?

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13063
  • MODERATOR
5 years 11 months ago #292014

Hi,

Yes.

Something like that:

$db = JFactory::getDBO();
$db->setQuery('SELECT o.order_product_id FROM #__hikashop_user AS u LEFT JOIN #__hikashop_order AS o ON u.user_id=o.order_user_id LEFT JOIN #__hikashop_order_product AS op.order_id = o.order_id WHERE u.user_cms_id = '.(int)$user->id.' AND op.product_id = XXXX AND o.order_status=\'confirmed\' LIMIT 1');
return (bool)$db->loadResult();
where XXXX is the id of the product.

The following user(s) said Thank You: kilou

Please Log in or Create an account to join the conversation.

  • Posts: 224
  • Thank you received: 8
5 years 11 months ago #292031

Thanks a lot Nicolas,
I will hire a developer to complete this step and post here the solution to use along with regularlabs conditional content, just in case someone else is looking for something similar.

The following user(s) said Thank You: kilou

Please Log in or Create an account to join the conversation.

Time to create page: 0.063 seconds
Powered by Kunena Forum