Working with no problem, status is changed automaticly to canceled.
Edit History
17 hours ago, Knowband Plugins said:You can add the below code in "controllers\admin\AdminReturnController.php" , postProcess(), above"if (Tools::isSubmit('submitAddorder_returnAndStay')) {"
Code need to added :
$kb_order_obj = new Order($orderReturn->id_order);
$history = new OrderHistory();$history->id_order = $kb_order_obj->id;
$history->id_employee = (int) $this->context->employee->id;
$use_existings_payment = false;
if (!$kb_order_obj->hasInvoice()) {
$use_existings_payment = true;
}
$history->changeIdOrderState((int) Configuration::get('PS_OS_CANCELED'), $kb_order_obj, $use_existings_payment); //code to update the order status to "Cancelled" Note that the whole order is treated as cancelled
$carrier = new Carrier($kb_order_obj->id_carrier, $kb_order_obj->id_lang);
$templateVars = array();
if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $kb_order_obj->shipping_number
) {
$templateVars = array(
'{followup}' => str_replace('@', $kb_order_obj->shipping_number, $carrier->url)
);
}// Save all changes
if ($history->addWithemail(true, $templateVars)) { //Code to send the respective mails for cancelled order to customer
// synchronizes quantities if needed..
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
foreach ($kb_order_obj->getProducts() as $product) {
if (StockAvailable::dependsOnStock($product['product_id'])) {
StockAvailable::synchronize(
$product['product_id'],
(int) $product['id_shop']
);
}
}
}
}
Seems not to work. Where exacly You want me to put the code?
public function postProcess()
{
$this->context = Context::getContext();
if (Tools::isSubmit('deleteorder_return_detail')) {
if ($this->access('delete')) {
if (($id_order_detail = (int) (Tools::getValue('id_order_detail'))) && Validate::isUnsignedId($id_order_detail)) {
if (($id_order_return = (int) (Tools::getValue('id_order_return'))) && Validate::isUnsignedId($id_order_return)) {
$orderReturn = new OrderReturn($id_order_return);
if (!Validate::isLoadedObject($orderReturn)) {
die(Tools::displayError());
}
if ((int) ($orderReturn->countProduct()) > 1) {
if (OrderReturn::deleteOrderReturnDetail($id_order_return, $id_order_detail, (int) (Tools::getValue('id_customization', 0)))) {
Tools::redirectAdmin(self::$currentIndex . '&conf=4token=' . $this->token);
} else {
$this->errors[] = $this->trans('An error occurred while deleting the details of your order return.', [], 'Admin.Orderscustomers.Notification');
}
} else {
$this->errors[] = $this->trans('You need at least one product.', [], 'Admin.Orderscustomers.Notification');
}
} else {
$this->errors[] = $this->trans('The order return is invalid.', [], 'Admin.Orderscustomers.Notification');
}
} else {
$this->errors[] = $this->trans('The order return content is invalid.', [], 'Admin.Orderscustomers.Notification');
}
} else {
$this->errors[] = $this->trans('You do not have permission to delete this.', [], 'Admin.Notifications.Error');
}
} elseif (Tools::isSubmit('submitAddorder_return') || Tools::isSubmit('submitAddorder_returnAndStay')) {
if ($this->access('edit')) {
if (($id_order_return = (int) (Tools::getValue('id_order_return'))) && Validate::isUnsignedId($id_order_return)) {
$orderReturn = new OrderReturn($id_order_return);
$order = new Order($orderReturn->id_order);
$customer = new Customer($orderReturn->id_customer);
$orderLanguage = new Language((int) $order->id_lang);
$orderReturn->state = (int) (Tools::getValue('state'));
if ($orderReturn->save()) {
$orderReturnState = new OrderReturnState($orderReturn->state);
$vars = [
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{id_order_return}' => $id_order_return,
'{state_order_return}' => (isset($orderReturnState->name[(int) $order->id_lang]) ? $orderReturnState->name[(int) $order->id_lang] : $orderReturnState->name[(int) Configuration::get('PS_LANG_DEFAULT')]),
];
Mail::Send(
(int) $order->id_lang,
'order_return_state',
$this->trans(
'Your order return status has changed',
[],
'Emails.Subject',
$orderLanguage->locale
),
$vars,
$customer->email,
$customer->firstname . ' ' . $customer->lastname,
null,
null,
null,
null,
_PS_MAIL_DIR_,
true,
(int) $order->id_shop
);
if (Tools::isSubmit('submitAddorder_returnAndStay')) {
Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token . '&updateorder_return&id_order_return=' . (int) $id_order_return);
} else {
Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token);
}
}
} else {
$this->errors[] = $this->trans('No order return ID has been specified.', [], 'Admin.Orderscustomers.Notification');
}
} else {
$this->errors[] = $this->trans('You do not have permission to edit this.', [], 'Admin.Notifications.Error');
}
}
parent::postProcess();
}
}
public function postProcess() { $this->context = Context::getContext(); if (Tools::isSubmit('deleteorder_return_detail')) { if ($this->access('delete')) { if (($id_order_detail = (int) (Tools::getValue('id_order_detail'))) && Validate::isUnsignedId($id_order_detail)) { if (($id_order_return = (int) (Tools::getValue('id_order_return'))) && Validate::isUnsignedId($id_order_return)) { $orderReturn = new OrderReturn($id_order_return); if (!Validate::isLoadedObject($orderReturn)) { die(Tools::displayError()); } if ((int) ($orderReturn->countProduct()) > 1) { if (OrderReturn::deleteOrderReturnDetail($id_order_return, $id_order_detail, (int) (Tools::getValue('id_customization', 0)))) { Tools::redirectAdmin(self::$currentIndex . '&conf=4token=' . $this->token); } else { $this->errors[] = $this->trans('An error occurred while deleting the details of your order return.', [], 'Admin.Orderscustomers.Notification'); } } else { $this->errors[] = $this->trans('You need at least one product.', [], 'Admin.Orderscustomers.Notification'); } } else { $this->errors[] = $this->trans('The order return is invalid.', [], 'Admin.Orderscustomers.Notification'); } } else { $this->errors[] = $this->trans('The order return content is invalid.', [], 'Admin.Orderscustomers.Notification'); } } else { $this->errors[] = $this->trans('You do not have permission to delete this.', [], 'Admin.Notifications.Error'); } } elseif (Tools::isSubmit('submitAddorder_return') || Tools::isSubmit('submitAddorder_returnAndStay')) { if ($this->access('edit')) { if (($id_order_return = (int) (Tools::getValue('id_order_return'))) && Validate::isUnsignedId($id_order_return)) { $orderReturn = new OrderReturn($id_order_return); $order = new Order($orderReturn->id_order); $customer = new Customer($orderReturn->id_customer); $orderLanguage = new Language((int) $order->id_lang); $orderReturn->state = (int) (Tools::getValue('state')); if ($orderReturn->save()) { $orderReturnState = new OrderReturnState($orderReturn->state); $vars = [ '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order_return}' => $id_order_return, '{state_order_return}' => (isset($orderReturnState->name[(int) $order->id_lang]) ? $orderReturnState->name[(int) $order->id_lang] : $orderReturnState->name[(int) Configuration::get('PS_LANG_DEFAULT')]), ]; Mail::Send( (int) $order->id_lang, 'order_return_state', $this->trans( 'Your order return status has changed', [], 'Emails.Subject', $orderLanguage->locale ), $vars, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop ); if (Tools::isSubmit('submitAddorder_returnAndStay')) { Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token . '&updateorder_return&id_order_return=' . (int) $id_order_return); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token); } } } else { $this->errors[] = $this->trans('No order return ID has been specified.', [], 'Admin.Orderscustomers.Notification'); } } else { $this->errors[] = $this->trans('You do not have permission to edit this.', [], 'Admin.Notifications.Error'); } } parent::postProcess(); } }