Kennedy5020 Posted June 14, 2013 Share Posted June 14, 2013 (edited) Hi, Currently cart have separate delete button for every products. How to remove all the products in one action. Just i need empty cart in one click i have used below code in ordercontroller and call the function from themes/default/shooping-cart.tpl function in ordercontroller public function emptybag() { $products = $this->getProducts(); foreach ($products as $product) { $this->deleteProduct($product->id); } } and how to call from shooping-cart.tpl and this is right code for empty the shopping bag ? i am new to prestashop so please brief answer . Edited June 28, 2013 by karthick (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted June 14, 2013 Share Posted June 14, 2013 create new button in the shopping cart template file: <form method="post"> <input type="submit" name="emptybag" value="remove all products"/> </form> then in order controller (controllers/OrderController.php) in the init() function add: if (isset($_POST['emptybag'])){ $this->emptybag(); } Link to comment Share on other sites More sharing options...
Kennedy5020 Posted June 14, 2013 Author Share Posted June 14, 2013 create new button in the shopping cart template file: <form method="post"> <input type="submit" name="emptybag" value="remove all products"/> </form> then in order controller (controllers/OrderController.php) in the init() function add: if (isset($_POST['emptybag'])){ $this->emptybag(); } thanks vekia. when i add this code in function init if (isset($_POST['emptybag'])){ $this->emptybag(); } shows empty screen . any idea ? Link to comment Share on other sites More sharing options...
vekia Posted June 14, 2013 Share Posted June 14, 2013 have you got your function emptybag() in the ordercontroller ? ps. turn error reporting on Link to comment Share on other sites More sharing options...
Kennedy5020 Posted June 14, 2013 Author Share Posted June 14, 2013 have you got your function emptybag() in the ordercontroller ? ps. turn error reporting on i got this error when i call this function public function emptybag() { $products = $this->getProducts(); foreach ($products as $product) { $this->deleteProduct($product->id); } } Fatal error: Call to undefined method OrderController::getProducts() Link to comment Share on other sites More sharing options...
vekia Posted June 14, 2013 Share Posted June 14, 2013 so you don't check your own code? $products = $this->getProducts(); this code from your function doesn't work, because getProducts(); doesn't exist Link to comment Share on other sites More sharing options...
samukacpz Posted June 27, 2013 Share Posted June 27, 2013 (edited) Hi! I'm using PS 1.4.4.1! What method should I use for empty the cart? I tried that code ($products = $this->nbProducts;) and it did not work! Edited June 27, 2013 by samukacpz (see edit history) Link to comment Share on other sites More sharing options...
sooroos Posted September 1, 2013 Share Posted September 1, 2013 hi, i am trying to make a button to clear all products in block cart, but i can't get it working. i have added this function in /override/controllers/front/CartController.php public function emptybag() { $products = $this->context->cart->getProducts(); foreach ($products as $product) { $this->context->cart->deleteProduct($product["id_product"]); } } then in the same file at the end of public function init() i have added (isset($_GET['emptybag'])){ $this->emptybag(); } than i have added the button in blockcart.tpl: <a href="{$link->getPageLink('order', true, NULL, 'emptybag=1')}" class="button_large" title="{l s='Clear cart'}">{l s='Clear cart'}</a> the button is there but it does not empty the cart, any help? Link to comment Share on other sites More sharing options...
Recommended Posts