Search code examples
magento

How to find a products parent in sales order


I am getting following information using the order number. How can I find that for a product parent type product was bundle product?

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app("default");

$orderNumber = 260038;  
    
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);

    // get order item collection
$orderItems = $order->getItemsCollection();

    
    $skuQtyArray = array();
    foreach ($orderItems as $item)
    {   
       $product_id = $item->product_id;
          //**How to find here if above product's parent was a bundle product**

    }       
    
    
?>

enter image description here


Solution

  • you can check from this way

    <?php
        require_once('app/Mage.php'); //Path to Magento
        umask(0);
        Mage::app("default");
    
        $orderNumber = 260038;  
    
        $order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
    
        // get order item collection
        $orderItems = $order->getItemsCollection();
    
    
        $skuQtyArray = array();
        foreach ($orderItems as $item)
        {   
            $product_id = $item->product_id;
            $_product=Mage::getModel('catalog/product')->load($product_id);
            if ($_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
    
                echo 'Bundled';//Do your stuf here
            }
            //**How to find here if above product's parent was a bundle product**
    
        }       
    
    
    ?>