dprovost1990 Posted July 28, 2015 Share Posted July 28, 2015 (edited) 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 July 28, 2015 by dprovost1990 (see edit history) 1 Link to comment Share on other sites More sharing options...
robertsona Posted September 4, 2015 Share Posted September 4, 2015 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 More sharing options...
Vitek_K_184 Posted January 8, 2016 Share Posted January 8, 2016 (edited) Hi, can you help me with AJAX cart? Now, Ajax is the same. It is OK. Problem was with cache-control on the hosting server. Edited January 20, 2016 by Vitek_K_184 (see edit history) Link to comment Share on other sites More sharing options...
Cvalya Posted December 5, 2016 Share Posted December 5, 2016 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 More sharing options...
lvaldeon Posted May 20, 2017 Share Posted May 20, 2017 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 More sharing options...
Recommended Posts