mavix91 Posted December 6, 2015 Share Posted December 6, 2015 (edited) Hello, I've been going through the Prestashop code trying to figure out how to make the cart contents persist after an order payment has been made, with no luck. The way I understand it, it would appear that once an order has been associated with a cart, it is no longer available as the customer's shopping cart (and the default cart is thus returned to "empty"). Based on the above then, I assume it would be best to duplicate the cart associated with the order to a new cart associated to the customer at some stage during the order, which will then repopulate the shopping cart as soon as the payment is processed. Would this be the best way to do it? And where/how would I make this change? Edited December 7, 2015 by mavix91 (see edit history) Link to comment Share on other sites More sharing options...
mavix91 Posted December 6, 2015 Author Share Posted December 6, 2015 For what it's worth, I tried adding the following code to controllers/front/OrderConfirmationController.php, before the return in displayOrderConfirmation(), which I figured was the last step in the order process and would be the best place to duplicate the cart: $cart = new Cart($this->id_cart); $this->context->cart = $cart->duplicate(); However, this doesn't seem to do anything. I've also tried placing it elsewhere in various order controllers functions with no luck. Any ideas on what I'm doing wrong? Link to comment Share on other sites More sharing options...
mavix91 Posted December 7, 2015 Author Share Posted December 7, 2015 Solved, as follows: 1. Duplicate cart once order complete (Controllers/front/displayOrderConfirmation, before return in displayOrderConfirmation, insert: $cart = new Cart($this->id_cart); $this->context->cart = $cart->duplicate(); 2. Under FrontController->init replace: if (!isset($cart) || !$cart->id) { $cart = new Cart(); $cart->id_lang = (int)$this->context->cookie->id_lang; $cart->id_currency = (int)$this->context->cookie->id_currency; $cart->id_guest = (int)$this->context->cookie->id_guest; $cart->id_shop_group = (int)$this->context->shop->id_shop_group; $cart->id_shop = $this->context->shop->id; if ($this->context->cookie->id_customer) { $cart->id_customer = (int)$this->context->cookie->id_customer; $cart->id_address_delivery = (int)Address::getFirstCustomerAddressId($cart->id_customer); $cart->id_address_invoice = (int)$cart->id_address_delivery; } else { $cart->id_address_delivery = 0; $cart->id_address_invoice = 0; } // Needed if the merchant want to give a free product to every visitors $this->context->cart = $cart; CartRule::autoAddToCart($this->context); } with if (!isset($cart) || !$cart->id) { $cart = new Cart(); $cart = $this->context->customer->getLastCartObjectES(); // Needed if the merchant want to give a free product to every visitors $this->context->cart = $cart; CartRule::autoAddToCart($this->context); } 3. Add the following function to the Customer class: public function getLastCartObjectES() { $carts = Cart::getCustomerCarts((int)$this->id, false); if (!count($carts)) { return false; } $cart = array_shift($carts); $cart = new Cart((int)$cart['id_cart']); return $cart; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now