2

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;}.......
2

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.

  • Thanks for answering the second question. As for the first, why am I getting a simple product when it does have a parent? And more importantly, why am I not getting the configurable product – RBS Dec 8 '14 at 22:44
  • I have edited the question now. Should have phrased it better – RBS Dec 8 '14 at 22:46
  • Well, if there is a simple product which is associated with some product and is also individually visible, I won't be able to get it with getAllVisibleItems(). I will have to change my code a little. – RBS Dec 8 '14 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.