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

时间:2013-01-01 08:17:35

标签: php magento

我正在尝试从旧网站将客户导入我的新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']此字段包含我还有城市,州,邮政编码的街道地址

如何了解如何将我的客户地址设置为默认结算或送货地址..

1 个答案:

答案 0 :(得分:9)

我在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());
}