Magento:通过id为特定用户添加送货地址

我想为我的导入器提出一个问题。</ p>

I 我从外部数据库获得了Magento的用户ID和“名字,姓氏,街道,邮政编码,城市等”的地址。 是否有magento功能来创建一个包含这样的记录的新送货地址并将其分配给用户? 那么,Magento必须自动将它设置在数据库中,没有这种情况,我必须在数据库中进行更改,只有php Magento魔法?</ p>

谢谢</ p>
</ DIV>

展开原文

原文

I'm coming up with a question for my importer.

I've got an userid from Magento and an address like "first name, last name, street, postcode, city, etc" from my external database. Is there a magento function to create a new shipping address with a record like this and assign it to an user ? So, Magento has to set it up in database automatically, without the case, that i have to do changes in the database, only php Magento magic ?

Thank you

1个回答



Magento允许为客户保存多个地址。 所以你不需要对数据库进行任何更改。 </ p>

如果您想在结帐时保存地址,请执行以下操作。 假设您的customerId为10,您可以通过以下方式保存送货地址:</ p>

  $ customerId = 10; 
$ addressArray = Array('prefix'=&gt;'',

'firstname'=&gt;'名字',
'姓氏'=&gt;'姓氏',
'后缀'=&gt;'',
'公司'=&gt;'公司',
' street'=&gt; array('Address1','Address2','Address3'),
'city'=&gt;'City',
'region'=&gt;'State',
'country_id'= &gt;'cc',
'邮政编码'=&gt;'ZIP',
'电话'=&gt;'PhoneNum',
'传真'=&gt;'FaxNum');

$ shippingAddress = Mage :: getModel('customer / address')

  • &gt; setData($ addressArray)
  • &gt; setCustomerId($ customerId)
  • &gt; setSaveInAddressBook('1');

    $ shippingAddress = $ quote-&gt; getShippingAddress()

  • &gt; setShouldIgnoreValidation(true)

  • &gt; addData($ shippingAddress);
    </ code> </ pre>

    你 可以在不同地址的代码上面循环。 如果此地址是您的默认发货地址,您可以通过以下代码将其设为默认地址:</ p>

      $ addressArray ['is_default_shipping'] = 1; 
    </ code> </ pre >

    祝你好运!</ p>
    </ div>

展开原文

原文

Magento allows saving multiple address for a customer. So you don't need any changes on database.

If you want to save address during checkout just do it like. Assuming your customerId is 10, you can save shipping address in following way:

$customerId = 10;
$addressArray = Array('prefix' => '',
            'firstname' => 'Firstname',
            'lastname' => 'Lastname',
            'suffix' => '',
            'company' => 'Company',
            'street' => array('Address1', 'Address2', 'Address3'),
            'city' => 'City',
            'region' => 'State',
            'country_id' =>  'cc',
            'postcode' => 'ZIP',
            'telephone' => 'PhoneNum',
            'fax' => 'FaxNum');

$shippingAddress =  Mage::getModel('customer/address')
                    ->setData($addressArray)
                    ->setCustomerId($customerId)
                    ->setSaveInAddressBook('1');

$shippingAddress = $quote->getShippingAddress()
            ->setShouldIgnoreValidation(true)
            ->addData($shippingAddress);

You can loop above code for different address. If this address is your default shipping, you can make it default by following code:

$addressArray['is_default_shipping'] = 1;

Good luck!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐