Reputation: 339
I have created an override on AdminOrderController.php. I am using the variables {$followup} and {$code_traking} and placed in Shipped.html.
Unfortunately, I am baffled as to why it is only working for single order status change. When I tried to update as bulk, both {$followup} and {$code_traking} are not replaced in the email.
{$firstname}, {$lastname} and {$id_order} are generating in the emails as per norm.
Below are the codes.
} elseif (Tools::isSubmit('sendStateEmail') && Tools::getValue('sendStateEmail') > 0 && Tools::getValue('id_order') > 0) {
if ($this->tabAccess['edit'] === '1') {
$order_state = new OrderState((int)Tools::getValue('sendStateEmail'));
if (!Validate::isLoadedObject($order_state)) {
$this->errors[] = Tools::displayError('An error occurred while loading order status.');
} else {
$history = new OrderHistory((int)Tools::getValue('id_order_history'));
$carrier = new Carrier($order->id_carrier, $order->id_lang);
$templateVars = array();
$templateVars = array(
'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
'{url_traking}' => $carrier->url,
'{shipping_number}' => $order->shipping_number,
'{code_traking}' => $order->shipping_number
);
if ($history->sendEmail($order, $templateVars)) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=10&token='.$this->token);
} else {
$this->errors[] = Tools::displayError('An error occurred while sending the e-mail to the customer.');
}
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
}
I have tried adding the following codes below to the override but it is still not displaying. I have cleared cache.
public function processBulkUpdateOrderStatus()
{
if (Tools::isSubmit('submitUpdateOrderStatus')
&& ($id_order_state = (int)Tools::getValue('id_order_state'))) {
if ($this->tabAccess['edit'] !== '1') {
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
} else {
$order_state = new OrderState($id_order_state);
if (!Validate::isLoadedObject($order_state)) {
$this->errors[] = sprintf(Tools::displayError('Order status #%d cannot be loaded'), $id_order_state);
} else {
foreach (Tools::getValue('orderBox') as $id_order) {
$order = new Order((int)$id_order);
if (!Validate::isLoadedObject($order)) {
$this->errors[] = sprintf(Tools::displayError('Order #%d cannot be loaded'), $id_order);
} else {
$current_order_state = $order->getCurrentOrderState();
if ($current_order_state->id == $order_state->id) {
$this->errors[] = $this->displayWarning(sprintf('Order #%d has already been assigned this status.', $id_order));
} else {
$history = new OrderHistory();
$history->id_order = $order->id;
$history->id_employee = (int)$this->context->employee->id;
$use_existings_payment = !$order->hasInvoice();
$history->changeIdOrderState((int)$order_state->id, $order, $use_existings_payment);
$carrier = new Carrier($order->id_carrier, $order->id_lang);
$templateVars = array();
if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) {
//$templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));
$templateVars = array(
'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
'{url_traking}' => $carrier->url,
'{shipping_number}' => $order->shipping_number,
'{code_traking}' => $order->shipping_number
);
}
if ($history->addWithemail(true, $templateVars)) {
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
foreach ($order->getProducts() as $product) {
if (StockAvailable::dependsOnStock($product['product_id'])) {
StockAvailable::synchronize($product['product_id'], (int)$product['id_shop']);
}
}
}
} else {
$this->errors[] = sprintf(Tools::displayError('Cannot change status for order #%d.'), $id_order);
}
}
}
}
}
}
if (!count($this->errors)) {
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
}
}
}
public function renderList()
{
if (Tools::isSubmit('submitBulkupdateOrderStatus'.$this->table)) {
if (Tools::getIsset('cancel')) {
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
}
$this->tpl_list_vars['updateOrderStatus_mode'] = true;
$this->tpl_list_vars['order_statuses'] = $this->statuses_array;
$this->tpl_list_vars['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
$this->tpl_list_vars['POST'] = $_POST;
}
return parent::renderList();
}
Is there any other areas I need to edit to get this working for bulk order status change? I do not find it feasible from my end to update every single order, one by one as it is too time consuming. :(
Thank you.
Upvotes: 1
Views: 1251
Reputation: 339
Solved.
I thank @TheDrot for showing guiding me towards the solution. There is an importance to overriding AdminOrdersController.php. We need to include processBulkOrderStatus() and I have the following codes removed to make bulk status order change in proper with additional variables. Without removing the condition below, it will be futile.
//remove the condition below
if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') &&
$order->shipping_number) {
//leave the rest of the codes intact
}
Thank you.
Upvotes: 0
Reputation: 4337
You will have to override processBulkUpdateOrderStatus() method as well.
But if you used a module and a proper hook actionGetExtraMailTemplateVars you wouldn't have these problems and you wouldn't need overrides.
Module hook would be something like this:
public function hookActionGetExtraMailTemplateVars($params)
{
// Don't do anything if email template is not for shipped status
if ($params['template'] != 'shipped') {
return null;
}
// Read order ID from template vars that was set by OrderHistory class
$orderID = $params['template_vars']['{id_order}'];
$order = new Order((int)$orderID);
$carrier = new Carrier($order->id_carrier, $order->id_lang);
/*
Merge extra_template_vars because some other modules might already set
their custom email variables otherwise they would be lost if you just set
it with your own data
*/
$params['extra_template_vars'] = array_merge(
$params['extra_template_vars'],
array(
'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
'{url_traking}' => $carrier->url,
'{shipping_number}' => $order->shipping_number,
'{code_traking}' => $order->shipping_number
));
}
Upvotes: 1