无法取消或清除joomla virtuemart cart会话变量

时间:2014-05-26 16:26:07

标签: php joomla virtuemart

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

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

我试过

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

但它确实对我不起作用

1 个答案:

答案 0 :(得分:0)

抱歉,对于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;
   }
}

请试一试!如果有什么不起作用,请告诉我 - 当然有帮助!