2

我读了类似的问题,但没有运气。

我正在使用 magento 1.9。我想在产品视图页面中显示运费。我在产品页面中有邮政编码文本框。输入邮政编码后,我想在同一页面中显示运费。

我尝试了以下代码。它正在显示更改,但实际价格不同,这意味着在结帐页面中相同的邮政编码费用不同。通过使用以下代码,收费是不同的。

$shippingblock = $this->getLayout()->createBlock('checkout/cart_shipping');
        $quote = Mage::getModel('sales/quote');

        $shippingAddress = $quote->getShippingAddress();
        $shippingAddress->setCountryId('country');
        $shippingAddress->setPostcode('zipcode');
        $shippingAddress->setCollectShippingRates(true);


        $quote->addProduct($_product);
        $quote->getShippingAddress()->collectTotals();
        $quote->getShippingAddress()->setCollectShippingRates(true);
        $quote->getShippingAddress()->collectShippingRates();

        $rates = $quote->getShippingAddress()->getGroupedAllShippingRates();


        if(empty($rates)){
             echo  Mage::helper('shipping')->__('There are no rates available');
        }


        foreach ($rates as $code=>$rate) {
            $carierName = '<div class="cariername">'
                . $shippingblock->getCarrierName($code)
                .'</div>';
            echo $carierName;

            foreach($rate as $r){
                $price = Mage::helper('core')->currency($r->getPrice(), true, false);
                $rates  = '<div>'
                    . $r->getMethodTitle()
                    . ' <strong>'
                    . $price
                    .' </strong>';
                echo $rates;
            }

        }

在产品页面中显示联邦快递费用的任何其他方式?我正在使用默认的联邦快递方法。

4

0 回答 0