Как программно добавить индивидуальный адрес доставки в Magento?

Исходя из этого, я хочу импортировать клиентов программно. Вот мой код

    <?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
require 'app/Mage.php';
require_once 'Zend/Crypt/Hmac.php';
Mage::app('default');

$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();

$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId($websiteId);
$customer->setStore($store);
$customer->setFirstname('fst');
$customer->setLastname('lst');
$customer->setEmail('[email protected]');
$customer->setPassword('somepassword');

$customer->save();
echo $customer->getId();

$address = Mage::getModel("customer/address");
$address->setCustomerId($customer->getId());
$address->setFirstname($customer->getFirstname());
$address->setLastname($customer->getLastname());
$address->setCountryId('US');
$address->setPostcode('31000');
$address->setCity('Osijek');
$address->setTelephone('0038511223344');
$address->setFax('0038511223355');
$address->setCompany('Inchoo');
$address->setStreet('Kersov');
$address->setIsDefaultBilling('1');
$address->setIsDefaultShipping(false);
$address->setSaveInAddressBook('1');

$address->save();

Но это создает только платежный адрес. Я хочу добавить еще один адрес и установить его для доставки.

1

Решение

Вы почти сделали это. Просто загрузите модель клиента / адреса и сохраните ее снова, но на этот раз $address->setIsDefaultBilling(false);$address->setIsDefaultShipping('1'); Это будет работать.

Проверено в magento 1.9

<?php
require_once 'app/Mage.php';
Mage::app();

$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();

$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId($websiteId);
$customer->setStore($store);
$customer->setFirstname('fst');
$customer->setLastname('lst');
$customer->setEmail('[email protected]');
$customer->setPassword('somepassword');

$customer->save();
echo $customer->getId();

$address = Mage::getModel("customer/address");
$address->setCustomerId($customer->getId());
$address->setFirstname($customer->getFirstname());
$address->setLastname($customer->getLastname());
$address->setCountryId('US');
$address->setPostcode('31000');
$address->setCity('Osijek');
$address->setTelephone('0038511223344');
$address->setFax('0038511223355');
$address->setCompany('Inchoo');
$address->setStreet('Kersov');
$address->setIsDefaultBilling('1');
$address->setIsDefaultShipping(false);
$address->setSaveInAddressBook('1');

$address->save();

$address = Mage::getModel("customer/address");
$address->setCustomerId($customer->getId());
$address->setFirstname($customer->getFirstname());
$address->setLastname($customer->getLastname());
$address->setCountryId('US');
$address->setPostcode('31000');
$address->setCity('Osijek');
$address->setTelephone('0038511223344');
$address->setFax('0038511223355');
$address->setCompany('Inchoo');
$address->setStreet('Kersov');
$address->setIsDefaultBilling(false);
$address->setIsDefaultShipping('1');
$address->setSaveInAddressBook('1');

$address->save();

die("check it!");
1

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]