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

[*] CORE: Refactor table rows formatting code into new method #16

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
88 changes: 50 additions & 38 deletions mailalerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,42 +242,15 @@ public function getAllMessages($id)
return implode('<br/>', $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)
{
Expand Down Expand Up @@ -309,9 +282,9 @@ public function hookActionValidateOrder($params)
<td style="padding:0.6em 0.4em;">'.$product['product_reference'].'</td>
<td style="padding:0.6em 0.4em;">
<strong><a href="'.$url.'">'.$product['product_name'].'</a>'
.(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '')
.(!empty($customization_text) ? '<br />'.$customization_text : '')
.'</strong>
.(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '')
.(!empty($customization_text) ? '<br />'.$customization_text : '')
.'</strong>
</td>
<td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td>
<td style="padding:0.6em 0.4em; text-align:center;">'.(int)$product['product_quantity'].'</td>
Expand All @@ -320,14 +293,53 @@ public function hookActionValidateOrder($params)
.'</td>
</tr>';
}
foreach ($params['order']->getCartRules() as $discount)
foreach ($order->getCartRules() as $discount)
{
$items_table .=
'<tr style="background-color:#EBECEE;">
<td colspan="4" style="padding:0.6em 0.4em; text-align:right;">'.$this->l('Voucher code:').' '.$discount['name'].'</td>
<td colspan="4" style="padding:0.6em 0.4em; text-align:right;">'.$this->l('Voucher code:').' '.$discount['name'].'</td>
<td style="padding:0.6em 0.4em; text-align:right;">-'.Tools::displayPrice($discount['value'], $currency, false).'</td>
</tr>';
</tr>';
}

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)
Expand Down