step==1 ) $this->step=2; } public function initContent() { ParentOrderController::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)); } if ( Tools::isSubmit('ajax') && TOols::getValue('getAddressesList') ) { $result = $this->getAddressesList(); if ($result) die(Tools::jsonEncode($result)); } if ( Tools::isSubmit('ajax') && TOols::getValue('getCarriers') ) { $result = $this->getCarriersList(); exit; } /*!@Override*/ 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 $this->context->smarty->assign('current_order_step', (int)$this->step); 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(); /** * @Override */ $this->_assignAddress(); $this->processAddressFormat(); $this->_assignSummaryInformations(); // JQuery UI Date Picker $this->context->controller->addJqueryUI('ui.datepicker'); $this->setTemplate(_PS_THEME_DIR_.'order-carrier.tpl'); break; case 3: /** * @Override */ if(Tools::getValue('error') == 1) { $this->errors[] = 'Une erreur est survenue lors de votre paiement, vous pouvez réessayer'; } if(Tools::isSubmit('processAddress')) $this->processAddress(); if (Tools::isSubmit('processCarrier')) { $this->_updateMessage(Tools::getValue('message')); } // 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(); $cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $this->context->language->id); $this->context->smarty->assign('link_conditions', $this->context->link->getCMSLink($cms, $cms->link_rewrite, (bool)Configuration::get('PS_SSL_ENABLED'))); // 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(); $this->_assignWrappingAndTOS(); // 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, )); } public function postProcess() { // Update carrier selected on preProccess in order to fix a bug of // block cart when it's hooked on leftcolumn if ($this->step == 3 && (Tools::isSubmit('processAddress') || Tools::isSubmit('processCarrier'))) $this->processCarrier(); } public function getAddressesList(){ if (Configuration::get('PS_GUEST_CHECKOUT_ENABLED') == 0 && ((int)$this->context->customer->is_guest != Configuration::get('PS_GUEST_CHECKOUT_ENABLED'))) return; else if (!Customer::getAddressesTotalById($this->context->customer->id)) return; $customer = $this->context->customer; if (Validate::isLoadedObject($customer)) { /* Getting customer addresses */ $customerAddresses = $customer->getAddresses($this->context->language->id); // Getting a list of formated address fields with associated values $formatedAddressFieldsValuesList = array(); foreach ($customerAddresses as $i => $address) { if (!Address::isCountryActiveById((int)($address['id_address']))) unset($customerAddresses[$i]); $tmpAddress = new Address($address['id_address']); $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']); $formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues( $tmpAddress, $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']); unset($tmpAddress); } if (key($customerAddresses) != 0) $customerAddresses = array_values($customerAddresses); if (!count($customerAddresses) && !Tools::isSubmit('ajax')) { $bad_delivery = false; if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) { $back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, array('step' => Tools::getValue('step'), 'multi-shipping' => (int)Tools::getValue('multi-shipping'))); $params = array('multi-shipping' => (int)Tools::getValue('multi-shipping'), 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice), 'back' => $back_url); Tools::redirect($this->context->link->getPageLink('address', true, (int)$this->context->language->id, $params)); } } $result = array( 'addresses' => $customerAddresses, 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList ); return $result; } return false; } public function getCarriersList(){ if (Tools::isSubmit('processAddress')) $this->processAddress(); $this->autoStep(); $this->_assignCarrier(); return $this->smartyOutputContent(_PS_THEME_DIR_.'ajax-order-carrier.tpl'); } /** * Order process controller */ public function autoStep() { if ($this->step > 2 && (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice)){ Tools::redirect('index.php?controller=order&step=1'); } if ($this->step > 2 && !$this->context->cart->isVirtualCart()) { $redirect = false; if (count($this->context->cart->getDeliveryOptionList()) == 0) $redirect = true; $delivery_option = $this->context->cart->getDeliveryOption(); if (is_array($delivery_option)) $carrier = explode(',', $delivery_option[(int)$this->context->cart->id_address_delivery]); if (!$redirect && !$this->context->cart->isMultiAddressDelivery()) foreach ($this->context->cart->getProducts() as $product) { $carrier_list = Carrier::getAvailableCarrierList(new Product($product['id_product']), null, $this->context->cart->id_address_delivery); foreach ($carrier as $id_carrier) { if (!in_array($id_carrier, $carrier_list)) $redirect = true; else { $redirect = false; break; } } if ($redirect) break; } if ($redirect) Tools::redirect('index.php?controller=order&step=2'); } if($this->step > 2) { $delivery = new Address((int)$this->context->cart->id_address_delivery); $invoice = new Address((int)$this->context->cart->id_address_invoice); if ($delivery->deleted || $invoice->deleted) { if ($delivery->deleted) unset($this->context->cart->id_address_delivery); if ($invoice->deleted) unset($this->context->cart->id_address_invoice); Tools::redirect('index.php?controller=order&step=1'); } } } }