Magento $ order-> getAllItems () returns twice the same element

I write an observer who checks every item in the order, at some point I get the items

foreach($order->getAllItems() as $item){ //do something echo $item->getSku(); } //output sku-first sku-first sku-second sku-second 

but I get twice the same item with the same sku, of course, where is the catch? perhaps in some kind of configuration file?

+6
source share
3 answers

I believe you want to use getAllVisibleItems() instead of getAllItems() .

I believe that getAllItems gets customizable along with its associated simple product.

+11
source

getAllVisibleItems parameter not working

You must use this code

 $_items = $order->getItemsCollection(); foreach ($_items as $item) { if ($item->getParentItem()) continue; //do something echo $item->getSku(); } 
+8
source

If getAllVisibleItems() does not work, make sure you use it correctly:

 $quote = Mage::getSingleton('checkout/session')->getQuote(); $cartItems = $quote->getAllVisibleItems(); foreach ($cartItems as $item) { echo $item->getQty(); } 

Source: fooobar.com/questions/430364 / ...

+2
source

Source: https://habr.com/ru/post/899967/


All Articles