Timeline for Magento 2: get latest Bestseller collection
Current License: CC BY-SA 4.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 28, 2018 at 9:40 | comment | added | Chirag Patel | I give you a way how to get latest bestseller collection now you have to find out how to sort order in descending order. | |
Dec 28, 2018 at 9:31 | comment | added | Narendra Vyas | Yes in my database table id exists. But on printing the collection there comes not id, i think this is the reason its not working. And I have not done any customizations yet. | |
Dec 28, 2018 at 9:25 | comment | added | Chirag Patel |
I think you missed something because in database data in stored sales_bestsellers_aggregated_monthly table in table id is primary key if you sort by id then it have to work. but in your case i don't have idea why this is not working. In short basically you need to load collection by descending order so you get latest record first.
|
|
Dec 28, 2018 at 9:21 | comment | added | Narendra Vyas | For: setOrder('id','DESC') (no error but no change)... for ->setOrder('position','ASC') (same erorr) | |
Dec 28, 2018 at 9:18 | comment | added | Chirag Patel | Same error you got? | |
Dec 28, 2018 at 9:18 | comment | added | Narendra Vyas | not working for me :( | |
Dec 28, 2018 at 9:17 | comment | added | Chirag Patel | Let us continue this discussion in chat. | |
Dec 28, 2018 at 9:15 | comment | added | Chirag Patel |
Try with ->setOrder('id','DESC') OR ->setOrder('position','ASC');
|
|
Dec 28, 2018 at 9:10 | comment | added | Narendra Vyas | G etting same error for this as well. column not found | |
Dec 28, 2018 at 9:05 | comment | added | Chirag Patel |
For Ex:- if you wan to get last updates product so you need to pass like this ->setOrder('updated_at','DESC')
|
|
Dec 28, 2018 at 9:03 | comment | added | Chirag Patel |
In the place of sort_order you need to pass product_id
|
|
Dec 28, 2018 at 9:03 | comment | added | Narendra Vyas | I think I need to change this ORDER BY period ASC to DSC. You have any idea how to do that ? | |
Dec 28, 2018 at 9:02 | comment | added | Narendra Vyas |
I am getting this error: Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sort_order' in 'order clause', query was: SELECT DATE_FORMAT(period, '%Y-%m') AS period , SUM(qty_ordered) AS qty_ordered , sales_bestsellers_aggregated_monthly .product_id , MAX(product_name) AS product_name , MAX(product_price) AS product_price FROM sales_bestsellers_aggregated_monthly WHERE (rating_pos <= 5) AND (store_id IN(0)) AND (store_id IN(0)) GROUP BY period , product_id ORDER BY period ASC, qty_ordered DESC, sort_order DESC LIMIT 8
|
|
Dec 28, 2018 at 9:00 | history | answered | Chirag Patel | CC BY-SA 4.0 |