1
votes

Situation: Checkout as guest (no customer billing address in database).

Problem: How to fill out the billing address form automatically using variables from url or session?

Perfect solution for me would to be:

  1. change as less as possible e.g. in this file

    app/design/frontend/default/my_theme_name/template/persistent/checkout/onepage/billing.phtml

  2. and access variables this way

    $this->getAddress()->getName();

My temporary solution:

/* array comes from url or session */

$myAddress = array (
    'firstname' => 'John',
    'lastname' => 'Smith',
    'street' => array (
        '0' => '1st Street',
        '1' => '2056',
    ),
    'city' => 'Maspeth',
    'region_id' => '',
    'region' => '',
    'postcode' => 'NY11378',
    'country_id' => 'US',
    'telephone' => '0017183209872'
    );

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

/* $this = Mage_Checkout_Block_Onepage_Billing */

$this
    ->setBillingAddress(Mage::getSingleton('sales/quote_address')
    ->importCustomerAddress($customAddress));

/* insert value into input field */

echo $this->getBillingAddress()->getName();
1
So you want to fill out an address automagically, that they haven't provided yet?Emery King
Precisely. Have you got a clue how to resolve this?rafis

1 Answers

1
votes
$this
->setBillingAddress(Mage::getSingleton('sales/quote_address')
->importCustomerAddress($customAddress));

Do no use "$this" here it have to be a Quote object (Mage_Sales_Model_Quote) and not a Billing Block (Mage_Checkout_Block_Onepage_Billing). Use $this->getQuote().