Php Prestashop 1.6.1.14-已发送电子邮件集中未替换的变量
我已经在AdminOrderController.php上创建了一个覆盖。我正在使用变量{$followup}和{$code_traking},并将它们放在Shipped.html中 不幸的是,我不明白为什么它只适用于单订单状态更改。当我尝试批量更新时,{$followup}和{$code_traking}在电子邮件中都没有被替换 {$firstname}、{$lastname}和{$id_order}按照规范在电子邮件中生成 下面是代码Php Prestashop 1.6.1.14-已发送电子邮件集中未替换的变量,php,prestashop,prestashop-1.6,Php,Prestashop,Prestashop 1.6,我已经在AdminOrderController.php上创建了一个覆盖。我正在使用变量{$followup}和{$code_traking},并将它们放在Shipped.html中 不幸的是,我不明白为什么它只适用于单订单状态更改。当我尝试批量更新时,{$followup}和{$code_traking}在电子邮件中都没有被替换 {$firstname}、{$lastname}和{$id_order}按照规范在电子邮件中生成 下面是代码 } elseif (Tools::isS
} 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.');
}
我已尝试将以下代码添加到覆盖中,但它仍不显示。我已经清除了缓存
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();
}
我是否需要编辑任何其他区域以使其适用于批量订单状态更改?我认为从我的角度来看,逐个更新每个订单是不可行的,因为这太耗时了(
谢谢。您还必须重写该方法
但是如果您使用了一个模块和一个合适的钩子,您就不会有这些问题,也不需要重写
模块挂钩应该是这样的:
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
));
}
解决了
我感谢@Drlot为我提供了解决方案的指导。重写AdminOrdersController.php非常重要。我们需要包括processBulkOrderStatus(),我删除了以下代码,以便使用其他变量正确更改批量状态订单。如果不删除以下条件,这将是徒劳的
//remove the condition below
if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') &&
$order->shipping_number) {
//leave the rest of the codes intact
}
谢谢。请同时发布电子邮件模板。在添加覆盖后,您是否删除了cache/class_index.php文件,或者覆盖是在模块安装中安装的?我已清除class_index.php,但批量订单状态更改时仍然没有显示变量。我已尝试覆盖,但仍然没有显示2个变量但是我可以检查一下吗,即使我没有重写,默认值也会显示{followup}值,因为它是在processBulkUpdateOrderStatus()中分配的,对吗?(第411行)@muhammaddfakhrinbinomar是的,该值会显示。您被重写的方法是否正在执行?Try to die()在它内部的某个地方查看它是否工作。否则您可能需要删除
cache/class_index.php