step == 0 && !Tools::getValue('ajax') && Module::isInstalled('privatesales_delay')) { // assign delay to Products if (!class_exists('SaleDelay')) { require_once dirname(__FILE__).'/../../modules/privatesales_delay/saledelay.php'; } $products_delay = SaleDelay::associateDelay(self::$cart->getProducts()); $delays = array_keys($products_delay); $date = new DateTime(); $delivery_date = SaleDelay::getDeliveryDate($delays, null, $date, true); self::$smarty->assign(array( 'delivery_date' => (!empty($delivery_date)?$delivery_date:null), )); } if($this->step == 2 && !Tools::getValue('ajax')){ // Bloque les canaries ES $delivery = new Address(self::$cart->id_address_delivery); $prefix_postcode = substr($delivery->postcode, 0 ,2); if ($delivery->id_country == 6 && (intval($prefix_postcode) == 35 || intval($prefix_postcode) == 38) ) { //$this->errors[] = Tools::displayError('Lo sentimos, en estos momentos no distribuimos nuestros productos en Canarias. Si deseas más información, puedes contactar con el Servicio de atención al cliente o llamar al 902 044 399.'); $this->step = 1; Tools::redirect('order.php?step=1&canaries=1'); } // bloque DOM-TOM $prefix_postcode = substr($delivery->postcode, 0 ,3); $domtom = array(971,972,973,974,975,976,984,986,987,988); if ($delivery->id_country == 8 && (in_array(intval($prefix_postcode),$domtom)) ) { //$this->errors[] = Tools::displayError('Nous sommes désolé, nous ne livrons pas dans le DOM-TOM'); $this->step = 1; Tools::redirect('order.php?step=1&domtom=1'); } } if(Module::isInstalled('privatesales')) { $removed = FALSE; $products_only_fr = array(); foreach(self::$cart->getProducts() as $product) { if(($sale = Sale::getSaleFromCategory($product['id_category_default'])) !== NULL) { if($sale->isFinished() || !$sale->enabled) { self::$cart->deleteProduct($product['id_product'], $product['id_product_attribute'], $product['id_customization']); $removed = TRUE; } } // shipping only in france if($sale->shipping_fr == 1) { // $link = new Link(); $products_only_fr[] = array( 'name' => $product['name'].' - '.$sale->title[(int)self::$cart->id_lang], //'link' => $link->getProductLink((int)$product['id_product'], $product['link_rewrite'], $product['category'], $product['ean13']) ); } } if (!empty($products_only_fr)) { self::$smarty->assign('products_fr',$products_only_fr); if ($this->step == 2) { $delivery = new Address(self::$cart->id_address_delivery); if ($delivery->id_country != 8 && !Tools::getValue('ajax')) { $this->step = 1; Tools::redirect('order.php?step=1&onlyfr=1'); } } } if($removed === TRUE) { self::$smarty->assign(array( 'products_removed' => TRUE, )); $this->nbProducts = self::$cart->nbProducts(); } if(!$this->nbProducts) { $this->step = -1; } } global $page_name; if(!isset($this->php_self)) { $this->php_self = strtolower(basename($_SERVER['PHP_SELF'])); } if($this->php_self == '404.php') { $page_name = 'page-404'; } else { if(preg_match('#^'.__PS_BASE_URI__.'modules/([a-zA-Z0-9_-]+?)/([^?]*)(\?(.*))?$#', strtolower($_SERVER['REQUEST_URI']), $m)) { $page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]); } else { $page_name = preg_replace('/\.php$/', '', $this->php_self); } } self::$smarty->assign(array('page_name' => $page_name)); $displayLeft = array( 'page-404', 'address', 'addresses', 'authentication', 'best-sales', 'breadcrumb', 'category', 'category-cms-tree-branch', 'category-tree-branch', 'cms', 'contact-form', 'discount', 'errors', 'footer', 'guest-tracking', 'header', 'history', 'identity', 'index', 'maintenance', 'manufacturer', 'manufacturer-list', 'my-account', 'new-products', 'order', 'order-address', 'order-carrier', 'order-confirmation', 'order-detail', 'order-follow', 'order-opc', 'order-opc-new-account', 'order-payment', 'order-return', 'order-slip', 'order-steps', 'pagination', 'password', 'payment', 'prices-drop', 'product', 'product-compare', 'product-list', 'products-comparison', 'product-sort', 'restricted-country', 'scenes', 'search', 'shopping-cart', 'shopping-cart-product-line', 'sitemap', 'store_infos', 'stores', 'supplier', 'supplier-list', 'module-privatesales-salechange', 'module-invite-invite-program', 'module-referralprogram-referral-program', 'module-cheque-payment', 'module-bankwire-payment', 'module-invite-invite-rules', ); $displayRight = array( 'page-404', 'address', 'addresses', 'authentication', 'best-sales', 'breadcrumb', 'category', 'category-cms-tree-branch', 'category-tree-branch', 'cms', 'contact-form', 'discount', 'errors', 'footer', 'guest-tracking', 'header', 'history', 'identity', 'index', 'maintenance', 'manufacturer', 'manufacturer-list', 'my-account', 'new-products', 'order', 'order-address', 'order-carrier', 'order-confirmation', 'order-detail', 'order-follow', 'order-opc', 'order-opc-new-account', 'order-payment', 'order-return', 'order-slip', 'order-steps', 'pagination', 'password', 'payment', 'prices-drop', 'product', 'product-compare', 'product-list', 'products-comparison', 'product-sort', 'restricted-country', 'scenes', 'search', 'shopping-cart', 'shopping-cart-product-line', 'sitemap', 'store_infos', 'stores', 'supplier', 'supplier-list', 'module-privatesales-salechange', 'module-invite-invite-program', 'module-referralprogram-referral-program', 'module-cheque-payment', 'module-bankwire-payment', 'module-invite-invite-rules', ); $countCols = count(array_keys($displayLeft + $displayRight, $page_name)); $bodyClass = 'singleCol'; if($countCols == 1) { $bodyClass = 'doubleCol'; } elseif($countCols == 2) { $bodyClass = 'tripleCol'; } self::$smarty->assign(array( 'displayLeft' => $displayLeft, 'displayRight' => $displayRight, 'bodyClass' => $bodyClass, )); Module::hookExec('preprocess'); // Redirect to the good order process $order_process_type = Configuration::get('PS_ORDER_PROCESS_TYPE'); if($order_process_type == 0 && strpos($_SERVER['PHP_SELF'], 'order.php') === FALSE) { Tools::redirect('order.php'); } if($order_process_type == 1 && strpos($_SERVER['PHP_SELF'], 'order-opc.php') === FALSE) { if(isset($_GET['step']) && $_GET['step'] == 3) { Tools::redirect('order-opc.php?isPaymentStep=true'); } Tools::redirect('order-opc.php'); } if(Configuration::get('PS_CATALOG_MODE')) { $this->errors[] = Tools::displayError('This store has not accepted your new order.'); } if(Tools::isSubmit('submitReorder') && $id_order = (int) Tools::getValue('id_order')) { $oldCart = new Cart(Order::getCartIdStatic((int) $id_order, (int) self::$cookie->id_customer)); $duplication = $oldCart->duplicate(); if(!$duplication || !Validate::isLoadedObject($duplication['cart'])) { $this->errors[] = Tools::displayError('Sorry, we cannot renew your order.'); } elseif (!$duplication['success']) { $this->errors[] = Tools::displayError('Missing items - we are unable to renew your order'); } else { self::$cookie->id_cart = $duplication['cart']->id; self::$cookie->write(); if($order_process_type == 1) { Tools::redirect('order-opc.php'); } Tools::redirect('order.php'); } } if($this->nbProducts) { if(Tools::isSubmit('submitAddDiscount') && Tools::getValue('discount_name')) { $discountName = Tools::getValue('discount_name'); if(!Validate::isDiscountName($discountName)) { $this->errors[] = Tools::displayError('Voucher name invalid.'); } else { $discount = new Discount((int)(Discount::getIdByName($discountName))); if(Validate::isLoadedObject($discount)) { if($tmpError = self::$cart->checkDiscountValidity($discount, self::$cart->getDiscounts(), self::$cart->getOrderTotal(), self::$cart->getProducts(), TRUE)) { $this->errors[] = $tmpError; } } else { $this->errors[] = Tools::displayError('Voucher name invalid.'); } if(!sizeof($this->errors)) { self::$cart->addDiscount((int)($discount->id)); if($order_process_type == 1) { Tools::redirect('order-opc.php'); } Tools::redirect('order.php'); } } self::$smarty->assign(array( 'errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName) )); } elseif(isset($_GET['deleteDiscount']) && Validate::isUnsignedId($_GET['deleteDiscount'])) { self::$cart->deleteDiscount((int) $_GET['deleteDiscount']); if($order_process_type == 1) { Tools::redirect('order-opc.php'); } Tools::redirect('order.php'); } /* Is there only virtual product in cart */ if($isVirtualCart = self::$cart->isVirtualCart()) { $this->_setNoCarrier(); } } self::$smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); /* If some products have disappear */ $cart_quantities = self::$cart->checkQuantitiesDetails(); if($cart_quantities !== TRUE) { $this->step = 0; $this->errors[] = Tools::displayError('An item in your cart is no longer available for this quantity, you cannot proceed with your order.').'
'.Tools::displayError('Concerned item:').' '.$cart_quantities['name']; } /* Check minimal amount */ $currency = Currency::getCurrency((int) self::$cart->id_currency); $orderTotal = self::$cart->getOrderTotal(); $minimalPurchase = Tools::convertPrice((float) Configuration::get('PS_PURCHASE_MINIMUM'), $currency); if(self::$cart->getOrderTotal(FALSE, Cart::ONLY_PRODUCTS) < $minimalPurchase && $this->step != -1) { $this->step = 0; $this->errors[] = Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency). ' '.Tools::displayError('is required in order to validate your order.'); } if (!self::$cookie->isLogged(TRUE) && in_array($this->step, array(1, 2, 3))) { Tools::redirect('authentication.php?back='.urlencode('order.php?step='.$this->step)); } if($this->nbProducts) { self::$smarty->assign('virtual_cart', $isVirtualCart); } // 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('processCarrier')) { $this->processCarrier(); } } /* * Manage address */ public function processAddress() { if (!Tools::isSubmit('id_address_delivery') OR !Address::isCountryActiveById((int)Tools::getValue('id_address_delivery'))) $this->errors[] = Tools::displayError('This address is not in a valid area.'); else { self::$cart->id_address_delivery = (int)(Tools::getValue('id_address_delivery')); self::$cart->id_address_invoice = Tools::isSubmit('same') ? self::$cart->id_address_delivery : (int)(Tools::getValue('id_address_invoice')); if (!self::$cart->update()) $this->errors[] = Tools::displayError('An error occurred while updating your cart.'); if (Tools::isSubmit('message')) $this->_updateMessage(Tools::getValue('message')); if (Tools::getValue('ajax')) { // Bloque les canaries ES $delivery = new Address(self::$cart->id_address_delivery); $prefix_postcode = substr($delivery->postcode, 0 ,2); if ($delivery->id_country == 6 && (intval($prefix_postcode) == 35 || intval($prefix_postcode) == 38) ) { $this->errors[] = Tools::displayError('Lo sentimos, en estos momentos no distribuimos nuestros productos en Canarias. Si deseas más información, puedes contactar con el Servicio de atención al cliente o llamar al 902 044 399.'); } // bloque DOM-TOM $prefix_postcode = substr($delivery->postcode, 0 ,3); $domtom = array(971,972,973,974,975,976,984,986,987,988); if ($delivery->id_country == 8 && (in_array(intval($prefix_postcode),$domtom)) ) { $this->errors[] = Tools::displayError('Nous sommes désolé, nous ne livrons pas dans le DOM-TOM'); } } } if (sizeof($this->errors)) { if (Tools::getValue('ajax')) die('{"hasError" : true, "errors" : ["'.implode('\',\'', $this->errors).'"]}'); $this->step = 1; } if (Tools::getValue('ajax')) die(true); } }