Magento产品页面上的运费报价

时间:2014-09-29 11:38:00

标签: php magento ip

我正在尝试使用以下代码在产品页面上显示运费:

<?php
            if($_product->isSaleable())
            {
            $quote = Mage::getModel('sales/quote');
            $quote->getShippingAddress()->setCountryId('GB');
            $quote->addProduct($_product);
            $quote->getShippingAddress()->collectTotals();
            $quote->getShippingAddress()->setCollectShippingRates(true);
            $quote->getShippingAddress()->collectShippingRates();
            $rates = $quote->getShippingAddress()->getShippingRatesCollection();

            $minPrice = PHP_INT_MAX;
            foreach ($rates as $rate) {
            $minPrice = min($minPrice, $rate->getPrice());
            }
            if ($minPrice == 0) {
                echo ('This item qualifies for FREE shipping');
            }
            elseif ($minPrice < PHP_INT_MAX) {
                echo ('Shipping to UK from £' . money_format('%i', $rate->getPrice()) . "\n");
            }
            }
            ?>

系统如何自动检测用户ip?而不是设置国家ID。

0 个答案:

没有答案