From f4265754058d3da9659bfbadaf387f95a53be791 Mon Sep 17 00:00:00 2001 From: dSevere Date: Fri, 2 Dec 2011 17:31:16 +0000 Subject: [PATCH] // Stock Available : Improve BackOffice interfaces with groups of shops management + bugs fix --- admin-dev/themes/template/manufacturers/view.tpl | 14 +++++++------- admin-dev/themes/template/suppliers/view.tpl | 4 ++-- classes/Cart.php | 6 +++--- classes/Category.php | 2 +- classes/Manufacturer.php | 2 +- classes/Product.php | 16 ++++++++-------- classes/ProductSale.php | 2 +- classes/Search.php | 4 ++-- classes/Supplier.php | 2 +- classes/stock/StockAvailable.php | 14 +++++++++----- .../admin/AdminManufacturersController.php | 3 ++- controllers/admin/AdminSuppliersController.php | 5 +++-- controllers/admin/AdminTrackingController.php | 4 ++-- 13 files changed, 42 insertions(+), 36 deletions(-) diff --git a/admin-dev/themes/template/manufacturers/view.tpl b/admin-dev/themes/template/manufacturers/view.tpl index 4434ab7ec..e97ec785b 100644 --- a/admin-dev/themes/template/manufacturers/view.tpl +++ b/admin-dev/themes/template/manufacturers/view.tpl @@ -29,10 +29,10 @@ {block name="override_tpl"}

{$manufacturer->name}

- +

{l s='Total addresses:'} {count($addresses)}


- + {if !count($addresses)} {l s='No address for this manufacturer'} {else} @@ -61,7 +61,7 @@ {/foreach} {/if}

- +

{l s='Total products:'} {count($products)}

{foreach $products AS $product}
@@ -70,7 +70,7 @@ {l s='Edit'} {l s='Delete'} - +
{if !empty($product->reference)}{/if} @@ -85,13 +85,13 @@ {l s='Delete'}

{$product->name}

-
{$product->name}{l s='Ref:'} {$product->reference}
+
- {if $stock_management}{/if} + {if $stock_management && $shopContext != Shop::CONTEXT_ALL}{/if} {foreach $product->combinaison AS $id_product_attribute => $product_attribute} @@ -99,7 +99,7 @@ - {if $stock_management}{/if} + {if $stock_management && $shopContext != Shop::CONTEXT_ALL}{/if} {/foreach}
{l s='Attribute name'} {l s='Reference'} {l s='EAN13'} {l s='UPC'}{l s='Quantity'}{l s='Available Quantity'}
{$product_attribute.reference} {$product_attribute.ean13} {$product_attribute.upc}{$product_attribute.quantity}{$product_attribute.quantity}
diff --git a/admin-dev/themes/template/suppliers/view.tpl b/admin-dev/themes/template/suppliers/view.tpl index e4c755b2b..fe1d4f8c2 100644 --- a/admin-dev/themes/template/suppliers/view.tpl +++ b/admin-dev/themes/template/suppliers/view.tpl @@ -51,7 +51,7 @@ {l s='Reference'} {l s='EAN13'} {l s='UPC'} - {if $stock_management}{l s='Available Quantity'}{/if} + {if $stock_management && $shopContext != Shop::CONTEXT_ALL}{l s='Available Quantity'}{/if} {foreach $product->combinaison AS $id_product_attribute => $product_attribute} @@ -59,7 +59,7 @@ {$product_attribute.reference} {$product_attribute.ean13} {$product_attribute.upc} - {if $stock_management}{$product_attribute.quantity}{/if} + {if $stock_management && $shopContext != Shop::CONTEXT_ALL}{$product_attribute.quantity}{/if} {/foreach} diff --git a/classes/Cart.php b/classes/Cart.php index 6d714010d..9595155f4 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -394,7 +394,7 @@ class CartCore extends ObjectModel pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`, p.`price`, p.`weight`, stock.`quantity` quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`active`, p.`date_add`, - p.`date_upd`, t.`id_tax`, tl.`name` AS tax, t.`rate`, stock.quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category, + p.`date_upd`, t.`id_tax`, tl.`name` AS tax, t.`rate`, IFNULL(stock.quantity, 0), pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`, cp.`id_address_delivery`) AS unique_id, cp.id_address_delivery'); // Build FROM @@ -783,7 +783,7 @@ class CartCore extends ObjectModel { if ($operator == 'up') { - $sql = 'SELECT stock.out_of_stock, stock.quantity + $sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) FROM '._DB_PREFIX_.'product p '.Product::sqlStock('p', $id_product_attribute, true, $shop).' WHERE p.id_product = '.$id_product; @@ -825,7 +825,7 @@ class CartCore extends ObjectModel /* Add product to the cart */ else { - $sql = 'SELECT stock.out_of_stock, stock.quantity + $sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) FROM '._DB_PREFIX_.'product p '.Product::sqlStock('p', $id_product_attribute, true, $shop).' WHERE p.id_product = '.$id_product; diff --git a/classes/Category.php b/classes/Category.php index 2ab014672..e852c9dc0 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -597,7 +597,7 @@ class CategoryCore extends ObjectModel return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } - $sql = 'SELECT p.*, stock.out_of_stock, stock.quantity as quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, + $sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), diff --git a/classes/Manufacturer.php b/classes/Manufacturer.php index c16477413..28cd6e3ce 100644 --- a/classes/Manufacturer.php +++ b/classes/Manufacturer.php @@ -335,7 +335,7 @@ class ManufacturerCore extends ObjectModel return (int)count($result); } - $sql = 'SELECT p.*, stock.out_of_stock, stock.quantity as quantity, pa.`id_product_attribute`, + $sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, DATEDIFF( diff --git a/classes/Product.php b/classes/Product.php index 277016d7e..e13a6bb5f 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -571,7 +571,7 @@ class ProductCore extends ObjectModel FROM '._DB_PREFIX_.'product_attribute pa' .($minimum_quantity > 0 ? Product::sqlStock('pa', 'pa') : ''). ' WHERE pa.default_on = 1 ' - .($minimum_quantity > 0 ? ' AND stock.quantity >= '.(int)$minimum_quantity : ''). + .($minimum_quantity > 0 ? ' AND IFNULL(stock.quantity, 0) >= '.(int)$minimum_quantity : ''). ' AND pa.id_product = '.(int)$id_product; $result = Db::getInstance()->getValue($sql); @@ -581,7 +581,7 @@ class ProductCore extends ObjectModel FROM '._DB_PREFIX_.'product_attribute pa' .($minimum_quantity > 0 ? Product::sqlStock('pa', 'pa') : ''). ' WHERE pa.id_product = '.(int)$id_product - .($minimum_quantity > 0 ? ' AND stock.quantity >= '.(int)$minimum_quantity : ''); + .($minimum_quantity > 0 ? ' AND IFNULL(stock.quantity, 0) >= '.(int)$minimum_quantity : ''); $result = Db::getInstance()->getValue($sql); } @@ -1632,7 +1632,7 @@ class ProductCore extends ObjectModel if (!Combination::isFeatureActive()) return array(); $sql = 'SELECT pa.*, GROUP_CONCAT(agl.`name`, \''.pSQL($attribute_value_separator).'\', - al.`name` SEPARATOR \''.pSQL($attribute_separator).'\') as attribute_designation, stock.quantity + al.`name` SEPARATOR \''.pSQL($attribute_separator).'\') as attribute_designation, IFNULL(stock.quantity, 0) FROM `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute` @@ -1656,7 +1656,7 @@ class ProductCore extends ObjectModel if (!Combination::isFeatureActive()) return array(); $sql = 'SELECT pa.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, al.`name` AS attribute_name, - a.`id_attribute`, pa.`unit_price_impact`, stock.quantity + a.`id_attribute`, pa.`unit_price_impact`, IFNULL(stock.quantity, 0) as quantity FROM `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute` @@ -1775,7 +1775,7 @@ class ProductCore extends ObjectModel $sql = new DbQuery(); $sql->select( - 'p.*, stock.out_of_stock, stock.quantity as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, + 'p.*, 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`, p.`ean13`, p.`upc`, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name, DATEDIFF( p.`date_add`, @@ -1972,7 +1972,7 @@ class ProductCore extends ObjectModel return (int)$result['nb']; } - $sql = 'SELECT p.*, stock.out_of_stock, stock.quantity as quantity, pl.`description`, pl.`description_short`, + $sql = 'SELECT p.*, 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`, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name, DATEDIFF( @@ -2766,7 +2766,7 @@ class ProductCore extends ObjectModel return array(); $sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, pa.`id_product_attribute`, - stock.quantity, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`, pa.`unit_price_impact`, + IFNULL(stock.quantity, 0) as quantity, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`, pa.`unit_price_impact`, pa.`minimal_quantity`, pa.`available_date`, ag.`group_type` FROM `'._DB_PREFIX_.'product_attribute` pa '.Product::sqlStock('pa', 'pa').' @@ -2838,7 +2838,7 @@ class ProductCore extends ObjectModel if (!$context) $context = Context::getContext(); - $sql = 'SELECT p.*, stock.out_of_stock, stock.quantity as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, + $sql = 'SELECT p.*, 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`, p.`ean13`, p.`upc`, i.`id_image`, il.`legend`, t.`rate`, m.`name` as manufacturer_name, cl.`name` AS category_default, DATEDIFF( diff --git a/classes/ProductSale.php b/classes/ProductSale.php index 1ecbc3763..708dc4d08 100644 --- a/classes/ProductSale.php +++ b/classes/ProductSale.php @@ -78,7 +78,7 @@ class ProductSaleCore $groups = FrontController::getCurrentCustomerGroups(); $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); - $sql = 'SELECT p.*, stock.out_of_stock, stock.quantity as quantity, + $sql = 'SELECT p.*, 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, i.`id_image`, il.`legend`, ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`, diff --git a/classes/Search.php b/classes/Search.php index 4166b4b16..7f0879493 100644 --- a/classes/Search.php +++ b/classes/Search.php @@ -263,7 +263,7 @@ class SearchCore return $db->executeS($sql); } - $sql = 'SELECT p.*, stock.out_of_stock, stock.quantity as quantity, + $sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name '.$score.', DATEDIFF( @@ -600,7 +600,7 @@ class SearchCore return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } - $sql = 'SELECT DISTINCT p.*, stock.out_of_stock, stock.quantity as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`, + $sql = 'SELECT DISTINCT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name, 1 position, DATEDIFF( p.`date_add`, diff --git a/classes/Supplier.php b/classes/Supplier.php index a12d56394..e887cc2bb 100644 --- a/classes/Supplier.php +++ b/classes/Supplier.php @@ -231,7 +231,7 @@ class SupplierCore extends ObjectModel $nb_days_new_product = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20; $sql = 'SELECT p.*, stock.out_of_stock, - stock.quantity as quantity, + IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php index 36e8c62ee..775c6f835 100644 --- a/classes/stock/StockAvailable.php +++ b/classes/stock/StockAvailable.php @@ -540,7 +540,6 @@ class StockAvailableCore extends ObjectModel public static function addSqlShopRestriction(DbQuery $sql = null, $id_shop = null, $alias = null) { $context = Context::getContext(); - $group_ok = false; if (!empty($alias)) $alias .= '.'; @@ -565,12 +564,17 @@ class StockAvailableCore extends ObjectModel $sql = ' AND '.pSQL($alias).'id_group_shop = '.(int)$group_shop->id.' '; $sql .= ' AND '.pSQL($alias).'id_shop = 0 '; } - - $group_ok = true; } - + // else if we are in group context + else if ($context->shop() == Shop::CONTEXT_GROUP) + { + if (is_object($sql)) + $sql->where(pSQL($alias).'id_shop IN ('.implode(', ', Shop::getShops(true, $group_shop->id, true)).')'); + else + $sql = ' AND '.pSQL($alias).'id_shop IN ('.implode(', ', Shop::getShops(true, $group_shop->id, true)).') '; + } // if no group specific restriction, set simple shop restriction - if (!$group_ok) + else { if (is_object($sql)) $sql->where(pSQL($alias).'id_shop = '.(int)$id_shop); diff --git a/controllers/admin/AdminManufacturersController.php b/controllers/admin/AdminManufacturersController.php index f86b4bc59..f6c8731e3 100644 --- a/controllers/admin/AdminManufacturersController.php +++ b/controllers/admin/AdminManufacturersController.php @@ -89,7 +89,7 @@ class AdminManufacturersControllerCore extends AdminController parent::__construct(); } - + public function setMedia() { parent::setMedia(); @@ -606,6 +606,7 @@ class AdminManufacturersControllerCore extends AdminController 'addresses' => $addresses, 'products' => $products, 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), + 'shopContext' => Context::getContext()->shop(), ); return parent::renderView(); diff --git a/controllers/admin/AdminSuppliersController.php b/controllers/admin/AdminSuppliersController.php index 9450cbfb4..98a62a71b 100644 --- a/controllers/admin/AdminSuppliersController.php +++ b/controllers/admin/AdminSuppliersController.php @@ -53,14 +53,14 @@ class AdminSuppliersControllerCore extends AdminController parent::__construct(); } - + public function setMedia() { parent::setMedia(); $this->addJqueryUi('ui.widget'); $this->addJqueryPlugin('tagify'); } - + public function renderForm() { $this->fields_form = array( @@ -201,6 +201,7 @@ class AdminSuppliersControllerCore extends AdminController 'supplier' => $this->object, 'products' => $products, 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), + 'shopContext' => Context::getContext()->shop(), ); return parent::renderView(); diff --git a/controllers/admin/AdminTrackingController.php b/controllers/admin/AdminTrackingController.php index aa851dd18..9eb600634 100644 --- a/controllers/admin/AdminTrackingController.php +++ b/controllers/admin/AdminTrackingController.php @@ -125,7 +125,7 @@ class AdminTrackingController extends AdminController SELECT DISTINCT(id_product) FROM `'._DB_PREFIX_.'product_attribute` ) - AND stock.quantity <= 0 + AND IFNULL(stock.quantity, 0) <= 0 )'; $this->tpl_list_vars = array('sub_title' => $this->l('List of products with attributes and without available quantities for sale:')); @@ -163,7 +163,7 @@ class AdminTrackingController extends AdminController SELECT DISTINCT(id_product) FROM `'._DB_PREFIX_.'product_attribute` ) - AND stock.quantity <= 0 + AND IFNULL(stock.quantity, 0) <= 0 )'; $this->tpl_list_vars = array('sub_title' => $this->l('List of products without attributes and without available quantities for sale:'));