How to retrieve the SKU of the first simple product for a configurable product
-
13-04-2021 - |
質問
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()
所属していません magento.stackexchange