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!

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

报告相同问题?