Apr 28, 2011
I've come across an interesting problem with a Magento store that deals primarily in selling configurable products. I have some code that packages up order information and sends it to an external warehouse who then fulfill the order. With this request, I'm using the increment_id as the identifier. Periodically, we ask the warehouse if the order has shipped and if they report it has, we retrieve the order in Magento via the increment_id and complete the order by creating a new shipment against it.
View 1 Replies
Now, this works fine until an order is edited. Due to Magento's handling of configurable products, editing an order involves cancelling the current order and recreating it anew with the same increment_id. Subsequently, my interactions based on the increment_id are now scuppered, since only the first (cancelled) order appears to be retrieved when I do something like this, as the increment_id is no longer unique:
$order = Mage::getModel('sales/order')->loadByIncrementId(100000001);
Ordinarily, having a duplicate increment_id is not possible, so I would have expected Magento to give preference to the 'active' order, but this is not the case. Now, I found a way to get around this with a collection:
$orders = Mage::getModel('sales/order')
However, I'd be interested to know if there's a way to get just one record back from the collection, negating the need for the foreach.