Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Fix the problem of Out of stock email not sending #34

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions mailalerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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'])
Expand Down Expand Up @@ -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));
}
}