php - Magento : Add customer default billing address

标签 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'] 该字段包含街道地址,我还有城市、州、 zip 、邮政编码

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

最佳答案

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

关于php - Magento : Add customer default billing address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14108956/

相关文章:

PHP snmpwalk() : No response, 通过腻子工作

php - sql语句中的变量

php - 扩展 Magento API - 无效路径

magento - css 在 magento 2 购物车页面中不起作用

php - 如何使用 php jquery 制作高效的通知生成器

php - 如何编写查询以抑制结果集列中的连续重复值?

php - 将时间转换为总小时数并使用 php 从 mysql 数据计算

magento - 如何删除 Magento 订单和返回页面

php - 以编程方式将礼品消息设置为现有订单

magento - SQLSTATE[23000] : Integrity constraint violation: 1062 Duplicate entry '3262-1' for key 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID'