Jump to content

[SOLVED] one click empty cart


Recommended Posts

Try changing line 36 (in PrestaShop v1.3.1) of cart.php in the root directory of PrestaShop from:

if ($add OR Tools::getIsset('update') OR $delete)



to:

if (Tools::getIsset('empty'))
  $cart->delete();
elseif ($add OR Tools::getIsset('update') OR $delete)



Then add a link in shopping-cart.tpl like the following:

<a href="{$base_dir_ssl}cart.php?empty&token={$token_cart}">{l s='Empty Cart'}



I haven't tested it, but it should work.

Link to comment
Share on other sites

  • 1 year later...

Hey Rocky,

 

Any idea how we can replicate this on Prestashop version 1.4.4.1?

 

I tried the exact same thing above (except that instead of cart.php, I edited controllers > cartControllers.php on Line 102), but when I added the <a> tag, clicking it brought me to an empty page.

 

Thanks in advance! :)

Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...
  • 1 month later...

In shopping-cart.tpl

 

line 82

 

<th class="cart_delete last_item"><a href="{$link->getPageLink('cart', true, NULL, "emptyCart=1&token={$token_cart}")}" title="{l s='Delete'}">{l s='Eliminar todo'}</a></th>

 

In CartController.php

 

//line 67

if (Tools::getIsset('add') || Tools::getIsset('update'))

{

$this->processChangeProductInCart();

}

else if (Tools::getIsset('emptyCart'))

{

$this->emptyCart();

}

 

 

//final .php

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;

}

Link to comment
Share on other sites

  • 3 months later...
  • 2 months later...
  • 6 months later...
  • 1 year later...
  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...