0

我在 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;
                    }
                }

             }
    }
}

结果是,对于所有运输方式,此过滤器都是正确的。因此,对于所有运输方式,贝宝和支票都会显示,而其他所有方式都不会显示。

请建议我如何设置此条件以仅针对一种特定的运输方式进行过滤。

4

1 回答 1

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;
        }
    }
于 2013-05-30T08:25:02.053 回答