diff --git a/mailalerts.php b/mailalerts.php index 3b31064..4a2537e 100644 --- a/mailalerts.php +++ b/mailalerts.php @@ -492,7 +492,7 @@ public function hookActionUpdateQuantity($params) $quantity = (int)$params['quantity']; $context = Context::getContext(); - $id_shop = (int)$context->shop->id; + $id_shop = (Shop::getContext() == Shop::CONTEXT_SHOP) ? (int)$context->shop->id : null; $id_lang = (int)$context->language->id; $product = new Product($id_product, false, $id_lang, $id_shop, $context); $product_has_attributes = $product->hasAttributes(); @@ -508,8 +508,15 @@ public function hookActionUpdateQuantity($params) $check_oos = ($product_has_attributes && $id_product_attribute) || (!$product_has_attributes && !$id_product_attribute); + $productActive = false; + if (Shop::getContext() == Shop::CONTEXT_SHOP) { + $productActive = $product->active; + } else { + $productActive = $this->isActiveInShopGroup($id_product, (int)Shop::getContextShopGroupID()); + } + if ($check_oos && - $product->active == 1 && + $productActive == 1 && (int)$quantity <= $ma_last_qties && !(!$this->merchant_oos || empty($this->merchant_mails)) && $configuration['PS_STOCK_MANAGEMENT']) @@ -1073,4 +1080,21 @@ public function getConfigFieldsValues() 'MA_RETURN_SLIP' => Tools::getValue('MA_RETURN_SLIP', Configuration::get('MA_RETURN_SLIP')), ); } + + /** + * //check if the product is activated at least in a Group shop + * @param int $idProduct + * @param int $idShopGroup + * @return boolean + */ + public function isActiveInShopGroup($idProduct, $idShopGroup) + { + $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + SELECT ps.`id_product` + FROM `' . _DB_PREFIX_ . 'product_shop` ps + INNER JOIN `' . _DB_PREFIX_ . 'shop` s ON (ps.`id_shop` = s.`id_shop`) + WHERE ps.`id_product` = ' . $idProduct . ' AND ps.`active` = 1 AND s.`id_shop_group` = ' . (int)$idShopGroup); + + return (!empty($result)); + } }