我正在使用 OC 版本 1.5.5.1
问题是我想通过 VQMod 在订单确认电子邮件中添加一些额外信息。我有这个脚本(整个 VQMod 文件的一部分):
<file name="/catalog/view/theme/kadobos/template/checkout/checkout.tpl">
<operation>
<search position="after">
<![CDATA[<script type="text/javascript"><!--]]>
</search>
<add>
<![CDATA[
// ORDER INFO CODE!!!
$('#button-confirm').live('click', function() {
waardes = [];
$('input[class=order_info_radio]:checked').each(function(index) {
waardes[$(this).attr("name").replace("order_info_answer_", "")] = $(this).attr("value");
});
$('input[class=order_info_input]').each(function(index) {
waardes[$(this).attr("name").replace("order_info_answer_", "")] = $(this).attr("value");
});
$('textarea[class=order_info_textarea]').each(function(index) {
waardes[$(this).attr("name").replace("order_info_answer_", "")] = $(this).attr("value");
});
$.ajax({
type: "POST",
data: {waardes:waardes},
url: "index.php?route=module/order_info",
success: function(msg){
// console.log(msg);
}
});
});
// END OF ORDER INFO CODE!!!
]]>
</add>
</operation>
</file>
<!-- Factuur die wordt verstuurd -->
<file name="/catalog/model/checkout/order.php">
<operation>
<search position="before">
<![CDATA[if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/order.tpl')) {]]>
</search>
<add>
<![CDATA[
// ORDER INFO CODE!!!
$this -> load -> model('module/order_info');
global $log;
$template -> data['order_info_waardes'] = $this -> model_module_order_info -> getAnswers($order_id);
$log->write(print_r($template -> data['order_info_waardes'], true));
$log->write("Order ID: " . $order_id);
// END OF ORDER INFO CODE!!!
]]>
</add>
</operation>
</file>
<file name="/catalog/view/theme/kadobos/template/mail/order.tpl">
<operation>
<search position="replace">
<![CDATA[<span id="order_info_holder"></span>]]>
</search>
<add>
<![CDATA[
<!-- ORDER INFO CODE!!! -->
<div id="tab-extra-info" >
<table class="form">
<tbody>
<?php
foreach($order_info_waardes as $order_info_waardes_key => $order_info_waardes_value){ ?>
<tr>
<td><?php echo $order_info_waardes_value['title']; ?></td>
<td><?php echo $order_info_waardes_value['value']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- END OF ORDER INFO CODE!!! -->
]]>
</add>
</operation>
</file>
和控制器文件(module/order_info
):
<?php
class ControllerModuleOrderInfo extends Controller {
public function index() {
global $log;
$this -> load -> model("module/order_info");
$order_num = $this -> session -> data['order_id'];
$log->write("Order ID ( tijdens opslaan ): " . $order_num);
foreach ($this -> request -> post['waardes'] as $key => $value) {
if ($value == "undefined") {
continue;
}
$info = $this -> model_module_order_info -> getInfo($key);
$this -> model_module_order_info -> insertAnswer($order_num, $info['title'], $value);
}
}
}
和模型文件(module/order_info
)(部分):
<?php
class Modelmoduleorderinfo extends Model {
public function getAnswers($uid) {
$query = "SELECT " . DB_PREFIX . "order_info_entrys.uid, " . DB_PREFIX . "order_info_entrys.title, " . DB_PREFIX . "order_info_entrys.`value` FROM `" . DB_PREFIX . "order_info_entrys` WHERE " . DB_PREFIX . "order_info_entrys.order_id = " . $uid;
$resultSet = $this -> db -> query($query);
return $resultSet -> rows;
}
}
但我没有从模型中得到任何数据(上面的代码)。如果我查看数据库,则数据中包含正确的信息。
所以我尝试将我得到的所有信息记录到错误日志中,这就是我得到的:
2013-12-06 9:27:54 - Array
(
)
2013-12-06 9:27:54 - Order ID: 36186
2013-12-06 9:27:54 - Array
(
)
2013-12-06 9:27:54 - Order ID: 36186
2013-12-06 9:27:54 - Order ID ( tijdens opslaan ): 36186
如您所见,首先是确认电子邮件发送,然后是存储在数据库中的信息。但是需要首先存储数据,我认为这已经发生了(因为 ajax 请求)。但我认为 ajax 请求会变慢,并且服务器会继续解析所有信息并发送电子邮件。
那么你们知道我如何在成功确认(存储数据)之前保存所有内容,还是你们知道另一种方式?