public function init()
 {
     if (!$this->isOpcModuleActive()) {
         return parent::init();
     }
     if (Tools::getIsset('id_carrier') && strpos(Tools::getValue('id_carrier'), ",") > 0) {
         $_POST['id_carrier'] = Cart::intifier(Tools::getValue('id_carrier'));
     }
     $this->opc_templates_path = _PS_MODULE_DIR_ . 'onepagecheckout/views/templates/front';
     $this->origInit();
     $this->_assignOpcSettings();
     if ($this->opc_config != null && $this->opc_config['goods_return_cms'] > 0) {
         $cms = new CMS((int) $this->opc_config['goods_return_cms'], (int) $this->context->language->id);
         $link_goods_return = $this->context->link->getCMSLink($cms, $cms->link_rewrite, true);
         if (!strpos($link_goods_return, '?')) {
             $link_goods_return .= '?content_only=1';
         } else {
             $link_goods_return .= '&content_only=1';
         }
         $this->context->smarty->assign("link_goods_return", $link_goods_return);
     }
     $this->_setInfoBlockContent();
     $this->_setExtraDivPaymentBlock();
     if ($this->nbProducts) {
         $this->context->smarty->assign('virtual_cart', false);
     }
     $this->context->smarty->assign('is_multi_address_delivery', $this->context->cart->isMultiAddressDelivery() || (int) Tools::getValue('multi-shipping') == 1);
     $this->context->smarty->assign('open_multishipping_fancybox', (int) Tools::getValue('multi-shipping') == 1);
     $this->context->smarty->assign('order_process_type', Configuration::get('PS_ORDER_PROCESS_TYPE'));
     $this->context->smarty->assign('one_phone_at_least', (int) Configuration::get('PS_ONE_PHONE_AT_LEAST'));
     $this->inv_first_on = isset($this->opc_config) && isset($this->opc_config["invoice_first"]) && $this->opc_config["invoice_first"] == "1";
     $this->default_ps_carriers = isset($this->opc_config) && isset($this->opc_config["default_ps_carriers"]) && $this->opc_config["default_ps_carriers"] == "1";
     if (version_compare(_PS_VERSION_, "1.5.2.0") <= 0) {
         $this->isLogged = (bool) ($this->context->customer->id && Customer::customerIdExistsStatic((int) $this->context->cookie->id_customer));
     }
     if ($this->context->cart->nbProducts()) {
         if (Tools::isSubmit('ajax')) {
             if (Tools::isSubmit('method')) {
                 switch (Tools::getValue('method')) {
                     case 'updateMessage':
                         if (Tools::isSubmit('message')) {
                             $txtMessage = urldecode(Tools::getValue('message'));
                             $this->_updateMessage($txtMessage);
                             if (count($this->errors)) {
                                 die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
                             }
                             die(true);
                         }
                         break;
                     case 'updateCarrierAndGetPayments':
                         if ((Tools::isSubmit('delivery_option') || Tools::isSubmit('id_carrier')) && Tools::isSubmit('recyclable') && Tools::isSubmit('gift') && Tools::isSubmit('gift_message')) {
                             $this->_assignWrappingAndTOS();
                             CartRule::autoRemoveFromCart($this->context);
                             CartRule::autoAddToCart($this->context);
                             if ($this->_processCarrier()) {
                                 $carriers = $this->context->cart->simulateCarriersOutput();
                                 $return = array_merge(array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'carrier_data' => $this->_getCarrierList(), 'HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array('carriers' => $carriers))), $this->getFormatedSummaryDetail());
                                 Cart::addExtraCarriers($return);
                                 die(Tools::jsonEncode($return));
                             } else {
                                 $this->errors[] = Tools::displayError('Error occurred while updating cart.');
                             }
                             if (count($this->errors)) {
                                 die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
                             }
                             exit;
                         }
                         break;
                     case 'updateTOSStatusAndGetPayments':
                         if (Tools::isSubmit('checked')) {
                             $this->context->cookie->checkedTOS = (int) Tools::getValue('checked');
                             die(Tools::jsonEncode(array()));
                         }
                         break;
                     case 'updatePaymentsOnly':
                         die(Tools::jsonEncode(array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => self::_getPaymentMethods())));
                         break;
                     case 'getCarrierList':
                         $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart());
                         $result = $this->_getCarrierList();
                         $result = array_merge($result, array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods()), $this->getFormatedSummaryDetail());
                         die(Tools::jsonEncode($result));
                         break;
                     case 'editCustomer':
                         if (!$this->isLogged) {
                             exit;
                         }
                         if (Tools::getValue('years')) {
                             $this->context->customer->birthday = (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
                         }
                         if (trim(Tools::getValue('customer_lastname')) == "") {
                             $_POST['customer_lastname'] = $this->inv_first_on ? Tools::getValue('lastname_invoice') : Tools::getValue('lastname');
                         }
                         if (trim(Tools::getValue('customer_firstname')) == "") {
                             $_POST['customer_firstname'] = $this->inv_first_on ? Tools::getValue('firstname_invoice') : Tools::getValue('firstname');
                         }
                         $this->errors = $this->context->customer->validateController();
                         $this->context->customer->newsletter = (int) Tools::isSubmit('newsletter');
                         $this->context->customer->optin = (int) Tools::isSubmit('optin');
                         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_customer' => (int) $this->context->customer->id, 'token' => Tools::getToken(false));
                         if (!count($this->errors)) {
                             $return['isSaved'] = (bool) $this->context->customer->update();
                         } else {
                             $return['isSaved'] = false;
                         }
                         die(Tools::jsonEncode($return));
                         break;
                     case 'getAddressBlockAndCarriersAndPayments':
                         if ($this->context->customer->isLogged()) {
                             if (!Customer::getAddressesTotalById($this->context->customer->id)) {
                                 die(Tools::jsonEncode(array('no_address' => 1)));
                             }
                             if (file_exists(_PS_MODULE_DIR_ . 'blockuserinfo/blockuserinfo.php')) {
                                 include_once _PS_MODULE_DIR_ . 'blockuserinfo/blockuserinfo.php';
                                 $blockUserInfo = new BlockUserInfo();
                             }
                             $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart());
                             $customer = $this->context->customer;
                             $customer_info = array("id" => $customer->id, "email" => $customer->email, "id_gender" => $customer->id_gender, "birthday" => $customer->birthday, "newsletter" => $customer->newsletter, "optin" => $customer->optin, "is_guest" => $customer->is_guest);
                             $this->_processAddressFormat();
                             $this->_assignAddress();
                             $address_delivery = $this->context->smarty->tpl_vars['delivery']->value;
                             $address_invoice = $this->context->smarty->tpl_vars['invoice']->value;
                             if (Configuration::get('VATNUMBER_MANAGEMENT') && file_exists(_PS_MODULE_DIR_ . '/vatnumber/vatnumber.php') && !class_exists("VatNumber", false)) {
                                 include_once _PS_MODULE_DIR_ . '/vatnumber/vatnumber.php';
                             }
                             if (isset($address_delivery) && Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(dirname(__FILE__) . '/../../modules/vatnumber/vatnumber.php') && VatNumber::isApplicable($address_delivery->id_country) && Configuration::get('VATNUMBER_COUNTRY') != $address_delivery->id_country) {
                                 $allow_eu_vat_delivery = 1;
                             } else {
                                 $allow_eu_vat_delivery = 0;
                             }
                             if (isset($address_invoice) && Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(dirname(__FILE__) . '/../../modules/vatnumber/vatnumber.php') && VatNumber::isApplicable($address_invoice->id_country) && Configuration::get('VATNUMBER_COUNTRY') != $address_invoice->id_country) {
                                 $allow_eu_vat_invoice = 1;
                             } else {
                                 $allow_eu_vat_invoice = 0;
                             }
                             $wrapping_fees_tax = new Tax((int) Configuration::get('PS_GIFT_WRAPPING_TAX'));
                             if (version_compare(_PS_VERSION_, "1.5.2.0") <= 0) {
                                 $wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
                                 $wrapping_fees_tax_inc = $wrapping_fees * (1 + (double) $wrapping_fees_tax->rate / 100);
                             } else {
                                 $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
                                 $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
                             }
                             $return = array_merge(array('customer_info' => $customer_info, 'allow_eu_vat_delivery' => $allow_eu_vat_delivery, 'allow_eu_vat_invoice' => $allow_eu_vat_invoice, 'customer_addresses' => $this->context->smarty->tpl_vars['addresses']->value, 'block_user_info' => isset($blockUserInfo) ? method_exists($blockUserInfo, 'hookTop') ? $blockUserInfo->hookTop(array()) : $blockUserInfo->hookDisplayTop(array()) : '', 'carrier_data' => $this->_getCarrierList(), 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'no_address' => 0, 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) $this->context->cookie->id_currency)))), $this->getFormatedSummaryDetail());
                             die(Tools::jsonEncode($return));
                         }
                         die(Tools::displayError("Customer is not logged in, while he should be. Check please AuthController and cookies."));
                         break;
                     case 'makeFreeOrder':
                         if (($id_order = $this->_checkFreeOrder()) && $id_order) {
                             $order = new Order((int) $id_order);
                             $email = $this->context->customer->email;
                             if ($this->context->customer->is_guest) {
                                 $this->context->customer->logout();
                             }
                             // If guest we clear the cookie for security reason
                             die('freeorder:' . $order->reference . ':' . $email);
                         }
                         exit;
                         break;
                     case 'updateAddressesSelected':
                         $id_address_delivery = (int) Tools::getValue('id_address_delivery');
                         $id_address_invoice = (int) Tools::getValue('id_address_invoice');
                         $address_delivery = new Address((int) Tools::getValue('id_address_delivery'));
                         $address_invoice = (int) Tools::getValue('id_address_delivery') == (int) Tools::getValue('id_address_invoice') ? $address_delivery : new Address((int) Tools::getValue('id_address_invoice'));
                         if (Configuration::get('VATNUMBER_MANAGEMENT') && file_exists(_PS_MODULE_DIR_ . '/vatnumber/vatnumber.php') && !class_exists("VatNumber", false)) {
                             include_once _PS_MODULE_DIR_ . '/vatnumber/vatnumber.php';
                         }
                         if (isset($address_delivery) && Configuration::get('VATNUMBER_MANAGEMENT') && file_exists(_PS_MODULE_DIR_ . '/vatnumber/vatnumber.php') && VatNumber::isApplicable($address_delivery->id_country) && Configuration::get('VATNUMBER_COUNTRY') != $address_delivery->id_country) {
                             $allow_eu_vat_delivery = 1;
                         } else {
                             $allow_eu_vat_delivery = 0;
                         }
                         if (isset($address_invoice) && Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(_PS_MODULE_DIR_ . '/vatnumber/vatnumber.php') && VatNumber::isApplicable($address_invoice->id_country) && Configuration::get('VATNUMBER_COUNTRY') != $address_invoice->id_country) {
                             $allow_eu_vat_invoice = 1;
                         } else {
                             $allow_eu_vat_invoice = 0;
                         }
                         $address_delivery = new Address((int) Tools::getValue('id_address_delivery'));
                         $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart());
                         $address_invoice = (int) Tools::getValue('id_address_delivery') == (int) Tools::getValue('id_address_invoice') ? $address_delivery : new Address((int) Tools::getValue('id_address_invoice'));
                         if ($address_delivery->id_customer && $address_delivery->id_customer != $this->context->customer->id || $address_invoice->id_customer && $address_invoice->id_customer != $this->context->customer->id) {
                             $this->errors = "not_your_address";
                         }
                         if (!Address::isCountryActiveById((int) Tools::getValue('id_address_delivery'))) {
                             $this->errors[] = Tools::displayError('This address is not in a valid area.');
                         } elseif (!Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) {
                             $this->errors[] = Tools::displayError('This address is invalid.');
                         } else {
                             $this->context->cart->id_address_delivery = (int) Tools::getValue('id_address_delivery');
                             $this->context->cart->id_address_invoice = Tools::isSubmit('same') ? $this->context->cart->id_address_delivery : (int) Tools::getValue('id_address_invoice');
                             if (!$this->context->cart->update()) {
                                 $this->errors[] = Tools::displayError('An error occurred while updating your cart.');
                             }
                             CartRule::autoRemoveFromCart($this->context);
                             CartRule::autoAddToCart($this->context);
                             $this->context->cart->setNoMultishipping();
                             // As the cart is no multishipping, set each delivery address lines with the main delivery address
                             if (!count($this->errors)) {
                                 $result = $this->_getCarrierList();
                                 $wrapping_fees_tax = new Tax((int) Configuration::get('PS_GIFT_WRAPPING_TAX'));
                                 if (version_compare(_PS_VERSION_, "1.5.2.0") <= 0) {
                                     $wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
                                     $wrapping_fees_tax_inc = $wrapping_fees * (1 + (double) $wrapping_fees_tax->rate / 100);
                                 } else {
                                     $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
                                     $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
                                 }
                                 $result = array_merge($result, array('allow_eu_vat_delivery' => $allow_eu_vat_delivery, 'allow_eu_vat_invoice' => $allow_eu_vat_invoice, 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) $this->context->cookie->id_currency))), 'carrier_data' => $this->_getCarrierList()), $this->getFormatedSummaryDetail());
                                 die(Tools::jsonEncode($result));
                             }
                         }
                         if (count($this->errors)) {
                             die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors)));
                         }
                         break;
                     case 'multishipping':
                         $this->_assignSummaryInformations();
                         $this->context->smarty->assign('product_list', $this->context->cart->getProducts());
                         if ($this->context->customer->id) {
                             $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id));
                         } else {
                             $this->context->smarty->assign('address_list', array());
                         }
                         $this->setTemplate(_PS_THEME_DIR_ . 'order-address-multishipping-products.tpl');
                         $this->display();
                         die;
                         break;
                     case 'cartReload':
                         $this->_assignSummaryInformations();
                         if ($this->context->customer->id) {
                             $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id));
                         } else {
                             $this->context->smarty->assign('address_list', array());
                         }
                         $this->context->smarty->assign('opc', true);
                         $this->setTemplate(_PS_THEME_DIR_ . 'shopping-cart.tpl');
                         $this->display();
                         die;
                         break;
                     case 'noMultiAddressDelivery':
                         $this->context->cart->setNoMultishipping();
                         die;
                         break;
                     case 'emailCheck':
                         if (Tools::isSubmit('cust_email')) {
                             $customer_email = Tools::getValue('cust_email');
                             $is_registered = Validate::isEmail($customer_email) ? Customer::customerExists($customer_email) : 0;
                             $return = array('is_registered' => $is_registered);
                             die(Tools::jsonEncode($return));
                         }
                         break;
                     case 'zipCheck':
                         if (Tools::isSubmit('id_country')) {
                             $id_country = Tools::getValue('id_country');
                             if ($id_country > 0) {
                                 $errors = array();
                                 $country = new Country($id_country);
                                 $zip_code_format = $country->zip_code_format;
                                 if ($country->need_zip_code) {
                                     if ($postcode = Tools::getValue('postcode') and $zip_code_format) {
                                         $zip_regexp = '/^' . $zip_code_format . '$/ui';
                                         $zip_regexp = str_replace(' ', '( |)', $zip_regexp);
                                         $zip_regexp = str_replace('-', '(-|)', $zip_regexp);
                                         $zip_regexp = str_replace('N', '[0-9]', $zip_regexp);
                                         $zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp);
                                         $zip_regexp = str_replace('C', $country->iso_code, $zip_regexp);
                                         if (!preg_match($zip_regexp, $postcode)) {
                                             $errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
                                         }
                                     } elseif ($zip_code_format) {
                                         $errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is required.');
                                     } elseif ($postcode and !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
                                         $errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
                                     }
                                 }
                             }
                             //if($id_country>0)
                             $return = array('is_ok' => empty($errors), 'errors' => $errors);
                             die(Tools::jsonEncode($return));
                         }
                         break;
                     default:
                         throw new PrestaShopException('Unknown method "' . Tools::getValue('method') . '"');
                 }
             } else {
                 throw new PrestaShopException('Method is not defined');
             }
         }
     } elseif (Tools::isSubmit('ajax')) {
         throw new PrestaShopException('Method is not defined');
     }
 }