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

rav*_*oni 2 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
Run Code Online (Sandbox Code Playgroud)

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

有关如何将我的客户地址设置为其默认结算或送货地址的任何想法..

rav*_*oni 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());
}
Run Code Online (Sandbox Code Playgroud)

  • aaand这里是链接:http://inchoo.net/ecommerce/magento/programming-magento/programatically-create-customer-and-order-in-magento-with-full-blown-one-page-checkout-process-under -the-罩/ (8认同)