duanqun9740 2014-05-26 12:51
浏览 42
已采纳

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

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条回答

  • dongqing7789 2014-05-26 14:14
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题