1

On payment step default checkout I am trying to get the customer shipping address. But sometimes returns empty (please see the image below).

enter image description here

I am using a code similar to this to get the Shipping Address:

$quote = Mage::getSingleton('checkout/session')->getQuote();
$address = $quote->getShippingAddress();
print $address->getPostcode();

Anyone know why this happens? Thank in advance

5
  • I tried to getBillingAddress... occurs some error.
    – Eduardo
    Mar 7, 2014 at 14:03
  • I think the problem is in trying to get the address on the payment step, and it has not been saved yet. I'm editing the controllers but I'm not succeeding...
    – Eduardo
    Mar 10, 2014 at 18:20
  • When I conclude the purchase order in the admin panel the address details appear correctly...
    – Eduardo
    Mar 10, 2014 at 18:28
  • I came to the conclusion that it is not it too, if I reload the page before completing the purchase, and fill again address and shipping information, all data appears.
    – Eduardo
    Mar 10, 2014 at 19:29
  • Log files are empty...
    – Eduardo
    Mar 10, 2014 at 19:50

1 Answer 1

1

If this is part of the one page checkout and you are working in a controller that extends Mage_Checkout_OnepageController, as the comments suggest what you should be able to do to get the shipping or billing information is call:

$this->getQuote()->getBillingAddress();
$this->getQuote()->getShippingAddress();

Another way of doing this could be to use the getAddressAction if you already know the address id then it might be worth considering this as this will return the address in json form:

/**
 * Address JSON
 */
public function getAddressAction()
{
    if ($this->_expireAjax()) {
        return;
    }
    $addressId = $this->getRequest()->getParam('address', false);
    if ($addressId) {
        $address = $this->getOnepage()->getAddress($addressId);

        if (Mage::getSingleton('customer/session')->getCustomer()->getId() == $address->getCustomerId()) {
            $this->getResponse()->setHeader('Content-type', 'application/x-json');
            $this->getResponse()->setBody($address->toJson());
        } else {
            $this->getResponse()->setHeader('HTTP/1.1','403 Forbidden');
        }
    }
}

Your Answer

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

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