我在创建 sales/quote_address 对象并将其添加到多运结账流程时遇到问题。目前,每当我创建一个新的地址对象时,它只是一遍又一遍地重复使用完全相同的对象;因此,当我将项目添加到一个地址时,它会将它们添加到所有地址。作为检查,我在主循环之后放置了一个 for 循环以回显所有已创建地址的 ID - 它总是回显数字 3。当我尝试动态更改新创建地址的 ID 时(注释掉的部分) 它们甚至不会出现在最终的 for 循环中。我的代码如下:
//dynamically create the addresses and add them to the shipping information screen
$idCounter = 1;
foreach($dropshippersCombineWProducts as $dropshippersWCProducts) {
$newAddress = null;
$newAddress = Mage::getSingleton('sales/quote_address')->importCustomerAddress($customAddress);
//$idCounter++;
//$newAddress->setId($idCounter);
foreach ($newAddress->getItemsCollection() as $item) {
$item->isDeleted(true);
}
foreach ($dropshippersWCProducts[1] as $_item) {
$newAddress->addItem($_item);
}
$quote->setShippingAddress($newAddress);
$newAddress->collectShippingRates();
}
$addresses = $quote->getAllShippingAddresses();
foreach ($addresses as $address) {
echo $address->getId();
}
如有任何帮助,我们将不胜感激。
最佳答案
getSingleton
方法总是返回相同的对象实例。尝试将该调用更改为 getModel
,看看它是否不能为您解决问题。
关于php - Magento 以编程方式创建一个 sales/quote_address 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3415297/