我正在学习Magento并尝试创建一种仅在购物车小计超过$100时才出现的运输方法。

我试着 getSubTotal() 在功能 collectRates(), ,则 return false 如果返回值小于100。然而,它总是返回 0.我猜在那一步还没有计算出来,是真的吗?

还有别的办法我可以做我想做的事吗?

请帮忙。..非常感谢!

有帮助吗?

解决方案

你的 collectRates 方法应该是这样的

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    //if method is disabled
    if (!$this->getConfigFlag('active')) {
        return false;
    }

    if ($request->getPackageValue() < 100) {
        return false;
    }
    /** @var Mage_Shipping_Model_Rate_Result $result */
    $result = Mage::getModel('shipping/rate_result');
    $method = Mage::getModel('shipping/rate_result_method');
    $method->setCarrier($this->_code); //add here the payment method code
    $method->setCarrierTitle($this->getConfigData('title')); //or you can add any title if it's not configurable
    $method->setPrice(your shiping cost here);
    $result->append($method);
    return $result;
}
许可以下: CC-BY-SA归因
scroll top