Magento 1.8 – Get ID of Simple Product from Configurable Product in Cart

configurable-productmagento-1.8

I am working with configurable product, I want simple product id of configurable product on cart.phtml, I am using this code

 <?php foreach($this->getItems() as $_item): ?>
$_product = $_item->getProduct();
echo $_product->getId();
 <?php endforeach ?>

but it always gives main product id, but I need its simple product id , any one help please.

Best Answer

In quote item table magento have sku and product id. For Configurable product's cart , 'sku' is simple product sku and product id is configurable product 'id'. SO, you need to load product by sku

<?php foreach($this->getItems() as $_item): ?>
 $_Configproduct = $_item->getProduct();
 $simpleProduct=Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku());
echo $simpleProduct->getId();
<?php endforeach ?