문제

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';
}
도움이 되었습니까?

해결책

You should be able to use this:

$_product->getTypeInstance()->getUsedProductCollection($_product)->getFirstItem()->getSku()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top