开发者

Magento programmatically creating a sales/quote_address object

I am having an issue with creating and adding sales/quote_address objects to the multishipping checkout process. Currently, whenever I create a new address object, it is just reusing the exact same object over and over; Thus, when I add items to one address, it will add them to all addresses. As a check, I put a for loop after my main loop to echo out all of the ID's of the created addresses - it always echos out the number 3. When i try to dynamically change the ID of the newly created addresses(commented out section) they won't even show up at all in the final for loop. My code is as follows:

//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);

    forea开发者_Go百科ch ($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();
}

Any help would be much appreciated.


The getSingleton method always returns the same object instance. Try changing that call to getModel and see if it doesn't fix the problem for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜