1

I'am using Magento 1.9. I have to make return process in magento.

For that I'm listing all items of order. But for the configurable product I need to take the ID of the simple product to make the return request, since I need to process the return request for corresponding simple product.

Using the below code all the configurable items. But I could not get the actual simple product related with that item.

foreach ($orderItems as $item){

if ($item->getParentItemId())
   continue;
   $productId = $item->getProductId(); //It gives only the configurable product Id
if ( $item->getProductType() == 'configurable' ) {
    $productId = $item->getOptionByCode('simple_product')->getProduct()->getId(); // It is not working
            }
    }

Can anyone help on this?

1 Answer 1

2

Try this

$OrderNumber = "100000201";//Put your order Number here

$order = Mage::getModel('sales/order')->load($OrderNumber, 'increment_id');

$order->getAllVisibleItems();


$orderItems = $order->getItemsCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('product_type', array('eq'=>'simple'))
    ->load();

foreach($orderItems as $sItem) {

    //Ignore conf for now
    //Alt. Mage_Catalog_Model_Product_Type::TYPE_SIMPLE = 'simple';
    if($sItem->getProductType() == "simple")
    {



        echo "\n*********************************\nMage Order #: ".$OrderNumber."<br/>";
        //Simple Item Info from Order
        echo "Type: ".$sItem->getProductType()."<br/>";
        echo "Order Id: ".$sItem->getOrderId()."<br/>";
        echo "Product Id: ".$sItem->getProductId()."<br/>";
        echo "Item Id: ".$sItem->getId()."<br/>";
        echo "Item Name: ".$sItem->getName()."<br/>";
        echo "Item Sku: ".$sItem->getSku()."<br/>";
        echo "Item Price: ".$sItem->getPrice()."<br/>";

        $pItemId = $sItem->getParentItemId();
        echo "Parent Item Id: ".$pItemId."<br/>";

        echo "<br/>*****<br/>";
        //Get Parent Item Information
        $item = Mage::getModel('sales/order_item')->load("$pItemId"); //use an item_id here

        //Testing, want to see whats inside the parent/configurable item?
        //print_r($item->toArray());

        echo "Parent Type: ".$item->getProductType()."<br/>";
        echo "Parent Order Id: ".$item->getOrderId()."<br/>";
        echo "Product Id: ".$item->getProductId()."<br/>";
        echo "Item Id: ".$item->getId()."<br/>";
        echo "Parent Item Price: ".$item->getPrice()."<br/>";
        echo "Qty: ".$qty = intval($item->getQtyOrdered())."<br/>";

        //get Active Product Data
        $nProduct = Mage::getModel('catalog/product')->load($sItem->getProductId());
        $nSku = $nProduct->getSku();
        echo "new Product UPC:".$nUpc = $nProduct->getUpc() . "<br/>";
        echo "new Product Price:".$nPrice = $nProduct->getPrice(). "<br/>";

        }
    }   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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