Question

I am trying to retrieve the SKU of the first simple product of configurable product as soon as a certain SKU type is found to be "configurable" type. The code below helps find out if the main SKU is configurable or not. I need to find out the SKU of the first simple product of this configurable product. Please advice.

if($_product->getTypeId() == 'configurable'){
 echo 'This is a configurable product';
 // I need to retrieve the SKU of the first simple product for this configurable product and return the SKU
}else{
 echo 'This is not a configurable product';
}
Était-ce utile?

La solution

You should be able to use this:

$_product->getTypeInstance()->getUsedProductCollection($_product)->getFirstItem()->getSku()
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top