Question

I am trying to get order item id by going over all items present in the order with getAllItems(). The problem is I am getting only the simple product even though the product has a parent item (double checked with $item->getParentItemId()). Even when I try getAllVisibleItems() I only get the simple product.
I can see that only the configurable product is visible, so I am obviously selecting the configurable product when placing order.

Also, is it possible to have a simple product which is visible individually and also associated with a grouped/configurable product? This is unrelated to the rest of the post but I will appreciate any help here as well.

This is the code:

foreach ($order->getAllVisibleItems() as $item) 
    {
        $k++;
        $productId = $item->getProductId();
        $product     = Mage::getModel('catalog/product')->load($productId);

        Mage::log($k.")".$product->getTypeId()." and id is ".$item->getId(), null, "MODB.log");
        if( $product->getTypeId() == 'simple' ){

            if ($item->getData('row_total_incl_tax') != null){
            $price = $item->getData('row_total_incl_tax');
            }

        if (!$item->getParentItemId){ //get simple prods data;}
        else{//get parent prods data;}.......
Was it helpful?

Solution

I think you are misunderstanding getAllVisibleItems method, and what it does.

Have a look at the method Mage_Sales_Model_Order::getAllVisibleItems() code

public function getAllVisibleItems()
    {
        $items = array();
        foreach ($this->getItemsCollection() as $item) {
            if (!$item->isDeleted() && !$item->getParentItemId()) {
                $items[] =  $item;
            }
        }
        return $items;
    }

As you can see, it has nothing to do with the admin product setting of 'is not visible individually', which is related to how a product will appear in the frontend display of your catalog.

In regards to your other question, yes, a product can be attached to a parent, and also still appear as an individual product in your catalog.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top