如果有一个运费金额为零的方法,请删除所有其他运送方式

时间:2014-04-04 11:15:26

标签: magento shipping

是否可以删除除运费 0 之外的所有shipping methods

可能会有一个promotion rule会返回 0 的数量,因此不能删除。

conditional free shipping

1 个答案:

答案 0 :(得分:0)

Display only shipping methods with price 0 (zero) if any

在我的模块中,我将Mage_Checkout_Block_Onepage_Shipping_Method_Available块重写为:

<强> config.xml中

<global>
    <blocks>
        <checkout>
            <rewrite>
                <onepage_shipping_method_available>Excellence_Subscription_Block_Checkout_Onepage_Shipping_Method_Available</onepage_shipping_method_available>
            </rewrite>
        </checkout>
    </blocks>
</global>

<强> Excellence_Subscription_Block_Checkout_Onepage_Shipping_Method_Available

<?php

class Excellence_Subscription_Block_Checkout_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available {

    public function getShippingRates() {
        $groups = parent::getShippingRates();
        $free = array();
        foreach ($groups as $code => $_rates) {
            foreach ($_rates as $_rate) {
                if (!$_rate->getPrice() > 0) {
                    $free[$code] = $_rates;
                }
            }
        }
        if (!empty($free)) {
            return $this->_rates = $free;
        }
        return $groups;
    }

}