0

Onepagecheckout: If I jump back to shipping address (i.e. from step shipping method or payment method) then I do see an empty shipping address form.

Since I "force" the customers to use billing address as shipping address I want to pre populate the shipping fields with billing address (automatically fill out shipping address for guests by using billing address).

The concerning template is frontend/default/mytheme/template/checkout/onepage/shipping.phtml.

All shipping fields would get filled out automatically if a customer is logged in because all fields have values like

value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>

So actually my goal is to overwrite $this->getAddress() with the data from billing address. But I can't get it to work!

What I got so far in

frontend/default/mytheme/template/checkout/onepage/shipping.phtml

// Load billing address
$checkout = Mage::getSingleton('checkout/session')->getQuote();
$bilAddress = $checkout->getBillingAddress();

// Load customer model
$customAddress = Mage::getModel('customer/address');
$customAddress->setData($bilAddress);

// Now I want to set billing address as shipping address. But none of these 3 approaches work.
$checkout->setShippingAddress(Mage::getSingleton('sales/quote_address')->importCustomerAddress($customAddress));
$this->setShippingAddress(Mage::getSingleton('sales/quote_address')->importCustomerAddress($customAddress));
$checkout->getShippingAddress()->setSameAsBilling(true);

Can anyone point me in the right direction? I ran out of ideas. Thank you very much for any help! I appreciate it!

  • Your address exist in quote, did you try to make smth like $quote->getBillingAddress()->get....() ? – zhartaunik May 8 '15 at 14:14
  • Thank you very much for your help. Yes, actually I load the quote object in $checkout. But it doesn't work:( Also tried $checkout->setAddress($bilAddress); $checkout->getAddress()->setData($bilAddress); $this->setAddress($bilAddress); – Stefan May 8 '15 at 14:40
  • 1
    Nope, I meaned another thing. I put into value default value from billing address. At this moment quote don't have shipping address!!! Once you jump to shipping information your address will be saved – zhartaunik May 8 '15 at 15:33
  • Thanks zhartaunik. It doesn't solve my initial question but its a nice work around! Probably I will have to go with this. Thanks again! – Stefan May 8 '15 at 17:14

Your Answer

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

Browse other questions tagged or ask your own question.