-1

How can i get current user purchase history in opencart 2.0.3.1?

I want the reviews to be given only by the users who has purchased the product, i could not find any free extension for it so would like to write the code manually.

Thank you.

VarunD
  • 1
  • 1

1 Answers1

0

If you know a little PHP/MySQL, you can easily do this with querying "order" table. The algorithm is simple: take current customer's ID (CUSTOMER_ID) and look for it in "order" table, when customer browses product with certain PRODUCT_ID (visits its page):

SELECT COUNT(order_id) as total FROM order WHERE customer_id = CUSTOMER_ID AND product_id = PRODUCT_ID

If "total" is more than zero, display review form. Otherwise, hide it.

The Krotek
  • 383
  • 1
  • 7
  • Thank s lot for reply. As i am new to opencart i do not know the structure. And i know it is bad practice to write mysql code in .tpl file. But i have to, can you please guide me on how to write mysql code in .tpl file.?? – VarunD Nov 05 '15 at 13:36
  • @VarunD, not TPL-file of course. Create XML file instead. For OpenCart 2 it's usually a OCMod file or VQMod with 3rd party extension. I can't explain it fully in comments and I'd really recommend you to learn, how OCMod/VQmod works. This is a VERY handy thing, which allows you to create modifications without changing core files. You only need, which file you want to change (model, controller or view) and where do you want to put your code (string to replace). – The Krotek Nov 05 '15 at 17:35
  • Here's a link, that might help you with OCMod basics: https://github.com/opencart/opencart/wiki/Modification-System – The Krotek Nov 05 '15 at 17:36