无法取消或清除joomla虚拟购物车会话变量


Unable to unset or clear joomla virtuemart cart session variable

我创建了一个按钮,我想在点击事件上重置购物车。保存购物车值的会话变量是

print_r(unserialize($_SESSION['__vm']['vmcart'])); 

I tried

$session->clear('__vm','vmcart');

但是它不适合我

对不起,对于VM 2应该有另一个解决方案!在文件/components/com_virtuemart/cart/default_pricelist.php中添加链接:

<a href="<?=JRoute::_( 'index.php?option=com_virtuemart&view=cart&task=deleteCart' ) ?>">Clear cart</a>

在components/com_virtuemart/controllers/cart.php中添加函数:

public 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'));
}

和components/com_virtuemart/helpers/cart.php

public function removeCart() {
   if (!empty($this->products)) {
      foreach ( $this->products as $key => $val ) {
         unset($this->products[$key]);
         $this->setCartIntoSession();
      }
      return true;
   }
}

请试试!让我知道如果有什么不工作-当然有帮助!