Jump to content

Change BestSalesQuantity on BlockBestSellers Module to BestSalesAmount


Recommended Posts

First, backup your ProcuctSale.php on classes dir and blockbestsellers.php on module/blockbestsellers dir.

in ProductSale.php add some code before trail '} ?>' on end of file
before

}
?>;


add some code

   static public function getBestSalesAmount($id_lang, $pageNumber = 0, $nbProducts = 10)
   {
       global $link, $cookie;

       if ($pageNumber < 0) $pageNumber = 0;
       if ($nbProducts < 1) $nbProducts = 10;

       $result = Db::getInstance()->ExecuteS('
       SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`,  
           ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / c.conversion_rate), 0), 2) AS sales,
           p.`ean13`, cl.`link_rewrite` AS category            
       FROM `'._DB_PREFIX_.'product_sale` ps 
       LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
       LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
       LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN '._DB_PREFIX_.'order_detail od ON od.product_id = p.id_product
       LEFT JOIN '._DB_PREFIX_.'orders o ON od.id_order = o.id_order
       LEFT JOIN '._DB_PREFIX_.'currency c ON o.id_currency = c.id_currency
       WHERE p.`active` = 1
       AND p.`id_product` IN (
           SELECT cp.`id_product`
           FROM `'._DB_PREFIX_.'category_group` cg
           LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
           WHERE cg.`id_group` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'
       )
       GROUP BY p.`id_product`
       ORDER BY sales DESC
       LIMIT '.intval($pageNumber * $nbProducts).', '.intval($nbProducts));

       if (!$result)
           return $result;

       foreach ($result AS &$row)
       {
            $row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
            $row['id_image'] = Product::defineProductImage($row);
       }
       return $result;    
   }
}
?>;



in blockbestsellers.php, change line 35
from

$bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5);


to

$bestsellers = ProductSale::getBestSalesAmount(intval($params['cookie']->id_lang), 0, 5);

Link to comment
Share on other sites

×
×
  • Create New...