diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php
index 2acdb725a..7ee809d1d 100644
--- a/controllers/admin/AdminProductsController.php
+++ b/controllers/admin/AdminProductsController.php
@@ -2044,6 +2044,8 @@ class AdminProductsControllerCore extends AdminController
{
if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product'))))
{
+ $update_product = false;
+
// Get all available suppliers
$suppliers = Supplier::getSuppliers();
@@ -2089,6 +2091,13 @@ class AdminProductsControllerCore extends AdminController
}
}
+ // Manage defaut supplier for product
+ if ($new_default_supplier != 0 && $new_default_supplier != $product->id_supplier && Supplier::supplierExists($new_default_supplier))
+ {
+ $product->id_supplier = $new_default_supplier;
+ $update_product = true;
+ }
+
$this->confirmations[] = $this->l('Suppliers of the product have been updated');
// Get all id_product_attribute
@@ -2169,17 +2178,32 @@ class AdminProductsControllerCore extends AdminController
}
}
+ // Retro-compatibility code
if ($product->id_supplier == $supplier->id_supplier)
- $product->wholesale_price = Tools::convertPrice($price, $id_currency);
+ {
+ if ((int)$attribute['id_product_attribute'] > 0)
+ {
+ Db::getInstance()->execute('
+ UPDATE '._DB_PREFIX_.'product_attribute
+ SET supplier_reference = '.$reference.',
+ wholesale_price = '.Tools::convertPrice($price, $id_currency).'
+ WHERE id_product = '.(int)$product->id.'
+ AND id_product_attribute = '.(int)$attribute['id_product_attribute'].'
+ LIMIT 1
+ ');
+ }
+ else
+ {
+ $product->wholesale_price = Tools::convertPrice($price, $id_currency); //converted in the default currency
+ $product->supplier_reference = $reference;
+ $update_product = true;
+ }
+ }
}
}
- // Manage defaut supplier for product
- if ($new_default_supplier != 0 && $new_default_supplier != $product->id_supplier && Supplier::supplierExists($new_default_supplier))
- {
- $product->id_supplier = $new_default_supplier;
+ if ($update_product)
$product->update();
- }
$this->confirmations[] = $this->l('Supplier Reference(s) of the product have been updated');
}
diff --git a/modules/statsbestproducts/statsbestproducts.php b/modules/statsbestproducts/statsbestproducts.php
index f5269f0d8..ce0289fe0 100644
--- a/modules/statsbestproducts/statsbestproducts.php
+++ b/modules/statsbestproducts/statsbestproducts.php
@@ -1,6 +1,6 @@
'quantity',
- 'header' => $this->l('Stock'),
+ 'header' => $this->l('Available Quantity for sale'),
'dataIndex' => 'quantity',
- 'width' => 50,
+ 'width' => 150,
'align' => 'right'
)
);
@@ -149,8 +149,9 @@ class StatsBestProducts extends ModuleGrid
$dateBetween = $this->getDate();
$arrayDateBetween = explode(' AND ', $dateBetween);
- $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,
- IFNULL((SELECT SUM(pa.quantity) FROM '._DB_PREFIX_.'product_attribute pa WHERE pa.id_product = p.id_product GROUP BY pa.id_product), p.quantity) as quantity,
+ $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,
+ 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('.$arrayDateBetween[1].'), TO_DAYS(NOW())) - GREATEST(TO_DAYS('.$arrayDateBetween[0].'), TO_DAYS(p.date_add))), 0), 2) as averageQuantitySold,
ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold,
@@ -168,6 +169,7 @@ class StatsBestProducts extends ModuleGrid
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->getLang().$this->context->shop->addSqlRestrictionOnLang('pl').')
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
+ '.Product::sqlStock('p', 0).'
WHERE p.active = 1
AND o.valid = 1
AND o.invoice_date BETWEEN '.$dateBetween.'
diff --git a/modules/statscheckup/statscheckup.php b/modules/statscheckup/statscheckup.php
index 0144a2171..eb7bf84f6 100644
--- a/modules/statscheckup/statscheckup.php
+++ b/modules/statscheckup/statscheckup.php
@@ -110,7 +110,7 @@ class StatsCheckUp extends Module
1 => '
',
2 => '
'
);
- $tokenProducts = Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)Context::getContext()->employee->id);
+ $tokenProducts = Tools::getAdminToken('AdminProducts'.(int)(Tab::getIdFromClassName('AdminProducts')).(int)Context::getContext()->employee->id);
$divisor = 4;
$totals = array('products' => 0, 'active' => 0, 'images' => 0, 'sales' => 0, 'stock' => 0);
foreach ($languages as $language)
@@ -138,12 +138,10 @@ class StatsCheckUp extends Module
WHERE od.product_id = p.id_product
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().'
'.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').'
- ) as nbSales, IFNULL((
- SELECT SUM(pa.quantity)
- FROM '._DB_PREFIX_.'product_attribute pa
- WHERE pa.id_product = p.id_product
- ), p.quantity) as stock
+ ) as nbSales,
+ IFNULL(stock.quantity, 0) as stock
FROM '._DB_PREFIX_.'product p
+ '.Product::sqlStock('p', 0).'
LEFT JOIN '._DB_PREFIX_.'product_lang pl
ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').')
'.$this->context->shop->addSqlAssociation('product', 'p').'
@@ -157,7 +155,7 @@ class StatsCheckUp extends Module
'DESCRIPTIONS' => array('name' => $this->l('Descriptions'), 'text' => $this->l('chars (without HTML)')),
'IMAGES' => array('name' => $this->l('Images'), 'text' => $this->l('images')),
'SALES' => array('name' => $this->l('Sales'), 'text' => $this->l('orders / month')),
- 'STOCK' => array('name' => $this->l('Stock'), 'text' => $this->l('items'))
+ 'STOCK' => array('name' => $this->l('Available quantities for sale'), 'text' => $this->l('items'))
);
$this->html = '
@@ -213,7 +211,7 @@ class StatsCheckUp extends Module
$this->html .= '
* '.$this->l('Correspond to the default wholesale price according to the default supplier for the product. An average price is used when the product has attributes.').'