Jump to content

Editing code on Best Sellers


tout2004

Recommended Posts

Hello,

 

I need to edit the bestsellers to show products sold by date - most recent first rather than actual best sellers as my products are unique items so only one of each will ever be sold.

 

The rest of my site is displayed by price order as set in preferances, i would like to keep this the same, only editing the bestsellers.

 

Any help welcome as I am stuck!

Link to comment
Share on other sites

Hi,

 

I'd create a module for that rather than edit the best-sellers.

 

But if you still want to edit this one, you'll need to modify the query so it selects each product of your orders (orders and order_detail tables), order by date_add and limit to x products. Don't forget to remove duplicates products.

 

Antho

Link to comment
Share on other sites

I thought this would do the trick, but for some reason it doesn't. Anyone a clue why not?? It doesn't reorder, it seems, even when changing DESC in ASC. Very strange...

 

Thing I tried:

 

Edit file classes/ProductSale.php and add the red text in the following sql query:

 

public static function getBestSalesLight($id_lang, $page_number = 0, $nb_products = 10, Context $context = null)

{

if (!$context)

$context = Context::getContext();

if ($page_number < 0) $page_number = 0;

if ($nb_products < 1) $nb_products = 10;

 

$groups = FrontController::getCurrentCustomerGroups();

$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');

 

$sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`,

ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, ps.`date_upd` as sales_date

FROM `'._DB_PREFIX_.'product_sale` ps

LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`

'.Shop::addSqlAssociation('product', 'p').'

LEFT JOIN `'._DB_PREFIX_.'product_lang` pl

ON p.`id_product` = pl.`id_product`

AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'

LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'.

Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'

LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')

LEFT JOIN `'._DB_PREFIX_.'category_lang` cl

ON cl.`id_category` = product_shop.`id_category_default`

AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'

WHERE product_shop.`active` = 1

AND p.`visibility` != \'none\'

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` '.$sql_groups.'

)

GROUP BY product_shop.id_product

ORDER BY sales_date DESC

LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;

 

 

Anyone can see what goes wrong?? Is it re-ordered somewhere else again??

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...