diff --git a/classes/Link.php b/classes/Link.php index 25853b103..70e1b501c 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -98,7 +98,7 @@ class LinkCore if (is_array($product) && isset($product['id_product'])) $product = new Product($product['id_product'], false, $id_lang); else if (is_numeric($product) || !$product) - $product = new Product($product, false, $id_lang); + $product = new Product($product, false, $id_lang); else throw new PrestaShopException('Invalid product vars'); } diff --git a/classes/Product.php b/classes/Product.php index 7b6f23ffd..42a50222a 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -2451,17 +2451,19 @@ class ProductCore extends ObjectModel } $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); - foreach ($res as $row) - self::$_pricesLevel2[$cache_id_2][(int)$row['id_product_attribute']] = array( - 'price' => $row['price'], - 'ecotax' => $row['ecotax'], - 'attribute_price' => (isset($row['attribute_price']) ? $row['attribute_price'] : null) - ); - if ($default_on) - self::$_pricesLevel2[$cache_id_2][0] = array('price' => $row['price'], - 'ecotax' => $row['ecotax'], - 'attribute_price' => $row['attribute_price']); - + if ($res) + { + foreach ($res as $row) + self::$_pricesLevel2[$cache_id_2][(int)$row['id_product_attribute']] = array( + 'price' => $row['price'], + 'ecotax' => $row['ecotax'], + 'attribute_price' => (isset($row['attribute_price']) ? $row['attribute_price'] : null) + ); + if ($default_on) + self::$_pricesLevel2[$cache_id_2][0] = array('price' => $row['price'], + 'ecotax' => $row['ecotax'], + 'attribute_price' => $row['attribute_price']); + } } $result = self::$_pricesLevel2[$cache_id_2][(int)$id_product_attribute]; diff --git a/classes/helper/HelperForm.php b/classes/helper/HelperForm.php index b49c662c2..45e24be2b 100644 --- a/classes/helper/HelperForm.php +++ b/classes/helper/HelperForm.php @@ -137,8 +137,8 @@ class HelperFormCore extends Helper break; case 'shop' : - $params['html'] = $this->renderAssoShop($params['type']); - $shops = Shop::getShops(true, null, true); + $disable_shops = isset($params['disable_shared']) ? $params['disable_shared'] : false; + $params['html'] = $this->renderAssoShop($disable_shops); if (Shop::getTotalShops(false) == 1) unset($this->fields_form[$fieldset_key]['form']['input'][$key]); break; @@ -190,7 +190,7 @@ class HelperFormCore extends Helper * * @return string */ - public function renderAssoShop() + public function renderAssoShop($disable_shared = false) { if (!Shop::isFeatureActive()) return; @@ -228,8 +228,11 @@ class HelperFormCore extends Helper $tpl = $this->createTemplate('assoshop.tpl'); $tree = Shop::getTree(); $nb_shop = 0; - foreach ($tree as $value) + foreach ($tree as &$value) + { + $value['disable_shops'] = (isset($value[$disable_shared]) && $value[$disable_shared]); $nb_shop += count($value['shops']); + } $tpl->assign(array( 'input' => array( 'type' => 'shop', diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index 7b7e2f105..4dc82645b 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -117,6 +117,7 @@ class ShopCore extends ObjectModel */ const SHARE_CUSTOMER = 'share_customer'; const SHARE_ORDER = 'share_order'; + const SHARE_STOCK = 'share_stock'; /** * On shop instance, get its theme and URL data too @@ -574,6 +575,7 @@ class ShopCore extends ObjectModel 'name' => $row['group_name'], 'share_customer' => $row['share_customer'], 'share_order' => $row['share_order'], + 'share_stock' => $row['share_stock'], 'shops' => array(), ); diff --git a/classes/stock/Warehouse.php b/classes/stock/Warehouse.php index 6f635c469..aa77ea9e0 100644 --- a/classes/stock/Warehouse.php +++ b/classes/stock/Warehouse.php @@ -309,8 +309,6 @@ class WarehouseCore extends ObjectModel */ public static function getProductWarehouseList($id_product, $id_product_attribute = 0, $id_shop = null) { - if (is_null($id_shop)) - $id_shop = Context::getContext()->shop->id; // if it's a pack, returns warehouses if and only if some products use the advanced stock management if (Pack::isPack($id_product)) @@ -321,11 +319,30 @@ class WarehouseCore extends ObjectModel $res[]['id_warehouse'] = $warehouse; return $res; } + $share_stock = false; + if ($id_shop === null) + { + if (Shop::getContext() == Shop::CONTEXT_GROUP) + $shop_group = Shop::getContextShopGroup(); + else + $shop_group = Context::getContext()->shop->getGroup(); + $share_stock = $shop_group->share_stock; + } + else + { + $shop_group = Shop::getGroupFromShop($id_shop); + $share_stock = $shop_group['share_stock']; + } + + if ($share_stock) + $ids_shop = Shop::getShops(true, (int)$shop_group->id, true); + else + $ids_shop = array((int)Context::getContext()->shop->id); $query = new DbQuery(); $query->select('wpl.id_warehouse, CONCAT(w.reference, " - ", w.name) as name'); $query->from('warehouse_product_location', 'wpl'); - $query->innerJoin('warehouse_shop', 'ws', 'ws.id_warehouse = wpl.id_warehouse AND id_shop = '.(int)$id_shop); + $query->innerJoin('warehouse_shop', 'ws', 'ws.id_warehouse = wpl.id_warehouse AND id_shop IN ('.implode(',', array_map('intval', $ids_shop)).')'); $query->innerJoin('warehouse', 'w', 'ws.id_warehouse = w.id_warehouse'); $query->where('id_product = '.(int)$id_product); $query->where('id_product_attribute = '.(int)$id_product_attribute); diff --git a/controllers/admin/AdminWarehousesController.php b/controllers/admin/AdminWarehousesController.php index 91fe9323f..8b5a36730 100644 --- a/controllers/admin/AdminWarehousesController.php +++ b/controllers/admin/AdminWarehousesController.php @@ -273,6 +273,7 @@ class AdminWarehousesControllerCore extends AdminController 'label' => $this->l('Shops:'), 'name' => 'checkBoxShopAsso', 'desc' => $this->l('Associated shops'), + 'disable_shared' => Shop::SHARE_STOCK ); } diff --git a/modules/carriercompare/template/configuration.tpl b/modules/carriercompare/template/configuration.tpl index 132871ad4..f27cb18da 100644 --- a/modules/carriercompare/template/configuration.tpl +++ b/modules/carriercompare/template/configuration.tpl @@ -6,7 +6,7 @@ {/if} {/if} -