如何获得带有 magento 运费的数组/对象,例如统一费率、免费送货等?
与所选地址或产品无关。
这是另一种方式。您需要设置邮编和国家 - 即使这对您的运输方式无关紧要。
// Change to your postcode / country.
$zipcode = '2000';
$country = 'AU';
// Update the cart's quote.
$cart = Mage::getSingleton('checkout/cart');
$address = $cart->getQuote()->getShippingAddress();
$address->setCountryId($country)
->setPostcode($zipcode)
->setCollectShippingrates(true);
$cart->save();
// Find if our shipping has been included.
$rates = $address->collectShippingRates()
->getGroupedAllShippingRates();
foreach ($rates as $carrier) {
foreach ($carrier as $rate) {
print_r($rate->getData());
}
}
您不能这样做“无关紧要”,因为您需要设置地址数据(账单或运输,如果只有账单,然后运输设置与账单相同:国家、邮编、地区取决于您的运输方式)并报价至少有一个简单的项目(引用现有的、虚拟的和可下载的产品不需要运输)。之后,您可以调用您的报价对象
$quote->getShippingAddress()->getGroupedAllShippingRates();
我想到了...
$carriers = Mage::getStoreConfig('carriers', Mage::app()->getStore()->getId());
foreach ($carriers as $carrierCode => $carrierConfig) {
print_R($carrierConfig);
}
谢谢您的帮助