2

我可以使用什么 magento 方法来停止结帐按钮的功能,直到某个条件为真?基本上是用户删除了购物篮中的产品,而他必须在购物篮中有两个产品之前结帐

public function deleteAction()
{
    parent::deleteAction();

   if($this->_getCart()->getQuote()->getItemsCount() == 1) {
      $this->addErrorMessage('Please remove one voucher. Or add one More infant milk product');
    }
    }
4

1 回答 1

4

使用配置标志很容易做到这一点checkout/options/onepage_checkout_enabled

public function deleteAction()
{
    parent::deleteAction();

   if($this->_getCart()->getQuote()->getItemsCount() == 1) {

       Mage::app()->getStore()->setConfig('checkout/options/onepage_checkout_enabled',0);
   }

}

旁注:

这里实际上没有必要重写控制器,因为您可以在调度后控制器观察者操作中处理它:

<events>
    <controller_action_postdispatch_checkout_cart_delete>
        <observers>
            <yourmodule_postdispatch_delete>
                <class>yourmodel/observer</class>
                <method>deletePostdispatch</method>
            </yourmodule_postdispatch_delete>
        </observers>
    </controller_action_postdispatch_checkout_cart_delete>
</events>

观察者方法看起来像:

public function deletePostdispatch($observer)
{
   if(Mage::getSingleton('checkout/session')->getQuote()->getItemsCount()==1){

       Mage::app()->getStore()->setConfig('checkout/options/onepage_checkout_enabled',0);
   }

}

HTH,干杯!

于 2013-08-21T00:28:51.630 回答