I'm using OC version 1.5.5.1
The thing is that i want to add some extra information to the confirmation email of an order through VQMod. I've got this script ( part of the whole VQMod file ):
<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>
And the controller 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);
}
}
}
And the model file (module/order_info
) (part):
<?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;
}
}
But i don't get any data from the model ( above code ). If i look in the DB, the data is there with the right information.
So i've tryed logging all the information i've got to the error log and this is what i got:
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
As you can see, is first the conformation email send, and later the info stored in the database. But the data needs to be stored first, and i thought that that happends already ( because of the ajax request ). But i think that the ajax request is to slow and that the server contineus with parsing all the information and sending the email.
So do you guys know how i can hold everything until the succes conformation ( that the data is stored ) or do you guys know an another way?