diff --git a/mailalerts.php b/mailalerts.php
index c0b86e2..1f5fe6c 100644
--- a/mailalerts.php
+++ b/mailalerts.php
@@ -242,42 +242,15 @@ public function getAllMessages($id)
return implode('
', $result);
}
- public function hookActionValidateOrder($params)
+ protected function formatProductTableRows(Order $order, Cart $cart, Customer $customer, Currency $currency, Context $context = null)
{
- if (!$this->merchant_order || empty($this->merchant_mails))
- return;
-
- // Getting differents vars
- $context = Context::getContext();
- $id_lang = (int)$context->language->id;
- $id_shop = (int)$context->shop->id;
- $currency = $params['currency'];
- $order = $params['order'];
- $customer = $params['customer'];
- $configuration = Configuration::getMultiple(
- array(
- 'PS_SHOP_EMAIL',
- 'PS_MAIL_METHOD',
- 'PS_MAIL_SERVER',
- 'PS_MAIL_USER',
- 'PS_MAIL_PASSWD',
- 'PS_SHOP_NAME',
- 'PS_MAIL_COLOR'
- ), $id_lang, null, $id_shop
- );
- $delivery = new Address((int)$order->id_address_delivery);
- $invoice = new Address((int)$order->id_address_invoice);
- $order_date_text = Tools::displayDate($order->date_add);
- $carrier = new Carrier((int)$order->id_carrier);
- $message = $this->getAllMessages($order->id);
-
- if (!$message || empty($message))
- $message = $this->l('No message');
+ if ($context === null)
+ $context = Context::getContext();
$items_table = '';
- $products = $params['order']->getProducts();
- $customized_datas = Product::getAllCustomizedDatas((int)$params['cart']->id);
+ $products = $order->getProducts();
+ $customized_datas = Product::getAllCustomizedDatas((int)$cart->id);
Product::addCustomizationPrice($products, $customized_datas);
foreach ($products as $key => $product)
{
@@ -309,9 +282,9 @@ public function hookActionValidateOrder($params)
'.$product['product_reference'].' |
'.$product['product_name'].''
- .(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '')
- .(!empty($customization_text) ? ' '.$customization_text : '')
- .'
+ .(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '')
+ .(!empty($customization_text) ? ' '.$customization_text : '')
+ .'
|
'.Tools::displayPrice($unit_price, $currency, false).' |
'.(int)$product['product_quantity'].' |
@@ -320,14 +293,53 @@ public function hookActionValidateOrder($params)
.'
';
}
- foreach ($params['order']->getCartRules() as $discount)
+ foreach ($order->getCartRules() as $discount)
{
$items_table .=
'
- | '.$this->l('Voucher code:').' '.$discount['name'].' |
+ '.$this->l('Voucher code:').' '.$discount['name'].' |
-'.Tools::displayPrice($discount['value'], $currency, false).' |
-
';
+ ';
}
+
+ return $items_table;
+ }
+
+ public function hookActionValidateOrder($params)
+ {
+ if (!$this->merchant_order || empty($this->merchant_mails))
+ return;
+
+ // Getting differents vars
+ $context = Context::getContext();
+ $id_lang = (int)$context->language->id;
+ $id_shop = (int)$context->shop->id;
+ $currency = $params['currency'];
+ $order = $params['order'];
+ $customer = $params['customer'];
+ $cart = $params['cart'];
+ $configuration = Configuration::getMultiple(
+ array(
+ 'PS_SHOP_EMAIL',
+ 'PS_MAIL_METHOD',
+ 'PS_MAIL_SERVER',
+ 'PS_MAIL_USER',
+ 'PS_MAIL_PASSWD',
+ 'PS_SHOP_NAME',
+ 'PS_MAIL_COLOR'
+ ), $id_lang, null, $id_shop
+ );
+ $delivery = new Address((int)$order->id_address_delivery);
+ $invoice = new Address((int)$order->id_address_invoice);
+ $order_date_text = Tools::displayDate($order->date_add);
+ $carrier = new Carrier((int)$order->id_carrier);
+ $message = $this->getAllMessages($order->id);
+
+ if (!$message || empty($message))
+ $message = $this->l('No message');
+
+ $items_table = $this->formatProductTableRows($order, $cart, $customer, $currency, $context);
+
if ($delivery->id_state)
$delivery_state = new State((int)$delivery->id_state);
if ($invoice->id_state)