基于运输方式的Magento过滤器支付方式

时间:2013-05-29 19:42:24

标签: magento

我在Magento中开发了基于运输方法的过滤器支付方法的观察者方法。这是我的方法:

class Devpassion_Paymentfilter_Model_Observer {

public function paymentMethodIsActive(Varien_Event_Observer $observer) {
    $event           = $observer->getEvent();
    $method          = $event->getMethodInstance();
    $result          = $event->getResult();
    $carriers = Mage::getSingleton('shipping/config')->getActiveCarriers();

        foreach ($carriers as $carrier) {
     //       $carrierCode = $carrier->getId();

            if ($carrier->getId() == 'flatrate' ){
                    if($method->getCode() == 'checkmo' OR $method->getCode() == 'paypal_standard'){
                        $result->isAvailable = true;
                    }else{
                        $result->isAvailable = false;
                    }
                }

             }
    }
}

结果是,对于所有送货方式,此过滤器均为真。所以对于所有的运输方式paypal和钱检查显示,所有其他没有。

请告诉我如何设置此条件以仅过滤一种特定的送货方式。

1 个答案:

答案 0 :(得分:1)

public function paymentMethodIsActive($observer)
    {
        /**
         * @var $quote Mage_Sales_Model_Quote
         */
        $quote  = $observer->getEvent()->getQuote();
        $method = $observer->getEvent()->getMethodInstance();
        $result = $observer->getEvent()->getResult();

        $shipping_method = $quote->getShippingAddress()->getShippingMethod();
        if ($shipping_method == 'flatrate_flatrate' && $method->getCode() == 'checkmo') {
            $result->isAvailable = false;
        }
    }