I'm trying to get a SKU from the first child item of a configurable product.
For a simple product, this works fine:
$product_id = Mage::registry('current_product')->getSku();
But on a configurable product I want it to show a SKU from a child product instead (need this for a remarketing add-in).
I'll end up with code something like the following - but this seems overly complex. Can this be simplified down a bit?
if($_product->getTypeId() == "configurable") {
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$_hassku = false
foreach($simple_collection as $simple_product){
if($_hassku == "false") {
echo $simple_product->getSku()
$_hassku=="true"
}
}
} else {
$product_id = Mage::registry('current_product')->getSku();
};
If configurable, set a variable as 'false.' Do a 'foreach' - on the first one, it'll set the variable to true, and thus return only the one sku for the product.