Jump to content

unable to display the best-sales items


Recommended Posts

Hi Guys, I am trying to display all my best selling items, but it does not reflect any items.

 

here is the URL.

 

Online Shopping

 

when i add in /best-sales

I am unable to see any best sales items

 

but in the back end, I can see all my best selling items...

 

I have deleted and reinstall the best sales module and it did not resolve the issue. Please help and advise.

 

Thanks a lot

Edited by cutecat (see edit history)
Link to comment
Share on other sites

sorry

here is the error log

 

1  4  Cart cannot be loaded or an order has already been placed using this cart   0  0x 1  07/31/2013 01:34:19
2  3  The function addCSS (Line 149) is deprecated and will be removed in the next major version.   0  0x 0  07/31/2013 22:47:22
3  3  The function getMetaTags (Line 184) is deprecated and will be removed in the next major version.   0  0x 0  07/31/2013 22:47:22

Edited by cutecat (see edit history)
Link to comment
Share on other sites

Warning: Function addCSS() is deprecated in /home/123456/public_html/modules/mailchimp/mailchimp.php on line 149
in /home/123456/public_html/classes/Tools.php on line 1845

 

Warning: Function addCSS() is deprecated in /home/lovelyin/public_html/modules/mailchimp/mailchimp.php on line 149
in /home/lovelyin/public_html/classes/Tools.php on line 1845
[PrestaShopDatabaseException]
Column 'date_add' in order clause is ambiguous
SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
 pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
 pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
 m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer,
 MAX(image_shop.`id_image`) id_image, il.`legend`,
 ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`,
 DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
 INTERVAL 30 DAY)) > 0 AS new
   FROM `ps_product_sale` ps
   LEFT JOIN `ps_product` p ON ps.`id_product` = p.`id_product`
 LEFT JOIN ps_product_shop product_shop
 ON (product_shop.id_product = p.id_product AND product_shop.id_shop = 1)
   LEFT JOIN `ps_product_lang` pl
 ON p.`id_product` = pl.`id_product`
 AND pl.`id_lang` = 1 AND pl.id_shop = 1
   LEFT JOIN `ps_image` i ON (i.`id_product` = p.`id_product`) LEFT JOIN ps_image_shop image_shop
 ON (image_shop.id_image = i.id_image AND image_shop.id_shop = 1 AND image_shop.cover=1)
   LEFT JOIN `ps_image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = 1)
   LEFT JOIN `ps_manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
   LEFT JOIN `ps_tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`)
 AND tr.`id_country` = 25
 AND tr.`id_state` = 0
   LEFT JOIN `ps_tax` t ON (t.`id_tax` = tr.`id_tax`)
 LEFT
  JOIN ps_stock_available stock
  ON (stock.id_product = p.id_product AND stock.id_product_attribute = 0 AND stock.id_shop = 1  )
   WHERE product_shop.`active` = 1
 AND p.`visibility` != 'none'
 AND p.`id_product` IN (
  SELECT cp.`id_product`
  FROM `ps_category_group` cg
  LEFT JOIN `ps_category_product` cp ON (cp.`id_category` = cg.`id_category`)
  WHERE cg.`id_group` IN (3)
 )
   GROUP BY product_shop.id_product
   ORDER BY `date_add` desc
   LIMIT 0, 24

at line 607 in file classes/db/Db.php
601.    WebserviceRequest::getInstance()->setError(500, '[sql Error] '.$this->getMsgError().'. From '.(isset($dbg[3]['class']) ? $dbg[3]['class'] : '').'->'.$dbg[3]['function'].'() Query was : '.$sql, 97);
602.   }
603.   else if (_PS_DEBUG_SQL_ && $errno && !defined('PS_INSTALLATION_IN_PROGRESS'))
604.   {
605.    if ($sql)
606.	 throw new PrestaShopDatabaseException($this->getMsgError().'<br /><br /><pre>'.$sql.'</pre>');
607.    throw new PrestaShopDatabaseException($this->getMsgError());
608.   }
609.  }
610.
611.  /**
   DbCore->displayError - [line 307 - classes/db/Db.php] - [1 Arguments]
   DbCore->query - [line 482 - classes/db/Db.php] - [1 Arguments]
   DbCore->executeS - [line 110 - classes/ProductSale.php] - [1 Arguments]
   ProductSaleCore::getBestSales - [line 40 - controllers/front/BestSalesController.php] - [5 Arguments]
   BestSalesControllerCore->initContent - [line 167 - classes/controller/Controller.php] - [0 Argument]
   ControllerCore->run - [line 349 - classes/Dispatcher.php] - [0 Argument]
   DispatcherCore->dispatch - [line 28 - index.php] - [0 Argument]

 

just open the best sales page - if any error will appear, then paste the error code here

 

btw. have you got any purchases?

 

yes i have quite a lot of purchase

i think i going to off the error log.

there are customers now looking at my site.

Link to comment
Share on other sites

It seems that there are Database errors, 5 in the BestSalesController.php

 

What version of PrestaShop are you using, is this an upgraded store?

 

It's strange because it seems that your best sales are showing up on the right column of that page... but it is not populating the page itself.

 

I am using 1.5.4.1 and it is a upgraded store. it was 1.5.3

 

How do i resolve it?

 

I have also just messed up my total number of products... now i am manually entering the number back in... really a pain!!! 500 over products!

Edited by cutecat (see edit history)
Link to comment
Share on other sites

hello

 

thanks for the error code above

ussually "ambiguous" errors are related to the JOINS in the query, and definition of the columns

 

take a look:

 

ORDER BY `date_add` desc

DATEDIFF(p.`date_add`, DATE_SUB(NOW(),

 

now you see the difference between column names (date_add and p.date_add)?

this is ambiguous for the script.

 

change query part with ORDER to:

ORDER BY p.`date_add` desc

Link to comment
Share on other sites

is this the correct way to check? I had never done this before.

 

SQL query: SELECT `ps_orders`.`date_add`, `ps_orders`.`date_upd` FROM ps_orders ;
Rows: 80
date_add  date_upd
2013-04-04 22:37:38  2013-04-15 13:39:08
2013-04-05 00:48:05  2013-04-15 13:38:31
2013-04-05 13:31:29  2013-04-15 00:05:46
2013-04-10 14:55:28  2013-04-22 16:58:43
2013-04-10 15:16:16  2013-04-22 16:58:29
2013-04-15 19:31:05  2013-04-29 17:02:06
2013-04-17 20:47:12  2013-04-28 20:39:32
2013-04-20 13:35:52  2013-05-02 15:32:18
2013-04-24 23:08:33  2013-05-10 15:43:10
2013-04-26 20:09:13  2013-05-10 14:23:43
2013-05-01 07:22:59  2013-05-02 14:00:56
2013-05-01 23:35:45  2013-05-02 19:47:17
2013-05-02 13:31:20  2013-05-10 14:24:14
2013-05-02 15:50:47  2013-05-10 14:24:32
2013-05-02 23:06:14  2013-07-13 03:35:48
2013-05-06 17:33:20  2013-05-15 16:58:27
2013-05-11 16:48:13  2013-05-18 06:19:10
2013-05-12 23:43:24  2013-05-19 01:32:23
2013-05-14 15:05:11  2013-05-20 23:21:44
2013-05-14 21:52:38  2013-05-20 22:33:13
2013-05-17 00:20:45  2013-05-17 10:49:42
2013-05-23 23:25:25  2013-05-29 22:03:22
2013-05-24 00:50:02  2013-05-29 17:48:08
2013-05-25 16:09:32  2013-06-11 15:56:28
2013-05-28 14:11:42  2013-05-28 22:53:37
2013-05-29 21:22:51  2013-06-13 17:09:51
2013-06-03 21:14:48  2013-06-13 15:48:18
2013-06-09 12:31:09  2013-06-11 20:56:40
2013-06-13 15:41:15  2013-06-20 21:31:55
2013-06-16 22:00:03  2013-06-18 22:38:39
2013-06-19 22:02:11  2013-06-19 23:29:27
2013-06-19 23:20:07  2013-06-25 20:08:24
2013-06-20 12:59:42  2013-06-25 17:36:52
2013-06-23 00:04:20  2013-06-26 21:34:49
2013-06-23 11:53:10  2013-06-27 18:09:44
2013-06-24 22:15:30  2013-07-03 16:18:51
2013-06-25 10:12:49  2013-07-02 22:41:38
2013-06-26 02:06:22  2013-07-02 22:26:41
2013-06-26 21:17:24  2013-07-02 22:51:51
2013-06-28 12:15:40  2013-07-04 21:42:29
2013-06-28 23:50:07  2013-07-07 00:37:51
2013-06-29 12:11:02  2013-07-07 18:22:31
2013-06-29 23:08:23  2013-07-09 17:24:12
2013-06-29 23:12:56  2013-07-06 23:47:07
2013-07-03 21:49:55  2013-07-10 15:37:21
2013-07-05 10:59:26  2013-07-12 16:35:00
2013-07-07 17:29:26  2013-07-15 22:11:17
2013-07-07 18:47:34  2013-07-13 20:58:15
2013-07-08 00:00:39  2013-07-13 21:04:24
2013-07-08 18:36:52  2013-07-18 01:08:49
2013-07-08 22:10:25  2013-07-20 01:15:13
2013-07-09 14:42:09  2013-07-18 01:48:09
2013-07-10 14:34:23  2013-07-18 18:24:33
2013-07-10 18:18:07  2013-07-18 01:52:31
2013-07-10 18:47:58  2013-07-18 01:59:46
2013-07-11 11:59:14  2013-07-21 20:56:12
2013-07-11 23:13:43  2013-07-15 19:06:28
2013-07-12 12:42:25  2013-07-21 18:45:07
2013-07-12 19:48:12  2013-07-23 21:09:55
2013-07-13 18:31:25  2013-07-18 22:29:34
2013-07-15 09:01:23  2013-07-25 00:15:26
2013-07-16 09:45:28  2013-07-23 22:34:41
2013-07-18 12:07:19  2013-07-24 04:23:21
2013-07-18 12:45:14  2013-07-31 16:23:13
2013-07-19 02:53:27  2013-07-21 00:45:36
2013-07-19 20:35:56  2013-07-21 19:40:01
2013-07-20 04:56:00  2013-07-31 16:23:52
2013-07-21 15:35:12  2013-07-31 16:24:09
2013-07-24 12:56:00  2013-07-30 06:49:42
2013-07-24 21:58:38  2013-07-25 23:33:06
2013-07-25 15:14:34  2013-07-25 23:33:00
2013-07-25 22:50:50  2013-07-25 23:05:24
2013-07-27 17:20:05  2013-07-29 08:30:13
2013-07-27 18:50:52  2013-07-27 18:50:52
2013-07-30 11:50:11  2013-07-31 15:27:34
2013-07-30 13:19:24  2013-07-30 22:50:21
2013-07-30 16:06:04  2013-07-30 22:53:55
2013-07-30 22:31:45  2013-07-30 22:50:06
2013-07-31 01:31:56  2013-07-31 13:52:03
2013-07-31 22:56:50  2013-07-31 23:58:03

Link to comment
Share on other sites

  • 4 weeks later...

Copy this script and paste to file manager  >  root  >  classes  > ProductSale.php

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

class ProductSaleCore
{
	/*
	** Fill the `product_sale` SQL table with data from `order_detail`
	** @return bool True on success
	*/
	public static function fillProductSales()
	{
		$sql = 'REPLACE INTO '._DB_PREFIX_.'product_sale
				(`id_product`, `quantity`, `sale_nbr`, `date_upd`)
				SELECT od.product_id, SUM(od.product_quantity), COUNT(od.product_id), NOW()
							FROM '._DB_PREFIX_.'order_detail od GROUP BY od.product_id';
		return Db::getInstance()->execute($sql);
	}

	/*
	** Get number of actives products sold
	** @return int number of actives products listed in product_sales
	*/
	public static function getNbSales()
	{
		$sql = 'SELECT COUNT(ps.`id_product`) AS nb
				FROM `'._DB_PREFIX_.'product_sale` ps
				LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = ps.`id_product`
				'.Shop::addSqlAssociation('product', 'p', false).'
				WHERE product_shop.`active` = 1';
		return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
	}

	/*
	** Get required informations on best sales products
	**
	** @param integer $id_lang Language id
	** @param integer $page_number Start from (optional)
	** @param integer $nb_products Number of products to return (optional)
	** @return array from Product::getProductProperties
	*/
	public static function getBestSales($id_lang, $page_number = 0, $nb_products = 10, $order_by = null, $order_way = null)
	{
		if ($page_number < 0) $page_number = 0;
		if ($nb_products < 1) $nb_products = 10;
		$final_order_by = $order_by;
		$order_table = ''; 		
		if (is_null($order_by) || $order_by == 'position' || $order_by == 'price') $order_by = 'sales';
		if ($order_by == 'date_add' || $order_by == 'date_upd')
			$order_table = 'product_shop'; 				
		if (is_null($order_way) || $order_by == 'sales') $order_way = 'DESC';
		$groups = FrontController::getCurrentCustomerGroups();
		$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
		$interval = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20;
		
		$prefix = '';
		if ($order_by == 'date_add')
			$prefix = 'p.';
		
		$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
					pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
					pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
					m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer,
					MAX(image_shop.`id_image`) id_image, il.`legend`,
					ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`,
					DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
					INTERVAL '.$interval.' DAY)) > 0 AS new
				FROM `'._DB_PREFIX_.'product_sale` ps
				LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
				'.Shop::addSqlAssociation('product', 'p', false).'
				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_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
				LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`)
					AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
					AND tr.`id_state` = 0
				LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
				'.Product::sqlStock('p').'
				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 '.(!empty($order_table) ? '`'.pSQL($order_table).'`.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).'
				LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;

		$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);

		if ($final_order_by == 'price')
			Tools::orderbyPrice($result, $order_way);
		if (!$result)
			return false;
		return Product::getProductsProperties($id_lang, $result);
	}

	/*
	** Get required informations on best sales products
	**
	** @param integer $id_lang Language id
	** @param integer $page_number Start from (optional)
	** @param integer $nb_products Number of products to return (optional)
	** @return array keys : id_product, link_rewrite, name, id_image, legend, sales, ean13, upc, link
	*/
	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
				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 DESC
				LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;
		if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
			return false;

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

	public static function addProductSale($product_id, $qty = 1)
	{
		return Db::getInstance()->execute('
			INSERT INTO '._DB_PREFIX_.'product_sale
			(`id_product`, `quantity`, `sale_nbr`, `date_upd`)
			VALUES ('.(int)$product_id.', '.(int)$qty.', 1, NOW())
			ON DUPLICATE KEY UPDATE `quantity` = `quantity` + '.(int)$qty.', `sale_nbr` = `sale_nbr` + 1, `date_upd` = NOW()');
	}

	public static function getNbrSales($id_product)
	{
		$result = Db::getInstance()->getRow('SELECT `sale_nbr` FROM '._DB_PREFIX_.'product_sale WHERE `id_product` = '.(int)$id_product);
		if (!$result || empty($result) || !key_exists('sale_nbr', $result))
			return -1;
		return (int)$result['sale_nbr'];
	}

	public static function removeProductSale($id_product, $qty = 1)
	{
		$total_sales = ProductSale::getNbrSales($id_product);
		if ($total_sales > 1)
			return Db::getInstance()->execute('
				UPDATE '._DB_PREFIX_.'product_sale
				SET `quantity` = `quantity` - '.(int)$qty.', `sale_nbr` = `sale_nbr` - 1, `date_upd` = NOW()
				WHERE `id_product` = '.(int)$id_product
			);
		elseif ($total_sales == 1)
			return Db::getInstance()->delete('product_sale', 'id_product = '.(int)$id_product);
		return true;
	}
}

Hope its help.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 6 months later...
  • 4 weeks later...
×
×
  • Create New...