I need to create an order with more than 60 products programmatically but it seems like Magento skips some(around 3 or 4) products randomly. I think it's a problem with itemsCollection of _quote but I have no idea what's wrong with my code. On repeated requests it skips different products. I disabled/deleted cache, reindexed everything. Here's a snippet of my code:
$this->_quote = Mage::getModel( 'sales/quote' );
//assign customer, address code here
foreach($products as $product){
//add custom options
$buyRequest = array(
'product_id' => $product->getId(),
'qty' => $req['Quantity']
);
$product_request = $this->_getProductRequest( $buy_request );
$quote_item = $this->_quote->addProduct( $product, $product_request );
if( is_string( $quote_item ) ) {
//code never enters this if
throw new Exception( $quote_item );
}
}
$itemsCount = count($this->_quote->getItemsCollection());
//for more than 60? items it seems like skips some products randomly
//continue with order create process
No error or exception message is generated, order gets created with success. Another strange thing is that when I use PHPStorm's debugger and place a breakpoint inside foreach, all products get added to quote without any problem. Is there some sort of asynchronousness or collection caching in quote addProduct proccess?
LE: I'm using magento 1.9