0

in /app/design/frontend/base/default/template/email/order/items/order/default.phtml

my new order email lists the configurable products the customer has ordered

I want to output the product id of the product that was selected, however:

$_item->getProductId()

gives me the configurable product ID and not the child (simple) product that was chosen by the customer.

in the basket, I did this:

$product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
if($product->getTypeId() == "configurable")
{
  $product = Mage::getModel('catalog/product')->load($_item->getOptionByCode('simple_product')->getProductId());  
} 
echo $product->getId() ;

but on this page i get:

Fatal error: Call to a member function getProductId() on a non-object

2 Answers 2

2

Managed to fix this with:

$product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
if($product->getTypeId() == "configurable")
{
  $options = $_item->getProductOptions() ;
  $sku = $options['simple_sku'] ;
  $productid = Mage::getModel('catalog/product')->getIdBySku($sku);
  $product = Mage::getModel('catalog/product')->load($productid) ;
}
2
  • Good to know, probably you should verify your answer, so that anybody in future may know Commented Jun 12, 2014 at 13:18
  • how do you mean "verify"? I can't mark as accepted answer for another 2 days.
    – Trev
    Commented Jun 12, 2014 at 15:26
0
if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($simple_collection as $simple_product){
        echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
    }
endif;
1
  • 1
    thanks, that prints out the simple products for the main product, but I only need the simple product purchased by the customer
    – Trev
    Commented Jun 12, 2014 at 11:49

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.