Magento Coding Solutions

get associative product Id by super_attribute in magento


$proIdS=120 /* Configrabel Product Id*/
$childIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($proIdS);

$asso='';
foreach($childIds[0] as $key=>$val)
{
//echo $val;
//echo "====";
$associatedProduct = Mage::getModel('catalog/product') ->load($val);
$assProduct_color=$associatedProduct->getProduct_color();
$assProduct_size=$associatedProduct->getProduct_size();
$assDecoration_type=$associatedProduct->getDecoration_type();

//echo $assDecoration_type.'===='.$assProduct_color.'==='. $assProduct_size;
//echo "<pre></br>";
$matchAss=object;
$matchAss=array('140'=>$assDecoration_type,'141'=>$assProduct_color,'142'=>$assProduct_size);

//print_r($matchAss);



$flag = true;

foreach($super_attribute as $keyAs=>$valAs){
if($valAs!=$matchAss[$keyAs]){
$flag = false;
break;
}
}
if($flag){
$asso = $val;
break;
}
}
echo $asso;

No comments:

Post a Comment