The task was as follows: clear cart by one click. Maybe this function will prove useful, or someone can do this better.
I added link in site/component/com_virtuemart/cart/default_pricelist.php
Quote<a href="<?=JRoute::_( 'index.php?option=com_virtuemart&view=cart&task=deleteCart' ) ?>">Clear cart</a>
Function in site/component/com_virtuemart/controllers/cart.php
Quotepublic function deleteCart() {
$mainframe = JFactory::getApplication();
$cart = VirtueMartCart::getCart();
if ($cart->removeCart()) {
$mainframe->enqueueMessage('All is done.');
} else {
$mainframe->enqueueMessage('Error with deleting.', 'error');
}
$mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart'));
}
Function in site/component/com_virtuemart/helpers/cart.php
Quotepublic function removeCart() {
if (!empty($this->products)) {
foreach ( $this->products as $key => $val ) {
unset($this->products[$key]);
$this->setCartIntoSession();
}
return true;
}
}
$cart = VirtueMartCart::getCart();
$cart->emptyCart();
should do the same, I mean instead of removeCart()
Thanks! Works!
To get this working for me with SEO enabled required an additional line in the router.php
Look for
elseif ( $helper->compareKey($segments[0] ,'delete') ) $vars['task'] = 'delete' ;
and add an extra line below
elseif ( $helper->compareKey($segments[0] ,'deleteCart') ) $vars['task'] = 'deleteCart' ;
I'm no expert on these things and took me hours to resolve it. It may help others