Jump to content

[solved]How to clear all produts from cart


Recommended Posts

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 by karthick (see edit history)
Link to comment
Share on other sites

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

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

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

  • 2 weeks later...
  • 2 months later...

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

×
×
  • Create New...