Jump to content

Low stock notification emails


Recommended Posts

I think you'll need to change line 653 of modules/mailalerts/mailalerts.php from:
$merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails);

to:

$merchant_mails = array('[email protected]');

Of course, it's better to override the module instead of change the code directly so you don't lose the change when the module updates in the future. To do this, you'll need to create override/modules/mailalerts/mailalerts.php with the following:

<?php

class MailAlertsOverride extends MailAlerts
{
	public function hookActionProductCoverage($params)
	{
		// if not advanced stock management, nothing to do
		if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
			return;

		// retrieves informations
		$id_product = (int)$params['id_product'];
		$id_product_attribute = (int)$params['id_product_attribute'];
		$warehouse = $params['warehouse'];
		$product = new Product($id_product);

		if (!Validate::isLoadedObject($product))
			return;

		if (!$product->advanced_stock_management)
			return;

		// sets warehouse id to get the coverage
		if (!Validate::isLoadedObject($warehouse))
			$id_warehouse = 0;
		else
			$id_warehouse = (int)$warehouse->id;

		// coverage of the product
		$warning_coverage = (int)Configuration::getGlobalValue('MA_PRODUCT_COVERAGE');

		$coverage = StockManagerFactory::getManager()->getProductCoverage($id_product, $id_product_attribute, $warning_coverage, $id_warehouse);

		// if we need to send a notification
		if ($product->active == 1 &&
			($coverage < $warning_coverage) && !empty($this->merchant_mails) &&
			Configuration::getGlobalValue('MA_MERCHANT_COVERAGE'))
		{
			$context = Context::getContext();
			$id_lang = (int)$context->language->id;
			$id_shop = (int)$context->shop->id;
			$iso = Language::getIsoById($id_lang);
			$product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang);
			$template_vars = array(
				'{current_coverage}' => $coverage,
				'{warning_coverage}' => $warning_coverage,
				'{product}' => pSQL($product_name)
			);

			if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.txt') &&
				file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.html'))
			{
				// Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
				$merchant_mails = array('[email protected]');
				foreach ($merchant_mails as $merchant_mail)
				{
					Mail::Send(
						$id_lang,
						'productcoverage',
						Mail::l('Stock coverage', $id_lang),
						$template_vars,
						$merchant_mail,
						null,
						(string)Configuration::get('PS_SHOP_EMAIL'),
						(string)Configuration::get('PS_SHOP_NAME'),
						null,
						null,
						dirname(__FILE__).'/mails/',
						null,
						$id_shop
					);
				}
			}
		}
	}
}
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...