gpt4 book ai didi

php - 如何在 Magento 中以编程方式添加个人送货地址?

转载 作者:行者123 更新时间:2023-11-28 23:20:17 25 4
gpt4 key购买 nike

从根本上说,我想以编程方式导入客户。这是我的代码。

    <?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('fst@ex.com');
$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->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('fst@ex.com');
$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!");

关于php - 如何在 Magento 中以编程方式添加个人送货地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42004528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com