From 5128852fb7c62e365a5656c153f6e3aeccd28c4c Mon Sep 17 00:00:00 2001 From: Dev Vitalyn Date: Wed, 9 Jun 2021 15:02:20 +0200 Subject: [PATCH 1/5] add rate return by product --- statsbestproducts.php | 70 ++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/statsbestproducts.php b/statsbestproducts.php index 288bda4..5eae84b 100644 --- a/statsbestproducts.php +++ b/statsbestproducts.php @@ -1,28 +1,28 @@ - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) - */ +/* +* 2007-2015 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 license@prestashop.com 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 +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ if (!defined('_PS_VERSION_')) { exit; @@ -107,11 +107,17 @@ public function __construct() 'header' => $this->trans('Active', array(), 'Admin.Global'), 'dataIndex' => 'active', 'align' => 'center' + ), + array( + 'id' => 'returnrate', + 'header' => $this->trans('% of return', array(), 'Modules.Statsbestproducts.Admin'), + 'dataIndex' => 'returnrate', + 'align' => 'center' ) ); $this->displayName = $this->trans('Best-selling products', array(), 'Modules.Statsbestproducts.Admin'); - $this->description = $this->trans('Enrich your stats with a small list of your best-sellers to better know your customers.', array(), 'Modules.Statsbestproducts.Admin'); + $this->description = $this->trans('Adds a list of the best-selling products to the Stats dashboard.', array(), 'Modules.Statsbestproducts.Admin'); $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_); } @@ -150,11 +156,11 @@ public function getData() $array_date_between = explode(' AND ', $date_between); $this->query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name, - ROUND(AVG(od.unit_price_tax_excl / o.conversion_rate), 2) as avgPriceSold, + ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold, IFNULL(stock.quantity, 0) as quantity, IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold, ROUND(IFNULL(IFNULL(SUM(od.product_quantity), 0) / (1 + LEAST(TO_DAYS('.$array_date_between[1].'), TO_DAYS(NOW())) - GREATEST(TO_DAYS('.$array_date_between[0].'), TO_DAYS(product_shop.date_add))), 0), 2) as averageQuantitySold, - ROUND(IFNULL(SUM((od.unit_price_tax_excl * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold, + ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold, ( SELECT IFNULL(SUM(pv.counter), 0) FROM '._DB_PREFIX_.'page pa @@ -191,6 +197,16 @@ public function getData() foreach ($values as &$value) { $value['avgPriceSold'] = Tools::displayPrice($value['avgPriceSold'], $currency); $value['totalPriceSold'] = Tools::displayPrice($value['totalPriceSold'], $currency); + $q = "SELECT count(oret.id_order_return) AS nr FROM "._DB_PREFIX_."order_return AS oret +LEFT JOIN "._DB_PREFIX_."order_return_detail AS ord ON (oret.id_order_return=ord.id_order_return) +LEFT JOIN "._DB_PREFIX_."order_detail AS od ON (ord.id_order_detail=od.id_order_detail) +LEFT JOIN "._DB_PREFIX_."product_attribute AS pa ON (od.product_attribute_id=pa.id_product_attribute) +LEFT JOIN "._DB_PREFIX_."order_return_state_lang AS status ON (oret.state=status.id_order_return_state) +WHERE status.id_lang='".(int)$this->getLang()."' +AND date_add BETWEEN $date_between +AND od.product_id='" . (int)$value['id_product'] . "';"; + $nb = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($q); + $value['returnrate'] = round($nb / $value['totalQuantitySold'] * 100, 2); } unset($value); From 1fc1151e703444d0f908bf162565208191b4c444 Mon Sep 17 00:00:00 2001 From: Dev Vitalyn Date: Wed, 9 Jun 2021 15:06:26 +0200 Subject: [PATCH 2/5] add rate return by product --- statsbestproducts.php | 57 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/statsbestproducts.php b/statsbestproducts.php index 5eae84b..685c4b6 100644 --- a/statsbestproducts.php +++ b/statsbestproducts.php @@ -1,28 +1,28 @@ -* @copyright 2007-2015 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ +/** + * Copyright since 2007 PrestaShop SA and Contributors + * PrestaShop is an International Registered Trademark & Property of PrestaShop SA + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License 3.0 (AFL-3.0) + * that is bundled with this package in the file LICENSE.md. + * It is also available through the world-wide-web at this URL: + * https://opensource.org/licenses/AFL-3.0 + * 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 license@prestashop.com 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 https://devdocs.prestashop.com/ for more information. + * + * @author PrestaShop SA and Contributors + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ if (!defined('_PS_VERSION_')) { exit; @@ -117,7 +117,7 @@ public function __construct() ); $this->displayName = $this->trans('Best-selling products', array(), 'Modules.Statsbestproducts.Admin'); - $this->description = $this->trans('Adds a list of the best-selling products to the Stats dashboard.', array(), 'Modules.Statsbestproducts.Admin'); + $this->description = $this->trans('Enrich your stats with a small list of your best-sellers to better know your customers.', array(), 'Modules.Statsbestproducts.Admin'); $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_); } @@ -156,11 +156,11 @@ public function getData() $array_date_between = explode(' AND ', $date_between); $this->query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name, - ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold, + ROUND(AVG(od.unit_price_tax_excl / o.conversion_rate), 2) as avgPriceSold, IFNULL(stock.quantity, 0) as quantity, IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold, ROUND(IFNULL(IFNULL(SUM(od.product_quantity), 0) / (1 + LEAST(TO_DAYS('.$array_date_between[1].'), TO_DAYS(NOW())) - GREATEST(TO_DAYS('.$array_date_between[0].'), TO_DAYS(product_shop.date_add))), 0), 2) as averageQuantitySold, - ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold, + ROUND(IFNULL(SUM((od.unit_price_tax_excl * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold, ( SELECT IFNULL(SUM(pv.counter), 0) FROM '._DB_PREFIX_.'page pa @@ -207,7 +207,8 @@ public function getData() AND od.product_id='" . (int)$value['id_product'] . "';"; $nb = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($q); $value['returnrate'] = round($nb / $value['totalQuantitySold'] * 100, 2); - } + + } unset($value); $this->_values = $values; From ac8bc41ff2fcc628a50d14e5b105a93a0c3c40b8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 9 Jun 2021 16:10:51 +0200 Subject: [PATCH 3/5] idents --- statsbestproducts.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/statsbestproducts.php b/statsbestproducts.php index 685c4b6..7e1aab5 100644 --- a/statsbestproducts.php +++ b/statsbestproducts.php @@ -108,7 +108,7 @@ public function __construct() 'dataIndex' => 'active', 'align' => 'center' ), - array( + array( 'id' => 'returnrate', 'header' => $this->trans('% of return', array(), 'Modules.Statsbestproducts.Admin'), 'dataIndex' => 'returnrate', @@ -197,18 +197,17 @@ public function getData() foreach ($values as &$value) { $value['avgPriceSold'] = Tools::displayPrice($value['avgPriceSold'], $currency); $value['totalPriceSold'] = Tools::displayPrice($value['totalPriceSold'], $currency); - $q = "SELECT count(oret.id_order_return) AS nr FROM "._DB_PREFIX_."order_return AS oret -LEFT JOIN "._DB_PREFIX_."order_return_detail AS ord ON (oret.id_order_return=ord.id_order_return) -LEFT JOIN "._DB_PREFIX_."order_detail AS od ON (ord.id_order_detail=od.id_order_detail) -LEFT JOIN "._DB_PREFIX_."product_attribute AS pa ON (od.product_attribute_id=pa.id_product_attribute) -LEFT JOIN "._DB_PREFIX_."order_return_state_lang AS status ON (oret.state=status.id_order_return_state) -WHERE status.id_lang='".(int)$this->getLang()."' -AND date_add BETWEEN $date_between -AND od.product_id='" . (int)$value['id_product'] . "';"; - $nb = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($q); - $value['returnrate'] = round($nb / $value['totalQuantitySold'] * 100, 2); - - } + $q = "SELECT count(oret.id_order_return) AS nr FROM "._DB_PREFIX_."order_return AS oret + LEFT JOIN "._DB_PREFIX_."order_return_detail AS ord ON (oret.id_order_return=ord.id_order_return) + LEFT JOIN "._DB_PREFIX_."order_detail AS od ON (ord.id_order_detail=od.id_order_detail) + LEFT JOIN "._DB_PREFIX_."product_attribute AS pa ON (od.product_attribute_id=pa.id_product_attribute) + LEFT JOIN "._DB_PREFIX_."order_return_state_lang AS status ON (oret.state=status.id_order_return_state) + WHERE status.id_lang='".(int)$this->getLang()."' + AND date_add BETWEEN $date_between + AND od.product_id='" . (int)$value['id_product'] . "';"; + $nb = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($q); + $value['returnrate'] = round($nb / $value['totalQuantitySold'] * 100, 2); + } unset($value); $this->_values = $values; From cd8dd28a69c2524fb57ad8592df1b144f1a5feda Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 9 Jun 2021 16:12:17 +0200 Subject: [PATCH 4/5] ident --- statsbestproducts.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/statsbestproducts.php b/statsbestproducts.php index 7e1aab5..fc7db6d 100644 --- a/statsbestproducts.php +++ b/statsbestproducts.php @@ -108,11 +108,11 @@ public function __construct() 'dataIndex' => 'active', 'align' => 'center' ), - array( - 'id' => 'returnrate', - 'header' => $this->trans('% of return', array(), 'Modules.Statsbestproducts.Admin'), - 'dataIndex' => 'returnrate', - 'align' => 'center' + array( + 'id' => 'returnrate', + 'header' => $this->trans('% of return', array(), 'Modules.Statsbestproducts.Admin'), + 'dataIndex' => 'returnrate', + 'align' => 'center' ) ); From df838d0f7263700acb72cd1d4978be58a30b4b8d Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 9 Jun 2021 16:17:30 +0200 Subject: [PATCH 5/5] idents --- statsbestproducts.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/statsbestproducts.php b/statsbestproducts.php index fc7db6d..52094cf 100644 --- a/statsbestproducts.php +++ b/statsbestproducts.php @@ -109,10 +109,10 @@ public function __construct() 'align' => 'center' ), array( - 'id' => 'returnrate', - 'header' => $this->trans('% of return', array(), 'Modules.Statsbestproducts.Admin'), - 'dataIndex' => 'returnrate', - 'align' => 'center' + 'id' => 'returnrate', + 'header' => $this->trans('% of return', array(), 'Modules.Statsbestproducts.Admin'), + 'dataIndex' => 'returnrate', + 'align' => 'center' ) );