public function postProcess() { parent::postProcess(); if (Tools::isSubmit('submitReorder') && ($id_order = (int) Tools::getValue('id_order'))) { $oldCart = new Cart(Order::getCartIdStatic($id_order, $this->context->customer->id)); $duplication = $oldCart->duplicate(); if (!$duplication || !Validate::isLoadedObject($duplication['cart'])) { $this->errors[] = $this->trans('Sorry. We cannot renew your order.', array(), 'Shop.Notifications.Error'); } elseif (!$duplication['success']) { $this->errors[] = $this->trans('Some items are no longer available, and we are unable to renew your order.', array(), 'Shop.Notifications.Error'); } else { $this->context->cookie->id_cart = $duplication['cart']->id; $context = $this->context; $context->cart = $duplication['cart']; CartRule::autoAddToCart($context); $this->context->cookie->write(); Tools::redirect('index.php?controller=order'); } } $this->bootstrap(); }
public static function appendMailTemplateVars($templateVars, $id_lang) { ${"GLOBALS"}["vcrfgjpuyrt"] = "templateVars"; ${"GLOBALS"}["koibsp"] = "sellerinfo"; $isvygtmm = "id_seller"; $khwsjbskxd = "templateVars"; $bastuj = "id_seller"; $vouxjjfmjp = "templateVars"; $rtckuvi = "templateVars"; $mwnpfrbzh = "templateVars"; $kcitojjxqdkw = "templateVars"; ${"GLOBALS"}["ogrtpesu"] = "templateVars"; include_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/SellerInfo.php"; ${"GLOBALS"}["mrjcdvuru"] = "id_sellerinfo"; if (!isset(${$kcitojjxqdkw}["{order_name}"])) { return ${${"GLOBALS"}["vcrfgjpuyrt"]}; } ${"GLOBALS"}["gczbxjeqx"] = "id_order"; ${${"GLOBALS"}["obhowuo"]} = AgileSellerManager::get_order_id_from_maildata(${${"GLOBALS"}["ogrtpesu"]}); if (Module::isInstalled("agilesellershipping")) { $wqmvtkfezgt = "id_order"; ${"GLOBALS"}["ijeihoi"] = "shipping_info"; ${"GLOBALS"}["pfdriwtjveux"] = "module"; $uwbvvypmb = "shipping_info"; $lapbpghjtz = "templateVars"; include_once _PS_ROOT_DIR_ . "/modules/agilesellershipping/agilesellershipping.php"; ${${"GLOBALS"}["pfdriwtjveux"]} = new AgileSellerShipping(); ${${"GLOBALS"}["gpojhlu"]} = Order::getCartIdStatic(${$wqmvtkfezgt}); ${${"GLOBALS"}["wcclsd"]} = new Cart(${${"GLOBALS"}["gpojhlu"]}); ${$uwbvvypmb} = $module->displayInfoByCart(${${"GLOBALS"}["gpojhlu"]}); ${$lapbpghjtz}["{carrier}"] = ${${"GLOBALS"}["ijeihoi"]}; ${${"GLOBALS"}["mmzbulzurq"]}["{total_shipping}"] = Tools::displayPrice($theCart->getOrderTotal(true, Cart::ONLY_SHIPPING)); ${${"GLOBALS"}["mmzbulzurq"]}["{total_paid}"] = Tools::displayPrice($theCart->getOrderTotal(true, Cart::BOTH)); } ${$isvygtmm} = intval(self::getObjectOwnerID("order", ${${"GLOBALS"}["gczbxjeqx"]})); ${${"GLOBALS"}["mrjcdvuru"]} = SellerInfo::getIdBSellerId(${$bastuj}); ${${"GLOBALS"}["qwrpbc"]} = new SellerInfo(${${"GLOBALS"}["qwbylcvmc"]}, ${${"GLOBALS"}["fnpaxtnrne"]}); if (!Validate::isLoadedObject(${${"GLOBALS"}["koibsp"]})) { return ${${"GLOBALS"}["mmzbulzurq"]}; } ${"GLOBALS"}["wjxcrjenr"] = "id_lang"; ${$rtckuvi}["{seller_logo}"] = Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . "img/as/" . $sellerinfo->id . ".jpg"; ${$vouxjjfmjp}["{seller_address}"] = $sellerinfo->fulladdress(${${"GLOBALS"}["wjxcrjenr"]}); ${$mwnpfrbzh}["{seller_name}"] = $sellerinfo->company; return ${$khwsjbskxd}; }
/** * Initialize parent order controller * @see FrontController::init() */ public function init() { $this->isLogged = (bool) ($this->context->customer->id && Customer::customerIdExistsStatic((int) $this->context->cookie->id_customer)); parent::init(); /* Disable some cache related bugs on the cart/order */ header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); $this->nbProducts = $this->context->cart->nbProducts(); if (!$this->context->customer->isLogged(true) && $this->context->getMobileDevice() && Tools::getValue('step')) { Tools::redirect($this->context->link->getPageLink('authentication', true, (int) $this->context->language->id, $params)); } // Redirect to the good order process if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 && Dispatcher::getInstance()->getController() != 'order') { Tools::redirect('index.php?controller=order'); } if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 && Dispatcher::getInstance()->getController() != 'orderopc') { if (isset($_GET['step']) && $_GET['step'] == 3) { Tools::redirect('index.php?controller=order-opc&isPaymentStep=true'); } Tools::redirect('index.php?controller=order-opc'); } 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($id_order, $this->context->customer->id)); $duplication = $oldCart->duplicate(); if (!$duplication || !Validate::isLoadedObject($duplication['cart'])) { $this->errors[] = Tools::displayError('Sorry. We cannot renew your order.'); } else { if (!$duplication['success']) { $this->errors[] = Tools::displayError('Some items are no longer available, and we are unable to renew your order.'); } else { $this->context->cookie->id_cart = $duplication['cart']->id; $this->context->cookie->write(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('index.php?controller=order-opc'); } Tools::redirect('index.php?controller=order'); } } } if ($this->nbProducts) { if (CartRule::isFeatureActive()) { if (Tools::isSubmit('submitAddDiscount')) { if (!($code = trim(Tools::getValue('discount_name')))) { $this->errors[] = Tools::displayError('You must enter a voucher code.'); } elseif (!Validate::isCleanHtml($code)) { $this->errors[] = Tools::displayError('The voucher code is invalid.'); } else { if (($cartRule = new CartRule(CartRule::getIdByCode($code))) && Validate::isLoadedObject($cartRule)) { if ($error = $cartRule->checkValidity($this->context, false, true)) { $this->errors[] = $error; } else { $this->context->cart->addCartRule($cartRule->id); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('index.php?controller=order-opc&addingCartRule=1'); } Tools::redirect('index.php?controller=order&addingCartRule=1'); } } else { $this->errors[] = Tools::displayError('This voucher does not exists.'); } } $this->context->smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($code))); } elseif (($id_cart_rule = (int) Tools::getValue('deleteDiscount')) && Validate::isUnsignedId($id_cart_rule)) { $this->context->cart->removeCartRule($id_cart_rule); Tools::redirect('index.php?controller=order-opc'); } } /* Is there only virtual product in cart */ if ($isVirtualCart = $this->context->cart->isVirtualCart()) { $this->setNoCarrier(); } } $this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); }
public function preProcess() { global $isVirtualCart; parent::preProcess(); // Redirect to the good order process if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 and strpos($_SERVER['PHP_SELF'], 'order.php') === false) { Tools::redirect('order.php'); } if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 and strpos($_SERVER['PHP_SELF'], 'order-opc.php') === false) { if (isset($_GET['step']) and $_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') and $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 or !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 renew your order'); } else { self::$cookie->id_cart = $duplication['cart']->id; self::$cookie->write(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('order-opc.php'); } Tools::redirect('order.php'); } } if ($this->nbProducts) { if (Tools::isSubmit('submitAddDiscount') and 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); Tools::redirect('order-opc.php'); } } self::$smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName))); } elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) { self::$cart->deleteDiscount((int) $_GET['deleteDiscount']); Tools::redirect('order-opc.php'); } /* Is there only virtual product in cart */ if ($isVirtualCart = self::$cart->isVirtualCart()) { $this->_setNoCarrier(); } } self::$smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); }
public static function appendMailTemplateVars($templateVars, $id_lang) { ${"GLOBALS"}["lpylolnr"] = "templateVars"; $ildhukdeocf = "id_order"; include_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/SellerInfo.php"; if (!isset(${${"GLOBALS"}["qeihure"]}["{order_name}"])) { return ${${"GLOBALS"}["lpylolnr"]}; } ${${"GLOBALS"}["onrihdtohmy"]} = AgileSellerManager::get_order_id_from_maildata(${${"GLOBALS"}["qeihure"]}); ${"GLOBALS"}["idkcttosxt"] = "id_sellerinfo"; $wnrfjewz = "templateVars"; ${"GLOBALS"}["qdtkkl"] = "templateVars"; if (Module::isInstalled("agilesellershipping")) { $uetwqe = "id_cart"; ${"GLOBALS"}["ydqcgliu"] = "id_cart"; include_once _PS_ROOT_DIR_ . "/modules/agilesellershipping/agilesellershipping.php"; ${${"GLOBALS"}["hxocupnzcmnc"]} = new AgileSellerShipping(); $lrenpohbp = "id_cart"; $jmkylvqmc = "id_order"; ${${"GLOBALS"}["ydqcgliu"]} = Order::getCartIdStatic(${$jmkylvqmc}); ${${"GLOBALS"}["ngtdqmicwms"]} = new Cart(${$lrenpohbp}); ${${"GLOBALS"}["tvdvxtyqyoc"]} = $module->displayInfoByCart(${$uetwqe}); ${${"GLOBALS"}["qeihure"]}["{carrier}"] = ${${"GLOBALS"}["tvdvxtyqyoc"]}; $dttltvoe = "templateVars"; ${${"GLOBALS"}["qeihure"]}["{total_shipping}"] = Tools::displayPrice($theCart->getOrderTotal(true, Cart::ONLY_SHIPPING)); ${$dttltvoe}["{total_paid}"] = Tools::displayPrice($theCart->getOrderTotal(true, Cart::BOTH)); } ${"GLOBALS"}["cugpmokiair"] = "id_seller"; ${${"GLOBALS"}["cugpmokiair"]} = intval(self::getObjectOwnerID("order", ${$ildhukdeocf})); ${"GLOBALS"}["pncxlnvlp"] = "id_sellerinfo"; ${${"GLOBALS"}["idkcttosxt"]} = SellerInfo::getIdBSellerId(${${"GLOBALS"}["pbiyrsaos"]}); $uwckuubvuvi = "templateVars"; ${${"GLOBALS"}["qoouzqshac"]} = new SellerInfo(${${"GLOBALS"}["pncxlnvlp"]}, ${${"GLOBALS"}["menljubw"]}); if (!Validate::isLoadedObject(${${"GLOBALS"}["qoouzqshac"]})) { return ${${"GLOBALS"}["qeihure"]}; } ${$wnrfjewz}["{seller_logo}"] = Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . "img/as/" . $sellerinfo->id . ".jpg"; ${${"GLOBALS"}["qdtkkl"]}["{seller_address}"] = $sellerinfo->fulladdress(${${"GLOBALS"}["menljubw"]}); ${$uwckuubvuvi}["{seller_name}"] = $sellerinfo->company; return ${${"GLOBALS"}["qeihure"]}; }
public static function appendMailTemplateVars($templateVars, $id_lang) { $srsiruwobuv = "templateVars"; ${"GLOBALS"}["ssvrfqcid"] = "templateVars"; $gbmmhekbxpl = "templateVars"; include_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/SellerInfo.php"; if (!isset(${$srsiruwobuv}["{order_name}"])) { return ${${"GLOBALS"}["ssvrfqcid"]}; } ${${"GLOBALS"}["fcndxqdqabb"]} = AgileSellerManager::get_order_id_from_maildata(${$gbmmhekbxpl}); ${"GLOBALS"}["eqfybrvrw"] = "sellerinfo"; $sqoorpcij = "templateVars"; if (Module::isInstalled("agilesellershipping")) { $serwpmzyvy = "id_cart"; ${"GLOBALS"}["wsvfdbs"] = "id_cart"; ${"GLOBALS"}["yrkkwwacp"] = "module"; $aztngqymy = "id_cart"; include_once _PS_ROOT_DIR_ . "/modules/agilesellershipping/agilesellershipping.php"; ${${"GLOBALS"}["yrkkwwacp"]} = new AgileSellerShipping(); $zmifvyyg = "theCart"; ${${"GLOBALS"}["wsvfdbs"]} = Order::getCartIdStatic(${${"GLOBALS"}["fcndxqdqabb"]}); ${$zmifvyyg} = new Cart(${$serwpmzyvy}); $tethjnr = "shipping_info"; ${$tethjnr} = $module->displayInfoByCart(${$aztngqymy}); ${"GLOBALS"}["qsvjrq"] = "shipping_info"; $gkynzrky = "templateVars"; ${$gkynzrky}["{carrier}"] = ${${"GLOBALS"}["qsvjrq"]}; ${${"GLOBALS"}["fqdwpgrnipa"]}["{total_shipping}"] = Tools::displayPrice($theCart->getOrderTotal(true, Cart::ONLY_SHIPPING)); ${${"GLOBALS"}["fqdwpgrnipa"]}["{total_paid}"] = Tools::displayPrice($theCart->getOrderTotal(true, Cart::BOTH)); } ${${"GLOBALS"}["ghjbfbenq"]} = intval(self::getObjectOwnerID("order", ${${"GLOBALS"}["fcndxqdqabb"]})); ${"GLOBALS"}["fyetkbysysdd"] = "templateVars"; ${${"GLOBALS"}["ytlkgn"]} = SellerInfo::getIdBSellerId(${${"GLOBALS"}["ghjbfbenq"]}); ${${"GLOBALS"}["fgxqhdsi"]} = new SellerInfo(${${"GLOBALS"}["ytlkgn"]}, ${${"GLOBALS"}["vhbieui"]}); if (!Validate::isLoadedObject(${${"GLOBALS"}["eqfybrvrw"]})) { return ${${"GLOBALS"}["fqdwpgrnipa"]}; } ${$sqoorpcij}["{seller_logo}"] = Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . "img/as/" . $sellerinfo->id . ".jpg"; ${${"GLOBALS"}["fyetkbysysdd"]}["{seller_address}"] = $sellerinfo->fulladdress(${${"GLOBALS"}["vhbieui"]}); ${${"GLOBALS"}["fqdwpgrnipa"]}["{seller_name}"] = $sellerinfo->company; return ${${"GLOBALS"}["fqdwpgrnipa"]}; }
public static function appendMailTemplateVars($templateVars, $id_lang) { include_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/SellerInfo.php"; if (!isset($templateVars['{order_name}'])) { return $templateVars; } $id_order = AgileSellerManager::get_order_id_from_maildata($templateVars); if (Module::isInstalled('agilesellershipping')) { include_once _PS_ROOT_DIR_ . "/modules/agilesellershipping/agilesellershipping.php"; $module = new AgileSellerShipping(); $id_cart = Order::getCartIdStatic($id_order); $theCart = new Cart($id_cart); $shipping_info = $module->displayInfoByCart($id_cart); $templateVars['{carrier}'] = $shipping_info; $templateVars['{total_shipping}'] = Tools::displayPrice($theCart->getOrderTotal(true, Cart::ONLY_SHIPPING)); $templateVars['{total_paid}'] = Tools::displayPrice($theCart->getOrderTotal(true, Cart::BOTH)); } $id_seller = intval(self::getObjectOwnerID('order', $id_order)); $id_sellerinfo = SellerInfo::getIdBSellerId($id_seller); $sellerinfo = new SellerInfo($id_sellerinfo, $id_lang); if (!Validate::isLoadedObject($sellerinfo)) { return $templateVars; } $templateVars['{seller_logo}'] = Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'img/as/' . $sellerinfo->id . '.jpg'; $templateVars['{seller_address}'] = $sellerinfo->fulladdress($id_lang); $templateVars['{seller_name}'] = $sellerinfo->company; return $templateVars; }
public function preProcess() { global $isVirtualCart, $cookie; parent::preProcess(); // Redirect to the good order process if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 and (strpos($_SERVER['PHP_SELF'], 'order.php') === false and strpos($_SERVER['PHP_SELF'], 'cart-summary-large.php') === false)) { Tools::redirect('order.php'); } if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 and strpos($_SERVER['PHP_SELF'], 'order-opc.php') === false) { if (isset($_GET['step']) and $_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') and $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 or !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 (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('order-opc.php'); } Tools::redirect('order.php'); } } if (Tools::isSubmit('submit_instructions')) { $instructions = Tools::getValue('special_instructions'); self::$cart->gift_message = pSQL($instructions); self::$cart->update(); Tools::redirect('order?step=3'); } if ($this->nbProducts) { /* check discount validity */ $cartDiscounts = self::$cart->getDiscounts(); $discountInvalid = false; foreach ($cartDiscounts as $k => $cartDiscount) { if ($error = self::$cart->checkDiscountValidity(new Discount((int) $cartDiscount['id_discount']), $cartDiscounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING), self::$cart->getProducts())) { self::$cart->deleteDiscount((int) $cartDiscount['id_discount']); $discountInvalid = true; } } if ($discountInvalid) { Tools::redirect('order-opc.php'); } if (Tools::getValue('redeem_points')) { $points = (int) Tools::getValue('redeem_points'); if ($points < 1) { self::$smarty->assign('redeem_points', $points); $this->errors[] = Tools::displayError('You can redeem minimum of 1 coin in an order.'); } $orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $redemption_status = VBRewards::checkPointsValidity($cookie->id_customer, $points + self::$cart->getPoints(), $orderTotal); if ($redemption_status === CAN_REDEEM_COINS) { self::$cart->addPoints($points); self::$smarty->assign('redeem_points', (int) self::$cart->getPoints()); } else { if ($redemption_status === INSUFFICIENT_VALID_ORDERS) { $this->errors[] = Tools::displayError('Coins can be redeemed from second purchase onwards.'); } else { if ($redemption_status === MIN_CRITERIA_NOT_MET) { $this->errors[] = Tools::displayError('Order value should be more than 100 USD to redeem coins'); } } } $this->adjustPoints(); } elseif (Tools::getValue('deletePoints')) { self::$cart->deletePoints(); } if (Tools::isSubmit('submitAddDiscount') and 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); Tools::redirect('order-opc.php'); } } self::$smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName))); $this->adjustPoints(); } elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) { self::$cart->deleteDiscount((int) $_GET['deleteDiscount']); Tools::redirect('order-opc.php'); } /* Is there only virtual product in cart */ if ($isVirtualCart = self::$cart->isVirtualCart()) { $this->_setNoCarrier(); } } //if enough stock, show free gift message $free_products = array(66254, 66255, 66256); $sql = "select quantity from ps_product where id_product in (" . implode(",", $free_products) . ")"; $result = Db::getInstance()->ExecuteS($sql); $free_gift_stock = $has_free_gift = false; foreach ($result as $row) { if (intval($row['quantity']) > 0) { $free_gift_stock = true; break; } } $total_products_wt = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $cv = Tools::convertPrice($total_products_wt, (int) self::$cookie->id_currency, false); /*if( $cv > 50) { if( $free_gift_stock ) { $cart_products = self::$cart->getProducts(); foreach($cart_products as $cproduct) { $id_product = $cproduct['id_product']; if( in_array($id_product, $free_products )) { $has_free_gift = true; break; } } } if( !$has_free_gift && $free_gift_stock ) { self::$smarty->assign("spl_voucher_message","Here is the free <a href='/1222-free-gifts'>gift product</a> for you.Valid still stock lasts. Read <a href='/content/30-womens-day-special-discount'>T&C</a> here"); } } else { $free_products = array(66254, 66255, 66256); foreach($free_products as $p) self::$cart->deleteProduct($p); self::$smarty->assign("spl_voucher_message","We have a free <a href='/1222-free-gifts'>gift product</a> for you if the shopping cart value is atleast USD 50."); } self::$smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); if (self::$cart->gift_message) { self::$smarty->assign('cart_instructions', 1); self::$smarty->assign('special_instructions', self::$cart->gift_message); }*/ //buy1 get 1 $products = self::$cart->getProducts(true); $offeredProducts = 0; // this is a very interesting array, keeps as many rows as there are items in your cart // if there is an item with quantity 2, it will have two rows in that array, // ie item will have as many rows as the quantity of the item in cart. $offerproducts = array(); foreach ($products as $product) { $productObj = new Product($product['id_product'], true); $tags = $productObj->getTags(1); //print_r($productObj); if (in_array('buy1get1', $tags)) { self::$smarty->assign("spl_voucher_message", "You are eligible for Buy 1 Get 1 Offer"); //counting the b1g1 products $offeredProducts = $offeredProducts + $product['cart_quantity']; } else { if (in_array('buy2get3', $tags)) { self::$smarty->assign("spl_voucher_message", "You are eligible for buy 3 pay for 2 offer"); //counting the b1g1 products $offeredProducts = $offeredProducts + $product['cart_quantity']; } } //adding rows to interesting array $b1g1products for ($q = 0; $q < $product['cart_quantity']; $q++) { array_push($offerproducts, $product); } } //sorting products in ascending order of price usort($offerproducts, function ($prod1, $prod2) { return $prod1['price'] - $prod2['price']; }); ///echo "<pre>";print_r($offerproducts); if (in_array('buy1get1', $tags)) { $noOfferedAdvantageAvailable = (int) ($offeredProducts / 2); } elseif (in_array('buy2get3', $tags)) { $noOfferedAdvantageAvailable = (int) ($offeredProducts / 3); } $discount = 0; for ($p = 0; $p < $noOfferedAdvantageAvailable; $p++) { //print_r("offerproducts".$offerproducts[$p]['price']); $discount = $discount + $offerproducts[$p]['price']; //print_r($discount); } if ((int) self::$cart->id_currency != 2) { $discount = Tools::convertPrice($discount, (int) self::$cart->id_currency, false); } $discount = round($discount, 2); $b1g1DiscountInCart = null; $b2g3DiscountInCart = null; $allCartDiscounts = self::$cart->getDiscounts(); //print_r($allCartDiscounts); foreach ($allCartDiscounts as $cartDiscount) { if (strpos($cartDiscount['name'], 'B1G1') === 0) { $b1g1DiscountInCart = new Discount((int) Discount::getIdByName($cartDiscount['name'])); //echo "buy1get1"; } else { if (strpos($cartDiscount['name'], 'B2G3') === 0) { $b2g3DiscountInCart = new Discount((int) Discount::getIdByName($cartDiscount['name'])); //echo "buy2get3"; } } } if (in_array('buy1get1', $tags)) { if ($discount > 0 && empty($b1g1DiscountInCart)) { $new_discount = new Discount(); $new_discount->id_discount_type = 2; $new_discount->value = $discount; // coupon value $new_discount->name = "B1G1" . Tools::rand_string(5); $new_discount->id_currency = 2; $new_discount->quantity = 1; $new_discount->quantity_per_user = 0; $new_discount->date_from = date('Y-m-d H:i:s'); $new_discount->date_to = '2015-08-10 20:00:00'; //validity $new_discount->cumulable_reduction = 1; $languages = Language::getLanguages(); foreach ($languages as $language) { $new_discount->description[$language['id_lang']] = "Buy1 Get1"; } // coupon description $new_discount->add(); $id_discount = Discount::getIdByName($new_discount->name); self::$cart->addDiscount($id_discount); } else { if (!empty($b1g1DiscountInCart)) { $b1g1DiscountInCart->value = (double) $discount; // coupon value if ($b1g1DiscountInCart->value > 0) { $b1g1DiscountInCart->update(); } else { $b1g1DiscountInCart->delete(); } } } } else { if (in_array('buy2get3', $tags)) { if ($discount > 0 && empty($b2g3DiscountInCart)) { $new_discount = new Discount(); $new_discount->id_discount_type = 2; $new_discount->value = $discount; // coupon value $new_discount->name = "B2G3" . Tools::rand_string(5); $new_discount->id_currency = 2; $new_discount->quantity = 1; $new_discount->quantity_per_user = 0; $new_discount->date_from = date('Y-m-d H:i:s'); $new_discount->date_to = '2015-08-10 20:00:00'; //validity $new_discount->cumulable_reduction = 1; $languages = Language::getLanguages(); foreach ($languages as $language) { $new_discount->description[$language['id_lang']] = "Buy2 Get3"; } // coupon description $new_discount->add(); $id_discount = Discount::getIdByName($new_discount->name); self::$cart->addDiscount($id_discount); } else { if (!empty($b2g3DiscountInCart)) { $b2g3DiscountInCart->value = (double) $discount; // coupon value if ($b2g3DiscountInCart->value > 0) { $b2g3DiscountInCart->update(); } else { $b2g3DiscountInCart->delete(); } } } } } /*//pick3pay2 $products = self::$cart->getProducts(true); //print_r($products); $nP3P2Products = 0; // this is a very interesting array, keeps as many rows as there are items in your cart // if there is an item with quantity 2, it will have two rows in that array, // ie item will have as many rows as the quantity of the item in cart. $p3p2products = array(); foreach($products as $product) { $productObj = new Product($product['id_product'], true); $tags = $productObj->getTags(1); if(in_array('pick3pay2', $tags)){ self::$smarty->assign("spl_voucher_message", "Pick 3 and Pay for 2 only offer"); $nP3P2Products = $nP3P2Products + $product['cart_quantity']; for($q = 0; $q < $product['cart_quantity']; $q++){ array_push($p3p2products, $product); } } } //sorting products in ascending order of price usort($p3p2products, function($prod1, $prod2){ return $prod1['price'] - $prod2['price']; }); $noP3P2AdvantageAvailable = (int)($nP3P2Products/3); print_r($noP3P2AdvantageAvailable); $discount = 0; for($p = 0; $p < $noP3P2AdvantageAvailable; $p++){ $discount = $discount + $p3p2products[$p]['price']; } if((int)self::$cart->id_currency != 2){ $discount = Tools::convertPrice($discount, (int)self::$cart->id_currency, false); } $discount = round($discount, 2); $p3p2DiscountInCart = null; $allCartDiscounts = self::$cart->getDiscounts(); foreach ($allCartDiscounts as $cartDiscount) { //print_r($cartDiscount);print_r('<br/>');die; if(strpos('P3P2', $cartDiscount['name']) == 0){ $p3p2DiscountInCart = new Discount((int) (Discount::getIdByName($cartDiscount['name']))); } } if($discount > 0 && empty($p3p2DiscountInCart)){ $new_discount = new Discount(); $new_discount->id_discount_type = 2; $new_discount->value = $discount; // coupon value $new_discount->name = "P3P2" . Tools::rand_string(5); $new_discount->id_currency = 2; $new_discount->quantity = 1; $new_discount->quantity_per_user = 100; $new_discount->date_from = date('Y-m-d H:i:s'); $new_discount->date_to = '2015-09-10 20:00:00'; //validity $new_discount->cumulable_reduction = 1; $languages = Language::getLanguages(); foreach ($languages as $language) $new_discount->description[$language['id_lang']] = "Pick3 Pay2"; // coupon description $new_discount->add(); $id_discount = Discount::getIdByName($new_discount->name); print_r($id_discount); self::$cart->addDiscount($id_discount); }else if(!empty($p3p2DiscountInCart)){ $p3p2DiscountInCart->value = (float) $discount; // coupon value if($p3p2DiscountInCart->value > 0) $p3p2DiscountInCart->update(); else $p3p2DiscountInCart->delete(); }*/ }
function refillCart($orderId) { if (!$orderId) { return false; } $oldCart = new Cart(Order::getCartIdStatic($orderId, $this->context->customer->id)); $duplication = $oldCart->duplicate(); if (!$duplication || !Validate::isLoadedObject($duplication['cart'])) { //$this->errors[] = Tools::displayError('Sorry. We cannot renew your order.'); return false; } elseif (!$duplication['success']) { //$this->errors[] = Tools::displayError('Some items are no longer available, and we are unable to renew your order.'); return false; } else { $this->context->cookie->id_cart = $duplication['cart']->id; $context = $this->context; $context->cart = $duplication['cart']; CartRule::autoAddToCart($context); $this->context->cookie->write(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { //Tools::redirect('index.php?controller=order-opc'); } //Tools::redirect('index.php?controller=order'); return true; } }
protected function getOrder() { $id_order = false; if (!is_numeric($reference = Tools::getValue('id_order'))) { $reference = ltrim($reference, '#'); $orders = Order::getByReference($reference); if ($orders) { foreach ($orders as $order) { $id_order = (int) $order->id; break; } } } elseif (Order::getCartIdStatic((int) Tools::getValue('id_order'))) { $id_order = (int) Tools::getValue('id_order'); } return (int) $id_order; }