I need to get the simple product of a configurable product in the cart. Right now I am getting the configurable product. Thank you.
3 Answers
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()
}
}
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
-
I'm only trying to get a single configured product, not all associated products. Oct 27, 2014 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, 2014 at 13:19
-
go from configurable product -> simple product. not simple product -> configurable product Oct 27, 2014 at 13:30
-
1Could you please explain a bit what exactly you want to achieve to do? Oct 27, 2014 at 13:32
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'