tags:

views:

94

answers:

1

Hello,

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

    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();
}

Any help would be much appreciated.

+1  A: 

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.

Joseph Mastey