2013-02-28 49 views
0

情況:作爲訪客結帳(數據庫中沒有客戶帳單地址)。Magento自動通過網址或會話結帳作爲訪客填寫帳單地址表格

問題:如何使用url或會話中的變量自動填寫帳單地址表單?

完美的解決辦法是:

  1. 變化儘可能少的例如在這個文件中

    應用程序/設計/前端/默認/ my_theme_name /模板/永久/結算/ onepage/billing.phtml

  2. 和訪問變量這樣

    $此 - >的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(); 
+0

所以你想自動填寫一個地址,他們還沒有提供? – 2013-02-28 00:52:58

+0

準確。你有線索如何解決這個問題? – rafis 2013-02-28 09:21:20

回答

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

做沒有用"$this"這必須是一個引用對象(Mage_Sales_Model_Quote),而不是一個開票凍結(Mage_Checkout_Block_Onepage_Billing)。使用$this->getQuote()

相關問題