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!

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

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划