Jump to content


Photo

out of stock product notification to admin


  • Please log in to reply
1 reply to this topic

#1 akroma

akroma

    Member

  • Members
  • PipPip
  • 13 posts

Posted 11 January 2018 - 10:41 AM

Hello good afternoon. 
I have this code to send a notice to the administrator

//nuevo envio correo 

public function sendEmailProductOutOfStock($id_customer, $id_product, $id_product_attribute, $id_shop=null, $id_lang=null, $guest_email=null) 
{


$context = Context::getContext();
if (is_null($id_shop)) 
$id_shop = (int)$context->shop->id; 
if (is_null($id_lang)) 
$id_lang = (int)$context->language->id;
$customer = new Customer($id_customer); 
$customer_email = $customer->email; 
$customer_firstname = $customer->firstname; 
$customer_lastname = $customer->lastname; 
$guest_email = pSQL($guest_email);
$id_customer = (int)$id_customer; 
$customer_email = pSQL($customer_email);
if ($id_customer==0) 
$customer_email = $guest_email;
$product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang);
if (empty($this->_merchant_mails))/* Algunas veces no guarda en $this->_merchant_mails los correos, si es así, los recuperamos de la configuración del módulo*/ 
$mails = str_replace(',', self::__MA_MAIL_DELIMITOR__, strval(Configuration::get('MA_MERCHANT_MAILS'))); 
else 
$mails = $this->_merchant_mails;
$template_vars = array( 
'{id_customer}' => $id_customer, 
'{customer_firstname}' => $customer_firstname, 
'{customer_lastname}' => $customer_lastname, 
'{customer_email}' => $customer_email, 
'{product}' => $product_name,



); 
$from = $customer_email; 
$fromName = ($customer_firstname.' '.$customer_lastname); 
if (!empty($mails)){ 
$merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $mails); 
foreach ($merchant_mails as $merchant_mail) 
{ 
Mail::Send( 
$id_lang, 
'new_request_availability', 
sprintf(Mail::l('Solicitud de disponibilidad del producto: %s', $id_lang), $product_name), 
$template_vars, 
$merchant_mail, 
null, 
//strval(Configuration::get('PS_SHOP_EMAIL')), 
//strval(Configuration::get('PS_SHOP_NAME')), 
$from, 
$fromName, 
null, 
null, 
dirname(__FILE__).'/mails/', 
null, 
$id_shop 
); 
} 
} 
else{ 
Mail::Send( 
$id_lang, 
'new_request_availability', 
sprintf(Mail::l('Solicitud de disponibilidad del producto: %s', $id_lang), $product_name), 
$template_vars, 
strval(Configuration::get('PS_SHOP_EMAIL')), 
null, 
// strval(Configuration::get('PS_SHOP_EMAIL')), 
// strval(Configuration::get('PS_SHOP_NAME')), 
$from, 
$fromName, 
null, 
null, 
dirname(__FILE__).'/mails/', 
null, 
$id_shop 
); 
} 
}//nuevo

But I would like to know how I can put in this same mail a list with the attributes type like this

8 Baby Benito Pérez Galdós - Talla - Talla 2 
16 Baby Benito Pérez Galdós - Talla - Talla 3 
32 Baby Benito Pérez Galdós - Talla - Talla 4 
0 Baby Benito Pérez Galdós - Talla - Talla 5 
0 Baby Benito Pérez Galdós - Talla - Talla 6 
1 Baby Benito Pérez Galdós - Talla - Talla 7 
0 Baby Benito Pérez Galdós - Talla - Talla 8 
1 Baby Benito Pérez Galdós - Talla - Talla 9
 
 


looking for the best presta addons with outstanding support? check this: PrestaShop Modules

#2 vekia

vekia

    Advanced Member

  • Members
  • PipPipPip
  • 9794 posts

Posted 11 January 2018 - 10:42 AM

This requires redevelopment of function and email template file.
Firstly it is necessary to get all product combinations in an array, and do a foreach loop on this array. Something like i attached below. I do not tested the code, but it should work.

$message = '';
$product = new Product($id_product, true, $this->context->language->id);
foreach ($product->getAttributeCombinations($this->context->language->id) AS $product_combination) {
$message.= StockAvailable:getStockAvailableIdByProductId($id_product, $product_combination->id_product_attribute.' '.$product_name = Product::getProductName($id_product, $product_combination->id_product_attribute, $this->context->language->id).'<br/>';
}

and add a new email variable:

$template_vars = array('{new_message}'=>$message);

then you will be able to use {new_message} variable in email template and it will show attributes in the way you want.


free tutorials, free templates, free addons, prestashop modules MndfRK4.png  lpHMrZ5.png  gtKHYO7.png  google-48.png





IPB Skin By Virteq