pol30 Posted November 4, 2013 Share Posted November 4, 2013 Hello, I have installed Prestashop default blockbestsellers module. When I click in the title of the module in the frontoffice: bestsellers, it shows best sales products, but it shows the best sales products in the last positions (down part of the page), Could you tell me what I should do to sort the products having best sales products first: top page? Prestashop version is 1.5.0.17. I do not know if I should edit: /classes/ProductSale.php or what I should do... Thanks very much Link to comment Share on other sites More sharing options...
SmartDataSoft Posted November 5, 2013 Share Posted November 5, 2013 If you use any module you can do that by sorting the array. Are you reffer the module or main page. best-seller.php . If so in that case you need to edit the page. Link to comment Share on other sites More sharing options...
pol30 Posted November 6, 2013 Author Share Posted November 6, 2013 Hello thanks for your reply. I use the module in main page: Top Sellers module is in the left column of the website, What do I have to edit in code so that when clicking in Top Sellers or All best seller link products most sold (best seller) are shown first (top of page)? Thanks very much, regards Link to comment Share on other sites More sharing options...
SmartDataSoft Posted November 6, 2013 Share Posted November 6, 2013 To show on home page you have to edit the php or build a module like our smartbestseller module for home page which we use on our sellya theme home page. Link to comment Share on other sites More sharing options...
pol30 Posted November 6, 2013 Author Share Posted November 6, 2013 I suppose the change is quite easy but I do not Know very much about php, could you tell me what code I should change in PHP? Thanks Link to comment Share on other sites More sharing options...
SmartDataSoft Posted November 6, 2013 Share Posted November 6, 2013 in the install section add a hook for home page !$this->registerHook('displayHome') in install function public function install() { if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('LeftColumn') || !$this->registerHook('header') || !$this->registerHook('updateOrderStatus') || !ProductSale::fillProductSales() || !Configuration::updateValue('PS_BLOCK_BESTSELLERS_DISPLAY', 1)|| !Configuration::updateValue('SMART_BESTSELLER_SHOW_COUNT', 6)|| !Configuration::updateValue('SMART_BESTSELLER_SHOW_HOME', 1)|| !Configuration::updateValue('SMART_BESTSELLER_SHOW_SIDEBAR',1)|| !Configuration::updateValue('SMART_BESTSELLER_HOME_LINK',1)) return false; return true; } then call the function of hook like bellow public function hookDisplayHome($params) { if (Configuration::get('PS_CATALOG_MODE')) return; $currency = new Currency($params['cookie']->id_currency); if (Product::getTaxCalculationMethod((int)$this->context->customer->id) == PS_TAX_EXC) $usetax = false; else $usetax = true; $bestsellers = ProductSale::getBestSalesLight((int)($params['cookie']->id_lang), 0, Configuration::get('SMART_BESTSELLER_SHOW_COUNT')); if (!$bestsellers && !Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY')) return; $best_sellers = array(); if ($bestsellers) foreach ($bestsellers as $bestseller) { $bestseller['price'] = Tools::displayPrice(Product::getPriceStatic((int)($bestseller['id_product']), $usetax), $currency); $best_sellers[] = $bestseller; } $this->smarty->assign(array( 'best_sellers' => $best_sellers, 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'smallSize' => Image::getSize(ImageType::getFormatedName('small')), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'displayInHome' => Configuration::get('SMART_BESTSELLER_SHOW_HOME'), 'showAllbestSellerLink' => Configuration::get('SMART_BESTSELLER_HOME_LINK') )); return $this->display(__FILE__, 'blockbestsellers-home.tpl'); } Please remember that for home page you may need to change the css also. I copy the funtion code from hookLeftColumn Hope you can do that. Link to comment Share on other sites More sharing options...
pol30 Posted November 6, 2013 Author Share Posted November 6, 2013 Thanks very much, but I have deault Blockbestsellers module installed, it appears in home page, it is oke everything except that when I click in best seller it sort the most products in down page not in top page...I think maybe it should be easier just changing some existing code: public static function getBestSales($id_lang, $pageNumber = 0, $nbProducts = 10, $orderBy=NULL, $orderWay=NULL) This function is in /classes/ProductSale.php But I do not what I should change... Link to comment Share on other sites More sharing options...
vekia Posted November 6, 2013 Share Posted November 6, 2013 hello you mean that you want to change sort method? Link to comment Share on other sites More sharing options...
pol30 Posted November 8, 2013 Author Share Posted November 8, 2013 Hello Vekia thanks for your interest, Yes I think so. I just want that when clicking in Top sellers (All best sellers), products sort in top of page most sold products and in down page the least sold products (Prestashop default bestsellers module do it on the contrary). I want to solve it and I do not know if I should edit some php...¿How can I do it? Thanks very much Link to comment Share on other sites More sharing options...
NemoPS Posted November 8, 2013 Share Posted November 8, 2013 I'm writing a tut on this! I did this on category pages, but It can be applied to that method as well . To the fields query, add this ps.quantity AS sales This will grab the number of sales from product_sale Of course,, join the table LEFT JOIN '._DB_PREFIX_.'product_sale ps ON ps.id_product = product_shop.id_product And lastly order by sales in your order clause! Link to comment Share on other sites More sharing options...
Recommended Posts