本文整理汇总了PHP中Cart::duplicate方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::duplicate方法的具体用法?PHP Cart::duplicate怎么用?PHP Cart::duplicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cart
的用法示例。
在下文中一共展示了Cart::duplicate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
/**
* 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');
}
}
示例2: duplicateCart
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;
}
示例3: postProcess
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();
}
示例4: init
/**
* 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')));
}
示例5: preProcess
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')));
}
示例6: preProcess
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');
}
//.........这里部分代码省略.........
示例7: refillCart
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;
}
}
示例8: die
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']);
}
示例9: duplicateCart
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;
}
示例10: retentativa
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);
}
示例11: refreshShippingCost
/**
* 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;
}