情况:以访客身份结帐(数据库中没有客户帐单地址)。
问题:如何使用来自 url 或 session 的变量自动填写帐单地址表?
对我来说完美的解决方案是:
尽可能少地改变,例如在这个文件中
app/design/frontend/default/my_theme_name/template/persistent/checkout/onepage/billing.phtml
并以这种方式访问变量
$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();