mohsart Posted August 26, 2010 Share Posted August 26, 2010 Would it be possible to change the built-in Top Sellers block like this...1. Show Top Sellers within the cathegory the customer's in, eg if my customer is looking for problem books for Go it would show the top selling Go Problem Books, not overall Top Selling products which may be Chess Boards.2. When listing All Top Sellers it would make more sense to list them in top selling order rather than alphabetically.Thanks for any ideas,/Mats Link to comment Share on other sites More sharing options...
mohsart Posted August 26, 2010 Author Share Posted August 26, 2010 Is this a strange request?I would think that eg someone selling baby clothes would want someone browsing for Boy Baby Clothings to see only top selling boy clothes and not girls, or someone in a record store looking at Metal seeing top selling Metal and not Hip Hop.../Mats Link to comment Share on other sites More sharing options...
rocky Posted August 27, 2010 Share Posted August 27, 2010 It seems everyone is getting less and less patient on these forums lately. %-P It's a good idea. Try changing line 99 of classes/ProductSales.php (in PrestaShop v1.3.1) from: static public function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10) to: static public function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10, $id_category = 0) and line 114 from: WHERE p.`active` = 1 to: WHERE p.`active` = 1'.($id_category > 0 ? ' AND p.`id_category_default` = '.$id_category : '').' and then change line 35 of modules/blockbestsellers/blockbestsellers.php from: $bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5); to: $id_category = 0; if (isset($_GET['id_category']) AND $_GET['id_category'] > 0) { $category = new Category($_GET['id_category']); if (Validate::isLoadedObject($category)) $id_category = $_GET['id_category']; } $bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5, $id_category); You need to go to Preferences > Products and change the "Default order way" to "Decreasing" to have top sellers sorted from most sales to least sales. Link to comment Share on other sites More sharing options...
mohsart Posted August 27, 2010 Author Share Posted August 27, 2010 Thanks!I just realized how you got your nick - you Rock! :-)One weird thing though:http://mohsart.se/13-bocker-pa-engelska and http://mohsart.se/35-pertigenomgangar-analyserIn both categories there's a book called invincible but it only shows up as a best seller in the firstSame for the Yunzi stones herehttp://mohsart.se/26-stenar and http://mohsart.se/14-utrustning/MatsPS Sorry for being impatient Link to comment Share on other sites More sharing options...
mohsart Posted August 27, 2010 Author Share Posted August 27, 2010 Another thing:http://mohsart.se/best-sales.phpOn 5th place it shows a book that I haven't sold a single copy of yet/Mats Link to comment Share on other sites More sharing options...
rocky Posted August 27, 2010 Share Posted August 27, 2010 My code above uses the default category of the product, since it will only appear as a best seller in the product's default category. It would require a more complicated query to select all categories the product is in. You'd need to instead change line 114 of classes/ProductSale.php from: WHERE p.`active` = 1 to: LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (p.`id_product` = cp.`id_product`) WHERE p.`active` = 1 AND sales > 0 AND '.($id_category > 0 ? ' AND cp.`id_category` = '.$id_category : '').' This will also exclude products that haven't been sold yet. Link to comment Share on other sites More sharing options...
mohsart Posted August 27, 2010 Author Share Posted August 27, 2010 Thanks, but now no best sellers are shown anywhere./Mats Link to comment Share on other sites More sharing options...
mohsart Posted August 28, 2010 Author Share Posted August 28, 2010 I removed " AND sales > 0 AND " and now it seems to be OKThanks again Rocky!/Mats Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted December 18, 2010 Share Posted December 18, 2010 Fantastic trick, it works !Thanks Rocky & Mats. Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted December 20, 2010 Share Posted December 20, 2010 Please, just one question...It works fine on the category page, but not in the product page because $id_category doesn't exist here.How to resolve this ?I'm not sure how to do this in php/smarty....Thanks for your help.... Link to comment Share on other sites More sharing options...
rocky Posted December 20, 2010 Share Posted December 20, 2010 The only solution is to set a default category other than "Home" on each product and then use $product->id_category_default to get the default category of the product. 1 Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted December 21, 2010 Share Posted December 21, 2010 Yes, sure, that's what I was thinking about.But I can't manage to translate this into code.I've tried a few things but can't make it work.Please gimme a clue, Mr Rocky....Thanks.... Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted January 24, 2011 Share Posted January 24, 2011 I've managed to pass $id_category in the product page by adding this to product.php : 'id_category' => intval($category->id), But still, the best sellers block shows all the best sellers in the produt page, not those from the category of the current product.Am I missing something ? Link to comment Share on other sites More sharing options...
rocky Posted January 25, 2011 Share Posted January 25, 2011 Try: $id_category = 0; if (isset($_GET['id_category']) AND intval($_GET['id_category']) > 0) { $category = new Category(intval($_GET['id_category']), intval($params['cookie']->id_lang)); if (Validate::isLoadedObject($category)) $id_category = intval($_GET['id_category']); } elseif (isset($_GET['id_product']) AND intval($_GET['id_product']) > 0) { $product = new Product(intval($_GET['id_product']), false, intval($params['cookie']->id_lang)); if (Validate::isLoadedObject($product)) $id_category = intval($product->id_category_default); } $bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5, $id_category); Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted January 25, 2011 Share Posted January 25, 2011 Yes, you did it !I had tried this kind of solution for hours but I was misunderstanding something.Thanks x1000Rocky rocks ! Link to comment Share on other sites More sharing options...
Enduro Posted January 30, 2012 Share Posted January 30, 2012 Hello, Can you say to me or put this code in the product.php file Thank you $id_category = 0; if (isset($_GET['id_category']) AND intval($_GET['id_category']) > 0) { $category = new Category(intval($_GET['id_category']), intval($params['cookie']->id_lang)); if (Validate::isLoadedObject($category)) $id_category = intval($_GET['id_category']); } elseif (isset($_GET['id_product']) AND intval($_GET['id_product']) > 0) { $product = new Product(intval($_GET['id_product']), false, intval($params['cookie']->id_lang)); if (Validate::isLoadedObject($product)) $id_category = intval($product->id_category_default); } $bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5, $id_category); Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted January 31, 2012 Share Posted January 31, 2012 You have to put this code into blockbestsellers.php. Here is how mine looks, for PS 1.3.2 and a Bestsellers block hooked on right column. <?php if (!defined('_CAN_LOAD_FILES_')) exit; class BlockBestSellers extends Module { private $_html = ''; private $_postErrors = array(); function __construct() { $this->name = 'blockbestsellers'; $this->tab = 'Blocks'; $this->version = '1.1'; parent::__construct(); $this->displayName = $this->l('Top seller block'); $this->description = $this->l('Add a block displaying the shop\'s top sellers'); } public function install() { if (!parent::install() OR !$this->registerHook('rightColumn') OR !$this->registerHook('updateOrderStatus') OR !ProductSale::fillProductSales()) return false; return true; } function hookRightColumn($params) { global $smarty; $currency = new Currency(intval($params['cookie']->id_currency)); $id_category = 0; if (isset($_GET['id_category']) AND intval($_GET['id_category']) > 0) { $category = new Category(intval($_GET['id_category']), intval($params['cookie']->id_lang)); if (Validate::isLoadedObject($category)) $id_category = intval($_GET['id_category']); } elseif (isset($_GET['id_product']) AND intval($_GET['id_product']) > 0) { $product = new Product(intval($_GET['id_product']), false, intval($params['cookie']->id_lang)); if (Validate::isLoadedObject($product)) $id_category = intval($product->id_category_default); } $bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5, $id_category); $best_sellers = array(); foreach ($bestsellers AS $bestseller) { $bestseller['price'] = Tools::displayPrice(Product::getPriceStatic(intval($bestseller['id_product'])), $currency); $best_sellers[] = $bestseller; } $smarty->assign(array( 'best_sellers' => $best_sellers, 'mediumSize' => Image::getSize('medium'))); return $this->display(__FILE__, 'blockbestsellers.tpl'); } function hookLeftColumn($params) { return $this->hookRightColumn($params); } } ?> Link to comment Share on other sites More sharing options...
Enduro Posted January 31, 2012 Share Posted January 31, 2012 Thank you, it's perfect. Also work on presta 1.4.6.2 I replaced the code into blockbestsellers.php $id_category = 0; if (isset($_GET['id_category']) AND $_GET['id_category'] > 0) { $category = new Category($_GET['id_category']); if (Validate::isLoadedObject($category)) $id_category = $_GET['id_category']; } $bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5, $id_category); by $id_category = 0; if (isset($_GET['id_category']) AND intval($_GET['id_category']) > 0) { $category = new Category(intval($_GET['id_category']), intval($params['cookie']->id_lang)); if (Validate::isLoadedObject($category)) $id_category = intval($_GET['id_category']); } elseif (isset($_GET['id_product']) AND intval($_GET['id_product']) > 0) { $product = new Product(intval($_GET['id_product']), false, intval($params['cookie']->id_lang)); if (Validate::isLoadedObject($product)) $id_category = intval($product->id_category_default); } $bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5, $id_category); Link to comment Share on other sites More sharing options...
outlet.ee Posted March 26, 2012 Share Posted March 26, 2012 The top sellers page on my shop is acting weird. As of now it is 'all products sold list, in no particular order'. The pagination doesn't work but I'd like to eliminate the pagination and have it like 50 top selling products, ordered by number of sales so the top selling one is the first etc. Now in the classes/productsale.php there is this function: static public function getBestSales($id_lang, $pageNumber = 0, $nbProducts = 10, $orderBy=NULL, $orderWay=NULL) { if ($pageNumber < 0) $pageNumber = 0; if ($nbProducts < 1) $nbProducts = 10; if (empty($orderBy) || $orderBy == 'position') $orderBy = 'sales'; if (empty($orderWay)) $orderWay = 'DESC'; but it doesn't sort it by sales, as a matter of fact it looks like it sorts them randomly, and sometimes in groups based on category. The very top selling product is right in the middle. I can change the number of products here but how to make it to be sorted by sales desc? Link to comment Share on other sites More sharing options...
karlangas77 Posted December 23, 2015 Share Posted December 23, 2015 Hello, I am trying to follow steps of this thread to filter best sellers by category but only for last month but not results. Any ideas ? thanks! (sorry for my crappy English) Link to comment Share on other sites More sharing options...
Guest locen Posted December 29, 2015 Share Posted December 29, 2015 Hi, i would create query to shows PRODUC TNAME, COUNTRY, QUANTITY SALES and SALE DATE. Because in STATS->BEST-SELLING PRODUCTS i can't shows also country that products are sold Please help me Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now