Question

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?

Was it helpful?

Solution

Looking at Your code I can see everything is fine, almost. The really important thing that is missing here is the place where You call Your orderInfo controller to store the information. Because I am sure You are calling this after the order is saved - but I mean You are calling this after this call:

$this->model_checkout_order->confirm();

Am I right?

Because the confirm method, as You may noticed, is the one sending the emails and if the orderInfo data is not yet stored, there is nothing to be inserted into the mail template...

Just a small hint how the checkout process is going on regarding the order lifecycle:

  • on Confirm tab of checkout the order is saved to the DB (inactive, without status, could not be even seen in the administration)
  • after confirming either the payment process takes it's place or (and after the payment process) the order is confirmed with the respective status - and here the email is sent

So Your bet is to save all the orderInfo either within addOrder method, or within confirm method before the email is sent.

And one more hint even: The first option is Your ticket as with the second one You may lose the information to be saved in the case some payment gateway was used (with redirects to payment gateway and back). So store the orderInfo data right within the addOrder() method and You are sure when the order is confirmed, the data is there and the email will contain them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top