开发者

Magento programmatically creating a sales/quote_address object

开发者 https://www.devze.com 2023-01-10 20:47 出处:网络
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 obj

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

精彩评论

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