php Magento:添加客户默认帐单地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14108956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:39:38  来源:igfitidea点击:

Magento : Add customer default billing address

phpmagento

提问by ravisoni

I am trying to import the customers into my new magento installation from an old site and want to set customer address as magento customer default billing address i hvae tried

我正在尝试将客户从旧站点导入到我的新 magento 安装中,并希望将客户地址设置为我尝试过的 magento 客户默认帐单地址

$customer = $this->getCustomerModel();
$address = Mage::getModel('customer/address');
$customer->addAddress($results[0]['address']); //this says trying to save invalide object
$address ->addAddress($results[0]['address']); //this says undefined method

$results[0]['address'] this field contains the street address i have also the city,state, zip,postcode

$results[0]['address'] 此字段包含我还有城市、州、邮政编码、邮政编码的街道地址

Any idea about how can i set my customer address as its default billing or shipping address..

关于如何将我的客户地址设置为其默认帐单或送货地址的任何想法..

回答by ravisoni

Well I have found it with help of Anoop sir.

好吧,我在 Anoop 先生的帮助下找到了它。

$_custom_address = array (
    'firstname' => 'Branko',
    'lastname' => 'Ajzele',
    'street' => array (
        '0' => 'Sample address part1',
        '1' => 'Sample address part2',
    ),
    'city' => 'Osijek',
    'region_id' => '',
    'region' => '',
    'postcode' => '31000',
    'country_id' => 'HR', /* Croatia */
    'telephone' => '0038531555444',
);
$customAddress = Mage::getModel('customer/address');
//$customAddress = new Mage_Customer_Model_Address();
$customAddress->setData($_custom_address)
            ->setCustomerId($customer->getId())
            ->setIsDefaultBilling('1')
            ->setIsDefaultShipping('1')
            ->setSaveInAddressBook('1');
try {
    $customAddress->save();
}
catch (Exception $ex) {
    //Zend_Debug::dump($ex->getMessage());
}