Beispiel #1
0
 /**
  * Initialize order controller
  * @see FrontController::init()
  */
 public function init()
 {
     global $orderTotal;
     parent::init();
     $this->step = (int) Tools::getValue('step');
     if (!$this->nbProducts) {
         $this->step = -1;
     }
     // If some products have disappear
     if (!$this->context->cart->checkQuantities()) {
         $this->step = 0;
         $this->errors[] = Tools::displayError('An item in your cart is no longer available in this quantity, you cannot proceed with your order.');
     }
     // Check minimal amount
     $currency = Currency::getCurrency((int) $this->context->cart->id_currency);
     $orderTotal = $this->context->cart->getOrderTotal();
     $minimal_purchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
     if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase && $this->step != -1) {
         $this->step = 0;
         $this->errors[] = sprintf(Tools::displayError('A minimum purchase total of %d is required in order to validate your order.'), Tools::displayPrice($minimal_purchase, $currency));
     }
     if (!$this->context->customer->isLogged(true) && in_array($this->step, array(1, 2, 3))) {
         Tools::redirect($this->context->link->getPageLink('authentication', true, (int) $this->context->language->id, 'back=' . $this->context->link->getPageLink('order', true, (int) $this->context->language->id, 'step=' . $this->step . '&multi-shipping=' . (int) Tools::getValue('multi-shipping')) . '&multi-shipping=' . (int) Tools::getValue('multi-shipping')));
     }
     if (Tools::getValue('multi-shipping') == 1) {
         $this->context->smarty->assign('multi_shipping', true);
     } else {
         $this->context->smarty->assign('multi_shipping', false);
     }
     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());
     }
 }
 public function init()
 {
     parent::init();
     $this->step = (int) Tools::getValue('step');
     if (!$this->nbProducts) {
         $this->step = -1;
     }
 }
Beispiel #3
0
 /**
  * Initialize order controller
  * @see FrontController::init()
  */
 public function init()
 {
     global $orderTotal;
     parent::init();
     $this->step = (int) Tools::getValue('step');
     if (!$this->nbProducts) {
         $this->step = -1;
     }
     $product = $this->context->cart->checkQuantities(true);
     if ((int) ($id_product = $this->context->cart->checkProductsAccess())) {
         $this->step = 0;
         $this->errors[] = sprintf(Tools::displayError('An item in your cart is no longer available (%1s). You cannot proceed with your order.'), Product::getProductName((int) $id_product));
     }
     // If some products have disappear
     if (is_array($product)) {
         $this->step = 0;
         $this->errors[] = sprintf(Tools::displayError('An item (%1s) in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.'), $product['name']);
     }
     // Check minimal amount
     $currency = Currency::getCurrency((int) $this->context->cart->id_currency);
     $orderTotal = $this->context->cart->getOrderTotal();
     $minimal_purchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
     if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase && $this->step > 0) {
         $this->step = 0;
         $this->errors[] = sprintf(Tools::displayError('A minimum purchase total of %1s (tax excl.) is required to validate your order, current purchase total is %2s (tax excl.).'), Tools::displayPrice($minimal_purchase, $currency), Tools::displayPrice($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS), $currency));
     }
     if (!$this->context->customer->isLogged(true) && in_array($this->step, array(1, 2, 3))) {
         $params = array();
         if ($this->step) {
             $params['step'] = (int) $this->step;
         }
         if ($multi = (int) Tools::getValue('multi-shipping')) {
             $params['multi-shipping'] = $multi;
         }
         $back_url = $this->context->link->getPageLink('order', true, (int) $this->context->language->id, $params);
         $params = array('back' => $back_url);
         if ($multi) {
             $params['multi-shipping'] = $multi;
         }
         if ($guest = (int) Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
             $params['display_guest_checkout'] = $guest;
         }
         Tools::redirect($this->context->link->getPageLink('authentication', true, (int) $this->context->language->id, $params));
     }
     if (Tools::getValue('multi-shipping') == 1) {
         $this->context->smarty->assign('multi_shipping', true);
     } else {
         $this->context->smarty->assign('multi_shipping', false);
     }
     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());
     }
 }
Beispiel #4
0
 /**
  * Initialize order controller
  * @see FrontController::init()
  */
 public function init()
 {
     global $orderTotal;
     parent::init();
     $this->step = (int) Tools::getValue('step');
     if (!$this->nbProducts) {
         $this->step = -1;
     }
     // If some products have disappear
     if (!$this->context->cart->checkQuantities()) {
         $this->step = 0;
         $this->errors[] = Tools::displayError('An item in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.');
     }
     // Check minimal amount
     $currency = Currency::getCurrency((int) $this->context->cart->id_currency);
     //Gelikon Стоимость товаров без доставки BEGIN
     $cart_products = $this->context->cart->getProducts();
     $products_total_wt = 0;
     if ($cart_products) {
         foreach ($cart_products as $cart_product) {
             $products_total_wt += $cart_product["total_wt"];
         }
     }
     $this->context->smarty->assign('products_total_wt', $products_total_wt);
     //Gelikon Стоимость товаров без доставки END
     $orderTotal = $this->context->cart->getOrderTotal();
     $this->context->smarty->assign('global_order_total', $orderTotal);
     $minimal_purchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
     if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase && $this->step > 0) {
         $this->step = 0;
         $this->errors[] = sprintf(Tools::displayError('A minimum purchase total of %1s (tax excl.) is required in order to validate your order, current purchase total is %2s (tax excl.).'), Tools::displayPrice($minimal_purchase, $currency), Tools::displayPrice($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS), $currency));
     }
     if (!$this->context->customer->isLogged(true) && in_array($this->step, array(1, 2, 3))) {
         $back_url = $this->context->link->getPageLink('order', true, (int) $this->context->language->id, array('step' => $this->step, 'multi-shipping' => (int) Tools::getValue('multi-shipping')));
         $params = array('multi-shipping' => (int) Tools::getValue('multi-shipping'), 'display_guest_checkout' => (int) Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'back' => $back_url);
         Tools::redirect($this->context->link->getPageLink('authentication', true, (int) $this->context->language->id, $params));
     }
     if (Tools::getValue('multi-shipping') == 1) {
         $this->context->smarty->assign('multi_shipping', true);
     } else {
         $this->context->smarty->assign('multi_shipping', false);
     }
     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());
     }
 }
Beispiel #5
0
 /**
  * Initialize order opc controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if ($this->nbProducts) {
         $this->context->smarty->assign('virtual_cart', $this->context->cart->isVirtualCart());
     }
     $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);
     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();
                             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('An error occurred while updating the 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('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods())));
                         }
                         break;
                     case 'getCarrierList':
                         die(Tools::jsonEncode($this->_getCarrierList()));
                         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');
                         }
                         $_POST['lastname'] = $_POST['customer_lastname'];
                         $_POST['firstname'] = $_POST['customer_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()) {
                             // check if customer have addresses
                             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());
                             $this->_processAddressFormat();
                             $this->_assignAddress();
                             if (!($formatedAddressFieldsValuesList = $this->context->smarty->getTemplateVars('formatedAddressFieldsValuesList'))) {
                                 $formatedAddressFieldsValuesList = array();
                             }
                             // Wrapping fees
                             $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
                             $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
                             $return = array_merge(array('order_opc_adress' => $this->context->smarty->fetch(_PS_THEME_DIR_ . 'order-address.tpl'), 'block_user_info' => isset($blockUserInfo) ? $blockUserInfo->hookDisplayTop(array()) : '', 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList, '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());
                         break;
                     case 'makeFreeOrder':
                         /* Bypass payment step if total is 0 */
                         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':
                         if ($this->context->customer->isLogged(true)) {
                             $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 != $this->context->customer->id || $address_invoice->id_customer != $this->context->customer->id) {
                                 $this->errors[] = Tools::displayError('This address is not yours.');
                             } elseif (!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.');
                                 }
                                 $infos = Address::getCountryAndState((int) $this->context->cart->id_address_delivery);
                                 if (isset($infos['id_country']) && $infos['id_country']) {
                                     $country = new Country((int) $infos['id_country']);
                                     $this->context->country = $country;
                                 }
                                 // Address has changed, so we check if the cart rules still apply
                                 $cart_rules = $this->context->cart->getCartRules();
                                 CartRule::autoRemoveFromCart($this->context);
                                 CartRule::autoAddToCart($this->context);
                                 if ((int) Tools::getValue('allow_refresh')) {
                                     // If the cart rules has changed, we need to refresh the whole cart
                                     $cart_rules2 = $this->context->cart->getCartRules();
                                     if (count($cart_rules2) != count($cart_rules)) {
                                         $this->ajax_refresh = true;
                                     } else {
                                         $rule_list = array();
                                         foreach ($cart_rules2 as $rule) {
                                             $rule_list[] = $rule['id_cart_rule'];
                                         }
                                         foreach ($cart_rules as $rule) {
                                             if (!in_array($rule['id_cart_rule'], $rule_list)) {
                                                 $this->ajax_refresh = true;
                                                 break;
                                             }
                                         }
                                     }
                                 }
                                 if (!$this->context->cart->isMultiAddressDelivery()) {
                                     $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
                                     $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
                                     $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
                                     $result = array_merge($result, array('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(), 'refresh' => (bool) $this->ajax_refresh), $this->getFormatedSummaryDetail());
                                     die(Tools::jsonEncode($result));
                                 }
                             }
                             if (count($this->errors)) {
                                 die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors)));
                             }
                         }
                         die(Tools::displayError());
                         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;
                     default:
                         throw new PrestaShopException('Unknown method "' . Tools::getValue('method') . '"');
                 }
             } else {
                 throw new PrestaShopException('Method is not defined');
             }
         }
     } elseif (Tools::isSubmit('ajax')) {
         $this->errors[] = Tools::displayError('No product in your cart.');
         die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
     }
 }
 /**
  * Initialize order opc controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if ($this->nbProducts) {
         $this->context->smarty->assign('virtual_cart', $this->context->cart->isVirtualCart());
     }
     $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);
     if ($this->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();
                             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('An error occurred while updating the cart.');
                             }
                             if (count($this->errors)) {
                                 die('{"hasError" : true, "errors_discount" : ["' . implode('\',\'', $this->errors) . '"]}');
                             }
                             exit;
                         }
                         break;
                     case 'updateTOSStatusAndGetPayments':
                         if (Tools::isSubmit('checked')) {
                             $this->context->cookie->checkedTOS = (int) Tools::getValue('checked');
                             die(Tools::jsonEncode(array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods())));
                         }
                         break;
                     case 'getCarrierList':
                         die(Tools::jsonEncode($this->_getCarrierList()));
                         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');
                         }
                         $_POST['lastname'] = $_POST['customer_lastname'];
                         $_POST['firstname'] = $_POST['customer_firstname'];
                         $this->errors = $this->context->customer->validateController();
                         //var_dump($this->errors);
                         if (Tools::getValue('delivery_form')) {
                             $address = new Address($this->context->cart->id_address_delivery);
                             if (empty($_POST['city'])) {
                                 $this->errors['city_courier'] = Tools::displayError('Город обязателен');
                             }
                             if (empty($_POST['street'])) {
                                 $this->errors['street_courier'] = Tools::displayError('Улица обязательна');
                             }
                             if (empty($_POST['house'])) {
                                 $this->errors['house_courier'] = Tools::displayError('Дом обязателен');
                             }
                             if (!Tools::getValue('phone')) {
                                 $this->errors['phone'] = Tools::displayError('Телефон обязателен');
                             } else {
                                 if (!Validate::isPhoneNumber(Tools::getValue('phone'))) {
                                     $this->errors['phone'] = Tools::displayError('мобильный телефон неверный');
                                 }
                             }
                             if (!empty($_POST['date_dilivery'])) {
                                 $address->other = 'Удобная дата доставки: ' . $_POST['date_dilivery'];
                             }
                             if (!count($this->errors) && is_object($address) && isset($address->id_customer)) {
                                 $address->address1 = $_POST['city'] . ' ' . $_POST['street'] . ' ' . $_POST['house'];
                                 $address->city = $_POST['city'];
                                 $address->firstname = $_POST['firstname'];
                                 $address->phone_mobile = $_POST['phone'];
                                 $delivery_pickup = array('delivery_city' => $_POST['city'], 'delivery_street' => $_POST['street'], 'delivery_house' => $_POST['house'], 'delivery_date' => isset($_POST['delivery_date']) ? $_POST['delivery_date'] : '');
                                 $address->other = $delivery_pickup['delivery_date'];
                                 foreach ($delivery_pickup as $k => $v) {
                                     $this->context->cookie->{$k} = $v;
                                 }
                                 $address->save();
                             }
                             //else
                             //$this->errors[] = Tools::displayError('Невозможно загрузить адресс');
                         }
                         $this->context->customer->newsletter = (int) Tools::isSubmit('newsletter');
                         $this->context->customer->optin = (int) Tools::isSubmit('optin');
                         //                            foreach($this->errors as $key=> $value){
                         //                               // if($key=="lastname")$key="customer_lastname";
                         //                               // if($key=="firstname")$key="customer_firstname";
                         //                                $this->val_errors[$key]=$value;
                         //                            }
                         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_customer' => (int) $this->context->customer->id, 'token' => Tools::getToken(false));
                         if (!count($this->errors)) {
                             $url = 'http://api.unisender.com/ru/api/subscribe?format=json&api_key=58priw95sdjt7umw17ixbnkkkudtoq5u7nmfcacy&list_ids=4734062';
                             $url .= '&fields[email]=' . trim($_POST['email']);
                             $url .= '&fields[Name]=' . urlencode($_POST['firstname'] . ' ' . $_POST['lastname']);
                             $url .= '&fields[phone]=' . trim($_POST['phone']);
                             $url .= '&tags=dev_etagerca';
                             $url .= '&double_optin=3';
                             $curl = curl_init($url);
                             curl_setopt_array($curl, array(CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true));
                             $result = json_decode(curl_exec($curl), true);
                             // var_dump($url);var_dump($result);exit();
                             if ($result['result'] && $result['result']['person_id']) {
                                 setcookie('subscribe', '1', time() + 31536000);
                                 $_COOKIE['subscribe'] = '1';
                             }
                             $return['isSaved'] = (bool) $this->context->customer->update();
                         } else {
                             $return['isSaved'] = false;
                         }
                         die(Tools::jsonEncode($return));
                         break;
                     case 'getAddressBlockAndCarriersAndPayments':
                         if ($this->isLogged) {
                             // check if customer have addresses
                             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());
                             $this->_processAddressFormat();
                             $this->_assignAddress();
                             if (!($formatedAddressFieldsValuesList = $this->context->smarty->getTemplateVars('formatedAddressFieldsValuesList'))) {
                                 $formatedAddressFieldsValuesList = array();
                             }
                             // Wrapping fees
                             $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
                             $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
                             $return = array_merge(array('order_opc_adress' => $this->context->smarty->fetch(_PS_THEME_DIR_ . 'order-address.tpl'), 'block_user_info' => isset($blockUserInfo) ? $blockUserInfo->hookDisplayTop(array()) : '', 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList, '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());
                         break;
                     case 'makeFreeOrder':
                         /* Bypass payment step if total is 0 */
                         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':
                         if ($this->context->customer->isLogged(true)) {
                             $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 != $this->context->customer->id || $address_invoice->id_customer != $this->context->customer->id) {
                                 $this->errors[] = Tools::displayError('This address is not yours.');
                             } elseif (!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.');
                                 }
                                 $infos = Address::getCountryAndState((int) $this->context->cart->id_address_delivery);
                                 if (isset($infos['id_country']) && $infos['id_country']) {
                                     $country = new Country((int) $infos['id_country']);
                                     $this->context->country = $country;
                                 }
                                 // Address has changed, so we check if the cart rules still apply
                                 $cart_rules = $this->context->cart->getCartRules();
                                 CartRule::autoRemoveFromCart($this->context);
                                 CartRule::autoAddToCart($this->context);
                                 if ((int) Tools::getValue('allow_refresh')) {
                                     // If the cart rules has changed, we need to refresh the whole cart
                                     $cart_rules2 = $this->context->cart->getCartRules();
                                     if (count($cart_rules2) != count($cart_rules)) {
                                         $this->ajax_refresh = true;
                                     } else {
                                         $rule_list = array();
                                         foreach ($cart_rules2 as $rule) {
                                             $rule_list[] = $rule['id_cart_rule'];
                                         }
                                         foreach ($cart_rules as $rule) {
                                             if (!in_array($rule['id_cart_rule'], $rule_list)) {
                                                 $this->ajax_refresh = true;
                                                 break;
                                             }
                                         }
                                     }
                                 }
                                 if (!$this->context->cart->isMultiAddressDelivery()) {
                                     $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
                                     $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
                                     $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
                                     $result = array_merge($result, array('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(), 'refresh' => (bool) $this->ajax_refresh), $this->getFormatedSummaryDetail());
                                     die(Tools::jsonEncode($result));
                                 }
                             }
                             if (count($this->errors)) {
                                 die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors)));
                             }
                         }
                         die(Tools::displayError());
                         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;
                     default:
                         throw new PrestaShopException('Unknown method "' . Tools::getValue('method') . '"');
                 }
             } else {
                 throw new PrestaShopException('Method is not defined');
             }
         }
     } elseif (Tools::isSubmit('ajax')) {
         $this->errors[] = Tools::displayError('No product in your cart.');
         die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
     }
 }