无法更新送货地址

时间:2017-03-15 08:59:18

标签: magento magento-1.9

我想在购物车页面上显示运费,所以我使用了工作正常的sales_quote_collect_totals_before活动。问题是,为了显示购物车上的运费,我必须从magento admin设置默认送货地址。现在,当我下订单时,使用默认送货地址,而不是我在结账的送货地址字段中手动输入的内容。我试图在报价单中保存送货地址,但在下订单时它会被覆盖。

这是我的代码 -

public function handleCollect($observer) {

        if (!Mage::getStoreConfig('shipping/origin/applydefaultstoemptyquote'))
            return $this;


        $quote = $observer->getEvent()->getQuote();

        $shippingAddress = $quote->getShippingAddress();


        $billingAddress = $quote->getBillingAddress();

        $saveQuote = false;
        if (!$shippingAddress->getCountryId()) {


            $country = Mage::getStoreConfig('shipping/origin/country_id');

            $state = Mage::getStoreConfig('shipping/origin/region_id');

            $postcode = Mage::getStoreConfig('shipping/origin/postcode');

            $method = Mage::getStoreConfig('shipping/origin/shippingmethod');

            $shippingAddress
                    ->setCountryId($country)
                    ->setRegionId($state)
                    ->setPostcode($postcode)
                    ->setShippingMethod($method)
                    ->setCollectShippingRates(true);
            $shippingAddress->save();

            $saveQuote = true;
        } else {
            $country = Mage::getStoreConfig('shipping/origin/country_id');
            $state = Mage::getStoreConfig('shipping/origin/region_id');
            $postcode = Mage::getStoreConfig('shipping/origin/postcode');
            $method = Mage::getStoreConfig('shipping/origin/shippingmethod');

            $shippingAddress
                    ->setCountryId($country)
                    ->setRegionId($state)
                    ->setPostcode($postcode)
                    ->setShippingMethod($method)
                    ->setCollectShippingRates(true);
            $shippingAddress->save();

            $saveQuote = true;
        }
        if (Mage::getStoreConfig('shipping/origin/applydefaultstobillingaddress') && !$billingAddress->getCountryId()) {

            $country = Mage::getStoreConfig('shipping/origin/country_id');
            $state = Mage::getStoreConfig('shipping/origin/region_id');
            $postcode = Mage::getStoreConfig('shipping/origin/postcode');

            $billingAddress
                    ->setCountryId($country)
                    ->setRegionId($state)
                    ->setPostcode($postcode);

            $saveQuote = true;

            $quote->save();
        }
        if ($saveQuote)
            $quote->save();

        return $this;
    }

我做错了什么?

0 个答案:

没有答案