Jump to content

Empty Cart in one click prestashop 1.6.1 - delete all products from cart


Recommended Posts

Hello,

 

I need a one click delete all products in cart.  I found solutions for previous versions of prestashop, but not 1.6, and I even though I tried solutions for earlier versions I cannot get to work.  Please someone help me, as I need to just remove all products in cart with one button. I tried other solution that didn't work in prestashop 1.6. such as

 

https://www.prestashop.com/forums/topic/281494-delete-all-products-in-shopping-cart/

 

And someone else needing same feature:

https://www.prestashop.com/forums/topic/388418-empty-cartdelete-all-products-from-cart-button-for-ps16-how/

 

EDIT:

I have solved this by piecing together different information, this is how I've accomplished to empty cart in one click with prestashop 1.6.1:

 

Add the link that calls emptyCart - add it somewhere in shopping-cart.tpl, as this is the cart page:
 

<a class="btn btn-default button button-medium exclusive" href="{$link->getPageLink('cart', true, NULL, "emptyCart=1&token={$token_cart}")}" title="{l s='Delete'}"><span>{l s='Clear Cart'}</span></a>

 

Inside CartController.php in root controllers directory, add the functions that empty out the cart:

 

protected function emptyCart()
{
 
$result = array();
$result['summary'] = $this->context->cart->getSummaryDetails(null, true);
foreach ($result['summary']['products'] as $key => &$product)
{
$this->processDeleteProduct($product['id_product'],$product['id_product_attribute'],$product['customization_id'],$product['id_address_delivery']);
 
 
}
 
 
protected function processDeleteProduct($idProd, $idAttrib, $custom_id, $id_address)
{
if ($this->context->cart->deleteProduct($idProd, $idAttrib, $custom_id, $id_address))
{
if (!Cart::getNbProducts((int)($this->context->cart->id)))
{
$this->context->cart->setDeliveryOption(null);
$this->context->cart->gift = 0;
$this->context->cart->gift_message = '';
$this->context->cart->update();
}
}
$removed = CartRule::autoAddToCart();
if (count($removed) && (int)Tools::getValue('allow_refresh'))
$this->ajax_refresh = true;
 
I added these functions right after init function, so line 65.
 
Inside same file, add the bit that actually runs the function when its called:
 
so, inside public function postProcess(), add elseif to the if statement:
 
so add:
 
elseif (Tools::getIsset('emptyCart'))
$this->emptyCart();
 
to:
 
if (Tools::getIsset('add') || Tools::getIsset('update'))
$this->processChangeProductInCart();
elseif (Tools::getIsset('delete'))
$this->processDeleteProductInCart();
elseif (Tools::getIsset('changeAddressDelivery'))
$this->processChangeProductAddressDelivery();
elseif (Tools::getIsset('allowSeperatedPackage'))
$this->processAllowSeperatedPackage();
elseif (Tools::getIsset('duplicate'))
$this->processDuplicateProduct();
 
mine looks like:
if (Tools::getIsset('add') || Tools::getIsset('update'))
$this->processChangeProductInCart();
elseif (Tools::getIsset('delete'))
$this->processDeleteProductInCart();
elseif (Tools::getIsset('emptyCart'))
$this->emptyCart();
elseif (Tools::getIsset('changeAddressDelivery'))
$this->processChangeProductAddressDelivery();
elseif (Tools::getIsset('allowSeperatedPackage'))
$this->processAllowSeperatedPackage();
elseif (Tools::getIsset('duplicate'))
$this->processDuplicateProduct();
Edited by dprovost1990 (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

awesome worked like a charm! although if I may add something for a little better security for you customers with a simple tweak 

 

<a onclick="return confirm('Are you sure you want to delete all items from your cart?');"class="btn btn-default button button-medium exclusive" href="{$link->getPageLink('cart', true, NULL, "emptyCart=1&token={$token_cart}")}" title="{l s='Delete'}"><span>{l s='Clear Cart'}</span></a>    

 

so they don;t accidentally delete anything ;) 

Link to comment
Share on other sites

  • 4 months later...
  • 10 months later...

Hi. This work for PS ver. 1.6.1.6

But i think all core modification should be in override folder. File for override folder (only if you dont have file with same name in override folder): https://drive.google.com/open?id=0B3xnLaE3af-Ybjg4bVFwZXdmLTg

 

Also, i found another one way, on this site: http://nemops.com/clear-cart-button-prestashop/#.WEWa7bKLQb9

Link to comment
Share on other sites

  • 5 months later...

Hi, 

 

 If you use customization, this should be changed:

 
$this->processDeleteProduct($product['id_product'],$product['id_product_attribute'],$product['customization_id],$product['id_address_delivery']);
 
to 
 
$this->processDeleteProduct($product['id_product'],$product['id_product_attribute'],$product['id_customization'],$product['id_address_delivery']);
 

 

Prestashop 1.6

 

 Regards,

   Lucas

Link to comment
Share on other sites

×
×
  • Create New...