本文介绍了Magento:获取所有运费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取带有magento运费(例如统一费率,免费送货等)的数组/对象?
How can I get an array/object with the shipping rates in magento such as Flat Rate, Free Delivery etc ?
所选地址或产品的字母缩写.
Irrelevant of the address or products selected.
推荐答案
这是另一种方法.您需要设置邮政编码和国家/地区-即使这与您的送货方式无关紧要.
Here's another way. You need to set a zip and country - even if that doesn't matter for your shipping methods.
// 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());
}
}
这篇关于Magento:获取所有运费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!