/** * Do whatever you have to before redirecting the customer on the website of your payment processor. */ public function postProcess() { /** * Oops, an error occured. */ if (Tools::getValue('action') == 'error') { return $this->displayError('An error occurred while trying to redirect the customer'); } else { //First solution to know if refreshed page: http://stackoverflow.com/a/6127748 $refreshButtonPressed = isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0'; $result = $this->module->callToRest('GET', '/orders?mid=' . Context::getContext()->cart->id, null, false); $result['response'] = json_decode($result['response'], true); if ($result['code'] == '200' && isset($result['response']['results'][0]['id']) && !$refreshButtonPressed) { //The cart exists on Aplazame, we try to send with another ID $oldCart = new Cart(Context::getContext()->cart->id); $data = $oldCart->duplicate(); if ($data['success']) { $cart = $data['cart']; Context::getContext()->cart = $cart; CartRule::autoAddToCart(Context::getContext()); Context::getContext()->cookie->id_cart = $cart->id; } else { $this->module->logError('Error: Cannot duplicate cart ' . Context::getContext()->cart->id); } } $this->context->smarty->assign(array('cart_id' => Context::getContext()->cart->id, 'secure_key' => Context::getContext()->customer->secure_key, 'aplazame_order_json' => json_encode($this->module->getCheckoutSerializer(0, Context::getContext()->cart->id), 128), 'aplazame_version' => ConfigurationCore::get('APLAZAME_API_VERSION', null), 'aplazame_url' => Configuration::get('APLAZAME_API_URL', null), 'aplazame_mode' => Configuration::get('APLAZAME_LIVE_MODE', null) ? 'false' : 'true')); return $this->setTemplate('redirect.tpl'); } }
private function duplicateCart(Cart $oldCart) { $data = $oldCart->duplicate(); if (!$data || !$data['success']) { $this->module->log(Aplazame::LOG_WARNING, 'Cannot duplicate cart', $oldCart->id); return $oldCart; } $cart = $data['cart']; $this->context->cookie->id_cart = $cart->id; $this->context->cart = $cart; CartRule::autoAddToCart($this->context); $this->context->cookie->write(); return $cart; }
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(); }
/** * 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 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; } }
if (in_array($txn_type, $recurring_txn_types)) { if ((!isset($_POST['subscr_id']) or empty($_POST['subscr_id'])) and isset($_POST['recurring_payment_id']) and !empty($_POST['recurring_payment_id'])) { $_POST['subscr_id'] = $_POST['recurring_payment_id']; } if (!isset($_POST['subscr_id']) or empty($_POST['subscr_id'])) { die('subscriber id invalid'); } $recs_total = AgilePaypalTxn::search($_POST['subscr_id']); if (count($recs_total) > 0) { $recs_this_txn = AgilePaypalTxn::search($_POST['subscr_id'], $_POST['txn_id']); if (count($recs_this_txn) > 0) { die('transaction processed before'); } $foundrec = array_shift($recs_total); $oldCart = new Cart((int) $foundrec['id_cart']); $duplicated = $oldCart->duplicate(); $newCart = $duplicated['cart']; if (!isset($newCart)) { die($paypal->getL('Error copying cart: (Error occured when copying cart for recurring payment)')); } if (Agile_Logging == 'on') { $paypal->log_message("recs_total:{$recs_total} recs_this_txn:{$recs_this_txn} old_cart_id:" . (isset($_POST['custom']) ? $_POST['custom'] : '') . " new_cart_id:" . $newCart->id); } $_POST['custom'] = $newCart->id; } } $oldcart = new Cart(intval($_POST['custom'])); $customer = new Customer(intval($oldcart->id_customer)); if (!Validate::isLoadedObject($customer)) { $customer->getByEmail($_POST['payer_email']); }
public static function duplicateCart() { $hipay = new HiPay_Tpp(); // Taken from controllers\front\ParentOrderController.php , keyword "submitReorder" /* 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'); $errors = array(); $context = Context::getContext(); //$oldCart = new Cart(Order::getCartIdStatic($context->cookie->id_cart, $context->customer->id)); $oldCart = new Cart($context->cookie->id_cart); $duplication = $oldCart->duplicate(); if (!$duplication || !Validate::isLoadedObject($duplication['cart'])) { $errors[] = $hipay->l('Sorry. We cannot renew your order.', 'hipay'); } else { if (!$duplication['success']) { $errors[] = $hipay->l('Some items are no longer available, and we are unable to renew your order.', 'hipay'); } else { // FR. Le panier courant a déjà été utilisé sur la plateforme Hipay. Un nouveau panier viens d'être créé afin de procéder malgré tout au paiement. Attention, celui-ci va impliquer une nouvelle transaction sur la plateforme Hipay. // EN. The current cart has already been used on the Hipay platform. A new cart just been created to make the payment anyway. Warning, this will involve a new transaction on the Hipay platform. $errors[] = $hipay->l('The current cart has already been used on the Hipay platform. A new cart just been created to make the payment anyway. Warning, this will involve a new transaction on the Hipay platform.', 'hipay'); $context->cookie->id_cart = $duplication['cart']->id; $context->cookie->write(); } } if (count($errors)) { return $errors; } return false; }
private function retentativa($e) { //See ParentOrderController.php L-74 $oldCart = new Cart($this->context->cart->id); $duplication = $oldCart->duplicate(); self::$cookie->id_cart = $duplication['cart']->id; self::$cookie->write(); $this->cancelOrder(); $params = array('retentativa' => true, 'b_errors' => $e->getErrors()->list); $url = $this->context->link->getModuleLink('bcash', 'payment', $params, true); Tools::redirectLink($url); }
/** * Re calculate shipping cost * @return object $order */ public function refreshShippingCost() { if (empty($this->id)) { return false; } if (!Configuration::get('PS_ORDER_RECALCULATE_SHIPPING')) { return $this; } $fake_cart = new Cart((int) $this->id_cart); $new_cart = $fake_cart->duplicate(); $new_cart = $new_cart['cart']; // assign order id_address_delivery to cart $new_cart->id_address_delivery = (int) $this->id_address_delivery; // assign id_carrier $new_cart->id_carrier = (int) $this->id_carrier; //remove all products : cart (maybe change in the meantime) foreach ($new_cart->getProducts() as $product) { $new_cart->deleteProduct((int) $product['id_product'], (int) $product['id_product_attribute']); } // add real order products foreach ($this->getProducts() as $product) { $new_cart->updateQty($product['product_quantity'], (int) $product['product_id']); } // get new shipping cost $base_total_shipping_tax_incl = (double) $new_cart->getPackageShippingCost((int) $new_cart->id_carrier, true, null); $base_total_shipping_tax_excl = (double) $new_cart->getPackageShippingCost((int) $new_cart->id_carrier, false, null); // calculate diff price, then apply new order totals $diff_shipping_tax_incl = $this->total_shipping_tax_incl - $base_total_shipping_tax_incl; $diff_shipping_tax_excl = $this->total_shipping_tax_excl - $base_total_shipping_tax_excl; $this->total_shipping_tax_excl = $this->total_shipping_tax_excl - $diff_shipping_tax_excl; $this->total_shipping_tax_incl = $this->total_shipping_tax_incl - $diff_shipping_tax_incl; $this->total_shipping = $this->total_shipping_tax_incl; $this->total_paid_tax_excl = $this->total_paid_tax_excl - $diff_shipping_tax_excl; $this->total_paid_tax_incl = $this->total_paid_tax_incl - $diff_shipping_tax_incl; $this->total_paid = $this->total_paid_tax_incl; $this->update(); // save order_carrier prices, we'll save order right after this in update() method $order_carrier = new OrderCarrier((int) $this->getIdOrderCarrier()); $order_carrier->shipping_cost_tax_excl = $this->total_shipping_tax_excl; $order_carrier->shipping_cost_tax_incl = $this->total_shipping_tax_incl; $order_carrier->update(); // remove fake cart $new_cart->delete(); return $this; }