1

I recently added an extension to show the shipping charges in cart page. It calls an observer upon the event sales_quote_collect_totals_before and sets the shipping address to default. I have a shopping bag popup to show the cart details and I don't want to show the shipping charges there. I checked the sales_flat_quote_address table and saw that the shipping address wasn't added when a product was first added to cart by a guest user; only the billing address was added with NULL values. The shipping address was set in the table after adding another item to cart or after calling the indexAction in CartController. However, the grandtotal was being set to the value which was inclusive of the shipping charge. Can someone please explain how the shipping charge is getting added to grand total in sales_flat_quote table without the shipping address being set in sales_flat_quote_address?

Here's the observer's code for the extension I have used.

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');
        Mage::log($method);
        $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;
}

1 Answer 1

0

If the billing address is set maybe theres also the attribute "use_for_shipping" setted. So Magento calculate the shipping price with the billing address

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.