Y
Y
Yuri Voronin2016-10-27 13:04:25
PHP
Yuri Voronin, 2016-10-27 13:04:25

How to remove all cart items on button click?

There is a component sale.basket.basket. Add a Delete Entire Cart button. I searched on the Internet and found this way:
in init.php add
if ($_POST["BasketDelete"] and CModule::IncludeModule("sale"))
{
CSaleBasket::DeleteAll(CSaleBasket::GetBasketUserID());
}
and add a button in the template

<input type="submit" value="Очистить корзину" name="BasketDelete">

Clicking on it will take you to the checkout page. And if you then return to the basket, then it is empty. Is there a way to do this without going to the checkout page?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Voronin, 2016-10-28
@yuraSco

after the basket form, I created another form with the post method, pushed the button there. Everything works as it should

O
Oleg Maksimenko, 2016-10-27
@olegprof

Add after CSaleBasket::DeleteAll() the line LocalRedirect('reference to the basket');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question