0

I need to get the simple product of a configurable product in the cart. Right now I am getting the configurable product. Thank you.

2

Take a look at Get Simple Product from Configurable in Cart

foreach ($cart->getQuote()->getAllVisibleItems() as $item) {
    if ($option = $item->getOptionByCode('simple_product')) {
        $simpleProduct = $option->getProduct()
    }

}
0
if($_product->getTypeId() == "configurable"):
    $conf_prod = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
    $simpleproducts = $conf_prod->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($simpleproducts as $simple_product){
        echo $simple_product->getSku();
        echo $simple_product->getName();
    }
endif;

Assuming $_product as configurable product, you can get all the associated products belonging to this particular configurable product using the above code. Thanks

4
  • I'm only trying to get a single configured product, not all associated products. Oct 27 '14 at 13:08
  • $simpleProductId = 4; $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable') ->getParentIdsByChild($simpleProductId); $product = Mage::getModel('catalog/product')->load($parentIds[0]); echo $product->getId(); Oct 27 '14 at 13:19
  • go from configurable product -> simple product. not simple product -> configurable product Oct 27 '14 at 13:30
  • 1
    Could you please explain a bit what exactly you want to achieve to do? Oct 27 '14 at 13:32
0

Magento is save simple product sku and configurable product id when it cart configurable product. Simple Product sku by $_item->getSku();

You can get cart simple product details by load of product model

$SimpleProduct=Mage::getModel('catalog/product')->loadByAttribute('sku',$_item->getSku());

Configurable product by $_item->getProduct()

$ConfigurableProduct=Mage::getModel('catalog/product')->load($_item->getProduct()->getId());



$_item->getProduct()->getTypeId=='configurable'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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