Magento 1.7

This is the code which gets called via the checkout_cart_product_add_after event when I add a product to the cart:

function addProductComplete(Varien_Event_Observer $observer) {

        $onepage = Mage::getSingleton('checkout/type_onepage');

        // Add address to cart
        $address = $onepage->getQuote()->getShippingAddress();

        if (null == $address->getCountryId())
            $country = Mage::helper('core')->getDefaultCountry(); // use default country
            if ( '' == $country )
                $country = 'DE';

        if ( null == $address->getPostcode() )

        // save settings


When I add the first product, nothing happens, only after adding the second product, it works. I guess thats because the first time there is no quote object? How to solve that so it works with the first product as well?


I would suggest going with sales_quote_product_add_after instead of checkout_cart_product_add_after

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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