Jump to content

[RESOLU] Modification module mail alert pour ajout image produit


Recommended Posts

Bonjour,

 

J'ai installé le module natif de prestashop mailalert sur la version 1.5.4.1 pour que le client puisse être notifié quand un produit hors stock devient en stock. Jusque la pas de problème.

J'ai ensuite voulu afficher, dans l'email qu'envoie le module, une image du produit. J'ai modifié la fonction sendCustomerAlert du module et mon image s'affiche.

Le problème est que quand j'ai plusieurs déclinaisons ce n'est pas la bonne image qui s'affiche.

 

Pour solutionner ce problème je me suis dis que je vais récupérer l'id_image dans la table ps_product_attribute_image et qu'avec ça je pourrais la comparer au résultat de getImageId de la classe product et ainsi choisir la bonne image.

Pour faire ça j'ai overridé la classe product et ajouté cette fonction

 

public function getImageId($id_product_attribute)
{
 $sql = 'SELECT pai.id_image
 FROM `'._DB_PREFIX_.'product_attribute_image` pai
 WHERE pai.`id_product_attribute` = '.(int)$id_product_attribute;

 return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}

 

ensuite j'appelle cette fonction pour récupérer les données

 

$image_id_attribute = $product->getImageId($id_product_attribute);

Bien sur $id_product_attribute contient la bonne valeur mais plus rien ne fonctionne quand j'ajoute l'appelle à cette fonction. Alors que quand je la commente je reçois bien mon email avec la mauvaise photo.

 

D'ou pourrait venir le problème? Il me semble que j'ai tout bien fait.

 

Si vous avez une meilleur idée que la solution que je propose je suis preneur.

 

Je reste à disposition pour un complément d'information.

 

Je met le code complet de la fonction ci-dessous

public static function sendCustomerAlert($id_product, $id_product_attribute)
{
 $link = new Link();
 $id_lang = (int)Context::getContext()->language->id;
 $product = new Product((int)$id_product, false, $id_lang);

 //Modif ajout image
 $images_info = $product->getImages((int)$id_lang);
 $image_id_attribute = $product->getImageId($id_product_attribute);
 foreach ($images_info as $k => $image)
 {
if($image_id_attribute['id_image'] == $image['id_image'])
{
 $id_image = $image['id_image'];
 break;
}

 }
 $images = $link->getImageLink($product->link_rewrite,$id_image,"home_01prem");

 $templateVars = array(
 '{product}' => (is_array($product->name) ? $product->name[$id_lang] : $product->name),
 '{product_link}' => $link->getProductLink($product),
 '{image}' => $images
);
 $customers = self::getCustomers($id_product, $id_product_attribute);
 foreach ($customers as $customer)
 {
  if ($customer['id_customer'])
  {
$customer = new Customer((int)$customer['id_customer']);
$customer_email = $customer->email;
$customer_id = (int)$customer->id;
  }
  else
  {
$customer_id = 0;
$customer_email = $customer['customer_email'];
  }
  $iso = Language::getIsoById($id_lang);
  if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.txt') &&
file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.html'))
Mail::Send((int)Configuration::get('PS_LANG_DEFAULT'), 'customer_qty', Mail::l('Product available', $id_lang), $templateVars, strval($customer_email), NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/');
  Hook::exec('actionModuleMailAlertSendCustomer', array('product' => (is_array($product->name) ? $product->name[$id_lang] : $product->name), 'link' => $link->getProductLink($product), 'image' => $images));
  self::deleteAlert((int)$customer_id, strval($customer_email), (int)$id_product, (int)$id_product_attribute);
 }
}

 

Merci.

 

Cordialement

Edited by Shonen07 (see edit history)
  • Like 1
Link to comment
Share on other sites

ça ne marche toujours pas mais j'ai fait une modification sur la requete qui semble être plus propre.

 

public function getImageId($id_product_attribute)
{
 $sql = 'SELECT pai.id_image
	 FROM `'._DB_PREFIX_.'product_attribute_image` pai
	 WHERE pai.`id_product_attribute` = '.(int)$id_product_attribute;
 return Db::getInstance()->getRow($sql);
}

Link to comment
Share on other sites

En fait mon code marche nickel, pour ceux qui veulent ajouter l'image du produit à l'email vous pouvez le reprendre.

La seule manip à faire est de supprimer le fichier /cache/class_index.php qui ne prenait pas en compte la création de mon override.

Link to comment
Share on other sites

  • 2 months 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...