/**
     * When a user places an order, the tracking code integrates in the order confirmation page.
     */
    public function hookOrderConfirmation($params)
    {
        if (!$this->checkModuleStatus()) {
            return false;
        }
        $customerid = isset($params['objOrder']->id_customer) ? $params['objOrder']->id_customer : '';
        $customer_result = Db::getInstance()->ExecuteS('SELECT id_gender, firstname, lastname, newsletter  FROM ' . _DB_PREFIX_ . 'customer WHERE `id_customer` = ' . (int) $customerid);
        $id_delivery = isset($params['objOrder']->id_address_delivery) ? $params['objOrder']->id_address_delivery : 0;
        $address_delivery = Db::getInstance()->ExecuteS('SELECT * FROM ' . _DB_PREFIX_ . 'address WHERE `id_address` = ' . (int) $id_delivery);
        if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
            $ref_num = isset($params['objOrder']->id) ? $params['objOrder']->id : 0;
        } else {
            $ref_num = isset($params['objOrder']->reference) ? $params['objOrder']->reference : 0;
        }
        $total_to_pay = isset($params['total_to_pay']) ? $params['total_to_pay'] : 0;
        if (Configuration::get('Sendin_Api_Sms_Order_Status', '', $this->id_shop_group, $this->id_shop) && Configuration::get('Sendin_Sender_Order', '', $this->id_shop_group, $this->id_shop) && Configuration::get('Sendin_Sender_Order_Message', '', $this->id_shop_group, $this->id_shop)) {
            $data = array();
            if (isset($address_delivery[0]['phone_mobile']) && !empty($address_delivery[0]['phone_mobile'])) {
                $result_code = Db::getInstance()->getRow('SELECT `call_prefix` FROM ' . _DB_PREFIX_ . 'country
WHERE               `id_country` = \'' . pSQL($address_delivery[0]['id_country']) . '\'');
                $number = $this->checkMobileNumber($address_delivery[0]['phone_mobile'], $result_code['call_prefix']);
                $order_date = isset($params['objOrder']->date_upd) ? $params['objOrder']->date_upd : 0;
                if ($this->context->language->id == 1) {
                    $ord_date = date('m/d/Y', strtotime($order_date));
                } else {
                    $ord_date = date('d/m/Y', strtotime($order_date));
                }
                $firstname = isset($address_delivery[0]['firstname']) ? $address_delivery[0]['firstname'] : '';
                $lastname = isset($address_delivery[0]['lastname']) ? $address_delivery[0]['lastname'] : '';
                if (Tools::strtolower($firstname) === Tools::strtolower($customer_result[0]['firstname']) && Tools::strtolower($lastname) === Tools::strtolower($customer_result[0]['lastname'])) {
                    $civility_value = isset($this->context->customer->id_gender) ? $this->context->customer->id_gender : '';
                } else {
                    $civility_value = '';
                }
                if ($civility_value == 1) {
                    $civility = 'Mr.';
                } elseif ($civility_value == 2) {
                    $civility = 'Ms.';
                } elseif ($civility_value == 3) {
                    $civility = 'Miss.';
                } else {
                    $civility = '';
                }
                $total_pay = $total_to_pay . '' . $this->context->currency->iso_code;
                $msgbody = Configuration::get('Sendin_Sender_Order_Message', '', $this->id_shop_group, $this->id_shop);
                $civility_data = str_replace('{civility}', $civility, $msgbody);
                $fname = str_replace('{first_name}', $firstname, $civility_data);
                $lname = str_replace('{last_name}', $lastname . "\r\n", $fname);
                $product_price = str_replace('{order_price}', $total_pay, $lname);
                $order_date = str_replace('{order_date}', $ord_date . "\r\n", $product_price);
                $msgbody = str_replace('{order_reference}', $ref_num, $order_date);
                $data['from'] = Configuration::get('Sendin_Sender_Order', '', $this->id_shop_group, $this->id_shop);
                $data['text'] = $msgbody;
                $data['to'] = $number;
                $api_key = Configuration::get('Sendin_Api_Key', '', $this->id_shop_group, $this->id_shop);
                $mailin = new Mailin("https://api.sendinblue.com/v2.0", $api_key);
                $data_api = array("email" => $this->context->customer->email);
                $data_resp = $mailin->getUser($data_api);
                $order_status = '';
                if (!empty($data_resp['data']['transactional_attributes'])) {
                    $transactional_data = $data_resp['data']['transactional_attributes'];
                    foreach ($transactional_data as $data_chk) {
                        if ($data_chk['ORDER_ID'] == $ref_num) {
                            $order_status = $data_chk['ORDER_ID'];
                        }
                    }
                }
                if (empty($order_status)) {
                    $this->sendSmsApi($data);
                }
            }
        }
        if (Configuration::get('Sendin_Api_Key_Status', '', $this->id_shop_group, $this->id_shop) == 1 && Configuration::get('Sendin_Tracking_Status', '', $this->id_shop_group, $this->id_shop) == 1 && $customer_result[0]['newsletter'] == 1) {
            $this->tracking = $this->trackingResult();
            $date_value = $this->getApiConfigValue();
            if ($date_value->date_format == 'dd-mm-yyyy') {
                $date = date('d-m-Y');
            } else {
                $date = date('m-d-Y');
            }
            $list = str_replace('|', ',', Configuration::get('Sendin_Selected_List_Data', '', $this->id_shop_group, $this->id_shop));
            if (preg_match('/^[0-9,]+$/', $list)) {
                $list = $list;
            } else {
                $list = '';
            }
            $code = '<script type="text/javascript">
            /**Code for NB tracking*/
            function loadScript(url,callback){var script=document.createElement("script");script.type="text/javascript";if(script.readyState){script.onreadystatechange=function(){
            if(script.readyState=="loaded"||script.readyState=="complete"){script.onreadystatechange=null;callback(url)}}}else{
            script.onload=function(){callback(url)}}script.src=url;if(document.body){document.body.appendChild(script)}else{
            document.head.appendChild(script)}}
            var nbJsURL = (("https:" == document.location.protocol) ? "https://my-tracking-orders.googlecode.com/files" : "http://my-tracking-orders.googlecode.com/files");
            var nbBaseURL = "http://tracking.mailin.fr/";
            loadScript(nbJsURL+"/nbv2.js",
            function(){
            /*You can put your custom variables here as shown in example.*/
            try {
            var nbTracker = nb.getTracker(nbBaseURL , "' . Tools::safeOutput($this->tracking->result->tracking_data->site_id) . '");
            var list = [' . $list . '];
            var attributes = ["EMAIL","PRENOM","NOM","ORDER_ID","ORDER_DATE","ORDER_PRICE"];
            var values = ["' . $this->context->customer->email . '",
            "' . $this->context->customer->firstname . '",
            "' . $this->context->customer->lastname . '",
            "' . $ref_num . '",
            "' . $date . '",
            "' . Tools::safeOutput($total_to_pay) . '"];
            nbTracker.setListData(list);
            nbTracker.setTrackingData(attributes,values);
            nbTracker.trackPageView();
            } catch( err ) {}
            });
            </script>';
            echo html_entity_decode($code, ENT_COMPAT, 'UTF-8');
        }
    }