From 7ee95c63f6fc6fba502873ff36c231526897067f Mon Sep 17 00:00:00 2001 From: rGaillard Date: Tue, 2 Oct 2012 18:57:39 +0000 Subject: [PATCH] // Fix #PSCFV-4628 --- classes/Image.php | 10 +++++++--- classes/Product.php | 3 +-- classes/shop/Shop.php | 2 +- classes/stock/StockAvailable.php | 20 +++++++++++++++++++ controllers/admin/AdminProductsController.php | 14 ++++++++++--- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/classes/Image.php b/classes/Image.php index 8559d2ca0..4ffc68ba7 100644 --- a/classes/Image.php +++ b/classes/Image.php @@ -89,9 +89,13 @@ class ImageCore extends ObjectModel public function delete() { - if (!parent::delete() || - !$this->deleteProductAttributeImage() || - !$this->deleteImage()) + if (!parent::delete()) + return false; + + if ($this->hasMultishopEntries()) + return true; + + if (!$this->deleteProductAttributeImage() || !$this->deleteImage()) return false; // update positions diff --git a/classes/Product.php b/classes/Product.php index 2204a7071..907206df5 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -660,11 +660,10 @@ class ProductCore extends ObjectModel if ($real_quantity > $physical_quantity) return false; } + $result = parent::delete(); // Removes the product from StockAvailable, for the current shop StockAvailable::removeProductFromStockAvailable($this->id); - - $result = parent::delete(); $result &= ($this->deleteProductAttributes() && $this->deleteImages() && $this->deleteSceneProducts()); // If there are still entries in product_shop, don't remove completly the product if ($this->hasMultishopEntries()) diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index 13a63708b..56c8dc6f4 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -749,7 +749,7 @@ class ShopCore extends ObjectModel */ public static function getSharedShops($shop_id, $type) { - if (!in_array($type, array(Shop::SHARE_CUSTOMER, Shop::SHARE_ORDER))) + if (!in_array($type, array(Shop::SHARE_CUSTOMER, Shop::SHARE_ORDER, SHOP::SHARE_STOCK))) die('Wrong argument ($type) in Shop::getSharedShops() method'); Shop::cacheShops(); diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php index 0db8a5c79..43091c1e0 100644 --- a/classes/stock/StockAvailable.php +++ b/classes/stock/StockAvailable.php @@ -521,6 +521,26 @@ class StockAvailableCore extends ObjectModel { if (!Validate::isUnsignedId($id_product)) return false; + + if (Shop::getContext() == SHOP::CONTEXT_SHOP) + if (Shop::getContextShopGroup()->share_stock == 1) + { + $pa_sql = ''; + if ($id_product_attribute !== null) + { + $pa_sql = '_attribute'; + $id_product_attribute_sql = $id_product_attribute; + } + else + $id_product_attribute_sql = $id_product; + + if ((int)Db::getInstance()->getValue('SELECT COUNT(*) + FROM '._DB_PREFIX_.'product'.$pa_sql.'_shop + WHERE id_product'.$pa_sql.'='.(int)$id_product_attribute_sql.' + AND id_shop IN ('.implode(',', array_map('intval', Shop::getContextListShopID(SHOP::SHARE_STOCK))).')')) + return true; + } + return Db::getInstance()->execute(' DELETE FROM '._DB_PREFIX_.'stock_available WHERE id_product = '.(int)$id_product. diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 9e15a110c..da9f5116e 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -144,15 +144,21 @@ class AdminProductsControllerCore extends AdminController $alias = 'sa'; $alias_image = 'image_shop'; if (Shop::getContext() == Shop::CONTEXT_SHOP) + { $this->_join .= ' JOIN `'._DB_PREFIX_.'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = '.(int)$this->context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = '.(int)$this->context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.(int)$this->context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop='.(int)$this->context->shop->id.')'; + $this->_where .= 'AND (i.id_image IS NULL OR image_shop.id_shop='.(int)$this->context->shop->id.')'; + } else + { $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = a.id_shop_default) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default) LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = a.id_shop_default) LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop=a.id_shop_default)'; + $this->_where .= 'AND (i.id_image IS NULL OR image_shop.id_shop=a.id_shop_default)'; + } $this->_select .= 'shop.name as shopname, '; } else @@ -168,9 +174,6 @@ class AdminProductsControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0 '.StockAvailable::addSqlShopRestriction(null, null, 'sav').') '; $this->_select .= 'cl.name `name_category` '.($join_category ? ', cp.`position`' : '').', '.$alias_image.'.`id_image`, '.$alias.'.`price`, ('.$alias.'.`price` * ((100 + (t.`rate`))/100)) AS price_final, sav.`quantity` as sav_quantity, '.$alias.'.`active`'; - - if (Shop::isFeatureActive()) - $this->_where .= ' AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1))'; $this->fields_list = array(); $this->fields_list['id_product'] = array( @@ -3413,6 +3416,11 @@ class AdminProductsControllerCore extends AdminController $shops = false; if (Shop::isFeatureActive()) $shops = Shop::getShops(); + + foreach ($shops as $key => $shop) + if (!$obj->isAssociatedToShop($shop['id_shop'])) + unset($shops[$key]); + $data->assign('shops', $shops); $count_images = Db::getInstance()->getValue('