Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

order item getProduct() returns null
 
ykidwaiiparcel
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2012-07-26
 

This has had me stuck for a while now. Anyway, in an attempt to determine if an item in an order is a configurable product, I’m using

foreach($order->getAllItems() as $item)
{
 
if($item->getProduct()->isConfigurable()){
//code here
}
}

The problem is, getProduct seems to be null, because I’m getting an error that isConfigurable is being called on a null object. What’s wrong here? Is it something strange about the catalog?

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagikMahesh
Member
 
Total Posts:  36
Joined:  2012-04-10
 


To check whether your product is configurable or not,
I use the following code on order collection.

foreach($orders as $order{
        $items 
$order->getAllVisibleItems();
        foreach(
$items as $item{
            $pid 
$item->getProductId();
            
$_product Mage::getModel(\'catalog/product\')->load($pid);
            if(
$_product -> isConfigurable())
                       echo 
\'yes\'// your code
            
else echo \'no\';
        
}        
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
MagikMahesh
Member
 
Total Posts:  36
Joined:  2012-04-10
 


To check whether your product is configurable or not,
I use the following code on order collection.

foreach($orders as $order{
        $items 
$order->getAllVisibleItems();
        foreach(
$items as $item{
            $pid 
$item->getProductId();
            
$_product Mage::getModel(\'catalog/product\')->load($pid);
            if(
$_product -> isConfigurable())
                       echo 
\'yes\'// your code
            
else echo \'no\';
        
}        
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
ykidwaiiparcel
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2012-07-26
 

Thank you for the replies. It seems that getProduct() is a newer function and won’t work on older installs. I’m using a solution similar to yours.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top