php - Magento 以编程方式创建一个 sales/quote_address 对象

标签 php magento

我在创建 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/

相关文章:

php - 使用准备好的语句执行类似于 "mysqli_fetch_array"的操作。 PHP MYSQL

php - 电子邮件被放入垃圾邮件 - 错误的 header 问题

Magento:在结构 block "content"末尾添加内容 block

php - 您使用 symfony 2.0 的体验

php - 如何在 PHP 后台运行 cURL 请求?

javascript - (JavaScript) 尝试通过复选框调用方法

php - Magento - 继续到主题中的结帐按钮位置

复制站点后 Magento 重定向到旧 URL

php - Magento 网格 : Better way of using addColumn Actions?

php - 结账时更新购物车商品价格