Magento自动填写账单地址表单通过url或会话时结帐为客人


Magento auto fill out billing address form via url or session when checkout as guest

情况:以客户身份结帐(数据库中没有客户账单地址)。

问题:如何使用url或session中的变量自动填写账单地址表单?

对我来说完美的解决方案是:

  1. 尽量少修改,例如在这个文件

    app/设计/前端/违约/my_theme_name/模板/持久/付款/onepage/billing.phtml

  2. 并以这种方式访问变量

    $ this→getAddress()→getName ();

我的临时解决方案:

/* 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();
$this
->setBillingAddress(Mage::getSingleton('sales/quote_address')
->importCustomerAddress($customAddress));

不要在这里使用"$this",它必须是报价对象(Mage_Sales_Model_Quote)而不是计费块(Mage_Checkout_Block_Onepage_Billing)。使用$this->getQuote()