Page 1 of 1

Monthly best sellers

Posted: Fri Jan 27, 2012 6:16 pm
by NTCommerce
My client has requested that the best seller module only lists the best sellers from the past 30 days,
Does anyone know if it is possible to adapt the bestsellers mod to suite ?
If so how would I go about this ?

Any thoughts would be greatly appreciated.

Nigel

Re: Monthly best sellers

Posted: Mon Apr 22, 2013 9:30 am
by eWarrior
I know this is an old thread but I am also looking to implement this for a client (they are using v1.5.2.1).

Would anyone be able to offer assistance with the required modifications?

Re: Monthly best sellers

Posted: Fri Apr 26, 2013 5:19 pm
by eWarrior
-

Re: Monthly best sellers

Posted: Fri Apr 26, 2013 5:49 pm
by daik01
You have to change the query in getBestSellerProducts at the \catalog\model\catalog\product.php file. I think that adding a where clause like WHERE o.date_added > CURDATE() -30 should do the trick.

Re: Monthly best sellers

Posted: Sat Apr 27, 2013 5:56 pm
by storm-cloud
Thank you for the reply daik01!

I tried your suggested code but unfortunately I was not able to get this to work. I researched this a little further and came up with o.date_added >= DATE_SUB(NOW(), INTERVAL 30 DAY).

The complete query was changed from:

$query = $this->db->query("SELECT op.product_id, COUNT(*) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE o.order_status_id > '0' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY op.product_id ORDER BY total DESC LIMIT " . (int)$limit);

To:

$query = $this->db->query("SELECT op.product_id, COUNT(*) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE o.order_status_id > '0' AND o.date_added >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY op.product_id ORDER BY total DESC LIMIT " . (int)$limit);

This seems to be doing the trick but admittedly my SQL skills could use some work. Would there be a better method than this or is there anything in the above code that may cause issues?

Re: Monthly best sellers

Posted: Wed Apr 20, 2016 4:05 pm
by ninad_jad
Hi,

i tried this code for oc2.1.0.2, but nothing happened, i cleared modifications and all but still same regular result, any one have solution for oc2.1.0.2 to get best sellers for last week or month

Re: Monthly best sellers

Posted: Fri May 13, 2016 11:23 pm
by straightlight

Re: Monthly best sellers

Posted: Thu Dec 22, 2016 5:59 am
by websiteworld
ninad_jad wrote:Hi,

i tried this code for oc2.1.0.2, but nothing happened, i cleared modifications and all but still same regular result, any one have solution for oc2.1.0.2 to get best sellers for last week or month
Same here, doesn't do anything in Opencart 2.3