Esempio n. 1
0
 public function init()
 {
     parent::init();
     if (Tools::isSubmit('storedelivery') && (int) Tools::getValue('storedelivery') != 0) {
         //Save cookie only if previous id_adress wasn't a store
         $cookie = new Cookie('storedelivery');
         $cookie->__set('id_address_delivery', $this->context->cart->id_address_delivery);
         $store = new Store(Tools::getValue('storedelivery'));
         //Test if store address exist in address table
         Tools::strlen($store->name) > 32 ? $storeName = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($storeName = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
         $sql = 'SELECT id_address FROM ' . _DB_PREFIX_ . 'address WHERE alias=\'' . addslashes($storeName) . '\' AND address1=\'' . addslashes($store->address1) . '\' AND address2=\'' . addslashes($store->address2) . '\' AND postcode=\'' . $store->postcode . '\' AND city=\'' . addslashes($store->city) . '\' AND id_country=\'' . addslashes($store->id_country) . '\' AND active=1 AND deleted=0';
         $id_address = Db::getInstance()->getValue($sql);
         //Create store adress if not exist for this user
         if (empty($id_address)) {
             $country = new Country($store->id_country, $this->context->language->id);
             $address = new Address();
             $address->id_country = $store->id_country;
             $address->id_state = $store->id_state;
             $address->country = $country->name;
             Tools::strlen($store->name) > 32 ? $address->alias = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->alias = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             Tools::strlen($store->name) > 32 ? $address->lastname = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->lastname = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             $address->firstname = " ";
             $address->address1 = $store->address1;
             $address->address2 = $store->address2;
             $address->postcode = $store->postcode;
             $address->city = $store->city;
             $address->phone = $store->phone;
             $address->deleted = 0;
             //create an address non deleted to register them in order
             $address->add();
             $id_address = $address->id;
         }
         //Update cart info
         $cart = $this->context->cart;
         $cart->id_address_delivery = $id_address;
         $cart->update();
         //Change address of all product in cart else we are redirect on step Carrier because of function autostep or OrderController
         Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $id_address), $where = 'id_cart = ' . $this->context->cart->id);
         //Change post carrier option else bad default carrier is saved by fonction processCarrier of ParentOrderController
         $array = array_values(Tools::getValue('delivery_option'));
         $_POST['delivery_option'] = array($id_address => $array[0]);
     } else {
         $cookie = new Cookie('storedelivery');
         $id_address_delivery = $cookie->__get('id_address_delivery');
         if ($id_address_delivery != false && $this->context->cart->id_address_delivery != $id_address_delivery && Tools::isSubmit('storedelivery')) {
             $this->context->cart->id_address_delivery = $cookie->__get('id_address_delivery');
             $this->context->cart->update();
             //Change address of all product in cart else we are redirect on step Carrier because of function autostep or OrderController
             Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $cookie->__get('id_address_delivery')), $where = 'id_cart = ' . $this->context->cart->id);
             //Change post carrier option else bad default carrier is saved by fonction processCarrier of ParentOrderController
             $array = array_values(Tools::getValue('delivery_option'));
             $_POST['delivery_option'] = array($cookie->__get('id_address_delivery') => $array[0]);
             $cookie->__unset('id_address_delivery');
         }
     }
 }
Esempio n. 2
0
 public function process()
 {
     parent::process();
     if (Module::isInstalled('agilesellershipping')) {
         include_once _PS_ROOT_DIR_ . "/modules/agilesellershipping/agilesellershipping.php";
         if (intval($this->step) == 2) {
             AgileSellerShipping::override_carriers();
         }
     }
 }
Esempio n. 3
0
 public function init()
 {
     parent::init();
     if (Tools::isSubmit('storedelivery') && (int) Tools::getValue('storedelivery') != 0) {
         $cookie = new Cookie('storedelivery');
         $cookie->__set('id_address_delivery', $this->context->cart->id_address_delivery);
         $store = new Store(Tools::getValue('storedelivery'));
         Tools::strlen($store->name) > 32 ? $storeName = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($storeName = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
         $sql = 'SELECT id_address FROM ' . _DB_PREFIX_ . 'address WHERE alias=\'' . addslashes($storeName) . '\' AND address1=\'' . addslashes($store->address1) . '\' AND address2=\'' . addslashes($store->address2) . '\' AND postcode=\'' . $store->postcode . '\' AND city=\'' . addslashes($store->city) . '\' AND id_country=\'' . addslashes($store->id_country) . '\' AND active=1 AND deleted=0';
         $id_address = Db::getInstance()->getValue($sql);
         if (empty($id_address)) {
             $country = new Country($store->id_country, $this->context->language->id);
             $address = new Address();
             $address->id_country = $store->id_country;
             $address->id_state = $store->id_state;
             $address->country = $country->name;
             Tools::strlen($store->name) > 32 ? $address->alias = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->alias = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             Tools::strlen($store->name) > 32 ? $address->lastname = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->lastname = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             $address->firstname = " ";
             $address->address1 = $store->address1;
             $address->address2 = $store->address2;
             $address->postcode = $store->postcode;
             $address->city = $store->city;
             $address->phone = $store->phone;
             $address->deleted = 0;
             $address->add();
             $id_address = $address->id;
         }
         $cart = $this->context->cart;
         $cart->id_address_delivery = $id_address;
         $cart->update();
         Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $id_address), $where = 'id_cart = ' . $this->context->cart->id);
         $array = array_values(Tools::getValue('delivery_option'));
         $_POST['delivery_option'] = array($id_address => $array[0]);
     } else {
         $cookie = new Cookie('storedelivery');
         $id_address_delivery = $cookie->__get('id_address_delivery');
         if ($id_address_delivery != false && $this->context->cart->id_address_delivery != $id_address_delivery && Tools::isSubmit('storedelivery')) {
             $this->context->cart->id_address_delivery = $cookie->__get('id_address_delivery');
             $this->context->cart->update();
             Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $cookie->__get('id_address_delivery')), $where = 'id_cart = ' . $this->context->cart->id);
             $array = array_values(Tools::getValue('delivery_option'));
             $_POST['delivery_option'] = array($cookie->__get('id_address_delivery') => $array[0]);
             $cookie->__unset('id_address_delivery');
         }
     }
 }
 public function setMedia()
 {
     parent::setMedia();
     if ($this->step == 2) {
         $this->addJS(_THEME_JS_DIR_ . 'order-carrier.js');
     }
     if ($this->step == 3) {
         $this->addJqueryUI('ui.datepicker');
         $this->addJqueryPlugin('validate');
         if (isset($this->context->cookie->{'error_pay'}) && !empty($this->context->cookie->{'error_pay'})) {
             $error_pay = json_decode($this->context->cookie->{'error_pay'}, true);
             $this->context->smarty->assign(array('errors_msgs' => $error_pay));
             $this->context->smarty->assign(array('errors_pay' => 'true'));
             //echo ('<pre>'.print_r($error_pay,true).'</pre>');
             // unset($this->context->cookie->{'error_pay'});
         } else {
             $this->context->smarty->assign(array('errors_pay' => 'false'));
         }
     }
 }
 /**
  * Initialize front controller.
  *
  * @return 	this
  */
 public function init()
 {
     // is the user logged in?
     if (!$this->context->customer->isLogged(true)) {
         // get current url
         $back_url = $this->context->link->getPageLink('order', true, (int) $this->context->language->id, $params);
         // set url parameters
         $params = array('back' => $back_url);
         // redirect to log in page
         Tools::redirect($this->context->link->getPageLink('authentication', true, (int) $this->context->language->id, $params));
     }
     $configuration = unserialize(Configuration::get('CHECKMEOUT'));
     if (!isset($configuration['CHECKMEOUT_API_TOKEN'], $configuration['CHECKMEOUT_API_SECRET'], $configuration['CHECKMEOUT_REFERENCE'])) {
         Tools::redirect('/');
     }
     $token = $configuration['CHECKMEOUT_API_TOKEN'];
     $secret = $configuration['CHECKMEOUT_API_SECRET'];
     $checkmeout = new CheckMeOutBase($token, $secret);
     parent::init();
     $cart = $this->context->cart;
     $summary = $this->context->cart->getSummaryDetails();
     $products = $this->context->cart->getProducts(true);
     foreach ($products as $product) {
         $image = $this->context->link->getImageLink($product['link_rewrite'], $product['id_image'], 'home_default');
         $link = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?controller=product&id_product=' . $product['id_product'];
         $price = 0;
         $checkmeout->addItem($product['name'], $product['total'], $image, $link);
     }
     $shipping = $summary['total_shipping'];
     $tax = $summary['total_tax'];
     if ($summary['total_shipping_tax_exc'] > 0) {
         $shipping = $summary['total_shipping_tax_exc'];
     }
     if ($shipping > 0) {
         $checkmeout->addItem('Shipping Cost', $shipping, null, null);
     }
     if ($tax > 0) {
         $checkmeout->addItem('Tax', $tax, null, null);
     }
     // if user is logged in
     if ($this->context->customer->isLogged(true)) {
         // get the customer details
         $customer = $this->context->customer;
         // get the fullname
         $fullname = $customer->firstname . ' ' . $customer->lastname;
         // set customer information
         $checkmeout->setCustomer($fullname, $customer->email, null);
     }
     $currency = $this->context->currency->iso_code;
     // get all addresses
     $addresses = $this->context->customer->getAddresses($this->context->language->id);
     foreach ($addresses as $address) {
         // get the customer details
         $customer = $this->context->customer;
         // get the fullname
         $fullname = $customer->firstname . ' ' . $customer->lastname;
         // set customer information
         $checkmeout->setCustomer($fullname, $customer->email, $address['phone_mobile']);
         // get country iso code
         $country = $this->context->country->iso_code;
         $city = 'N/A';
         if (isset($address['city']) && $address['city'] != '') {
             $city = $address['city'];
         }
         $state = 'N/A';
         // if state is set
         if ($address['id_state'] != 0) {
             // get the state by id
             $state = new State(intval($addres['id_state']));
             // get the state
             $state = $state->name;
         }
         $checkmeout->addAddress($address['alias'], $address['address1'], $city, $state, $country, $address['postcode']);
     }
     $redirect = $checkmeout->setRedirect('http://' . $_SERVER['HTTP_HOST'] . '/module/checkmeout/confirmation')->setTitle($configuration['CHECKMEOUT_TITLE'])->setWebsite($configuration['CHECKMEOUT_WEBSITE'])->setLogo($configuration['CHECKMEOUT_LOGO'])->setFavicon($configuration['CHECKMEOUT_FAVICON'])->setStyles($configuration['CHECKMEOUT_STYLES'])->setTerms($configuration['CHECKMEOUT_TERMS'])->setGateway($configuration['CHECKMEOUT_GATEWAYS'])->setCurrency($currency)->setShipping(1)->setCallbackUrl('http://' . $_SERVER['HTTP_HOST'] . '/order')->setSession($configuration['CHECKMEOUT_REFERENCE'])->getCheckoutUrl();
     Tools::redirect($redirect);
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     if (Tools::isSubmit('ajax') && Tools::getValue('method') == 'updateExtraCarrier') {
         // Change virtualy the currents delivery options
         $delivery_option = $this->context->cart->getDeliveryOption();
         $delivery_option[(int) Tools::getValue('id_address')] = Tools::getValue('id_delivery_option');
         $this->context->cart->setDeliveryOption($delivery_option);
         $this->context->cart->save();
         $return = array('content' => Hook::exec('displayCarrierList', array('address' => new Address((int) Tools::getValue('id_address')))));
         die(Tools::jsonEncode($return));
     }
     // start of implementation of the module code - taxamo
     if ((int) $this->step == 2) {
         // $this->errors = array_merge($this->errors, $taxamo_errores);
         // $this->step = 0;
         $merchants_self_settings = Tools::getMerchantsSelfSettings();
         if ($merchants_self_settings['allow_sms_verification']) {
             $invoice_address = new Address((int) $this->context->cart->id_address_invoice);
             $iso_country_code = Country::getIsoById($invoice_address->id_country);
             $token_taxamo = Tools::getValue('tokenTaxamo');
             if ($token_taxamo) {
                 $res_api_verify_sms_token = Tools::taxamoVerifySmsToken($token_taxamo);
                 if (isset($res_api_verify_sms_token['country_code']) && $res_api_verify_sms_token['country_code'] == $iso_country_code) {
                     Taxamoeuvat::updateCCPrefix((int) $this->context->cart->id_customer, null, null, $token_taxamo);
                 } else {
                     $iso_country_residence = Taxamoeuvat::getCountryByCustomer((int) $this->context->cart->id_customer);
                     $cc_prefix = Taxamoeuvat::getPrefixByCustomer((int) $this->context->cart->id_customer);
                     Taxamoeuvat::updateCCPrefix((int) $this->context->cart->id_customer, $iso_country_residence, $cc_prefix, null);
                 }
             }
         }
         if ($taxamo_errores = Tools::taxamoVerifyTaxes($this->context->cart)) {
             $this->errors = array_merge($this->errors, $taxamo_errores);
             $this->context->smarty->assign('allow_sms_verification', $merchants_self_settings['allow_sms_verification']);
             if ($merchants_self_settings['allow_sms_verification']) {
                 $this->context->smarty->assign('iso_country_code', $iso_country_code);
                 $country_name = Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $invoice_address->id_country);
                 $this->context->smarty->assign('country_name', $country_name);
             }
             $this->setTemplate(_PS_MODULE_DIR_ . 'taxamoeuvat/views/templates/front/info.tpl');
             return;
         }
     }
     // end of code implementation module - taxamo
     if ($this->nbProducts) {
         $this->context->smarty->assign('virtual_cart', $this->context->cart->isVirtualCart());
     }
     if (!Tools::getValue('multi-shipping')) {
         $this->context->cart->setNoMultishipping();
     }
     // 4 steps to the order
     switch ((int) $this->step) {
         case -1:
             $this->context->smarty->assign('empty', 1);
             $this->setTemplate(_PS_THEME_DIR_ . 'shopping-cart.tpl');
             break;
         case 1:
             $this->_assignAddress();
             $this->processAddressFormat();
             if (Tools::getValue('multi-shipping') == 1) {
                 $this->_assignSummaryInformations();
                 $this->context->smarty->assign('product_list', $this->context->cart->getProducts());
                 $this->setTemplate(_PS_THEME_DIR_ . 'order-address-multishipping.tpl');
             } else {
                 $this->setTemplate(_PS_THEME_DIR_ . 'order-address.tpl');
             }
             break;
         case 2:
             if (Tools::isSubmit('processAddress')) {
                 $this->processAddress();
             }
             $this->autoStep();
             $this->_assignCarrier();
             $this->setTemplate(_PS_THEME_DIR_ . 'order-carrier.tpl');
             break;
         case 3:
             // Check that the conditions (so active) were accepted by the customer
             $cgv = Tools::getValue('cgv') || $this->context->cookie->check_cgv;
             if (Configuration::get('PS_CONDITIONS') && (!Validate::isBool($cgv) || $cgv == false)) {
                 Tools::redirect('index.php?controller=order&step=2');
             }
             Context::getContext()->cookie->check_cgv = true;
             // Check the delivery option is set
             if (!$this->context->cart->isVirtualCart()) {
                 if (!Tools::getValue('delivery_option') && !Tools::getValue('id_carrier') && !$this->context->cart->delivery_option && !$this->context->cart->id_carrier) {
                     Tools::redirect('index.php?controller=order&step=2');
                 } elseif (!Tools::getValue('id_carrier') && !$this->context->cart->id_carrier) {
                     $deliveries_options = Tools::getValue('delivery_option');
                     if (!$deliveries_options) {
                         $deliveries_options = $this->context->cart->delivery_option;
                     }
                     foreach ($deliveries_options as $delivery_option) {
                         if (empty($delivery_option)) {
                             Tools::redirect('index.php?controller=order&step=2');
                         }
                     }
                 }
             }
             $this->autoStep();
             // Bypass payment step if total is 0
             if (($id_order = $this->_checkFreeOrder()) && $id_order) {
                 if ($this->context->customer->is_guest) {
                     $order = new Order((int) $id_order);
                     $email = $this->context->customer->email;
                     $this->context->customer->mylogout();
                     // If guest we clear the cookie for security reason
                     Tools::redirect('index.php?controller=guest-tracking&id_order=' . urlencode($order->reference) . '&email=' . urlencode($email));
                 } else {
                     Tools::redirect('index.php?controller=history');
                 }
             }
             $this->_assignPayment();
             // assign some informations to display cart
             $this->_assignSummaryInformations();
             $this->setTemplate(_PS_THEME_DIR_ . 'order-payment.tpl');
             break;
         default:
             $this->_assignSummaryInformations();
             $this->setTemplate(_PS_THEME_DIR_ . 'shopping-cart.tpl');
             break;
     }
     $this->context->smarty->assign(array('currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank));
 }