Magento Coding Solutions

get configrable Product Combination and ther Associate Product

*********************************************************************
Custom Cod

getConfigurableAttributes.php?product=30
*********************************************************************
$_REQUEST['product']

 <?php
include "../app/Mage.php";
Mage::app();
$fileData = "<xml>";
$product = Mage::getModel("catalog/product")->load($_REQUEST['product']);
if($product->getTypeId() == "configurable"){
    $associatedProducts=$product->getTypeInstance()->getUsedProducts();
   
    $fileData.='<configuration>';
   
    $ctr = 0;
    $configurableAttributeCollection = $product->getTypeInstance()->getConfigurableAttributes();
    foreach($configurableAttributeCollection as $attribute){
        $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attribute->getProductAttribute()->getAttributeCode())->getFirstItem()->setEntity($product->getResource());
        $attributeOptions = $attributeInfo->getSource()->getAllOptions(false);
        $fileData.='<attribute id="'.$attributeInfo->getAttributeId().'" code="'.$attributeInfo->getAttributeCode().'" label="'.$attributeInfo->getFrontend()->getLabel($product).'">';
       
       
        $ctr2 = 0;
        foreach($attributeOptions as $attributeOption){
            $visible = 0;
            foreach($associatedProducts as $associatedProduct){
                if($associatedProduct[$attributeInfo->getAttributeCode()] == $attributeOption['value'] && $associatedProduct->status==1){
                    $visible = '1';
                    break;
                }
            //    $productArr .= $associatedProduct[$attributeInfo->getAttributeCode()].' == '.$attributeOption['value'];//$associatedProduct->getId();
            }
            if($visible>0){
                $fileData.='<option value="'.$attributeOption['value'].'">'. $attributeOption['label'].'</option>';
            }
        }
        $fileData .='</attribute>';
    }
    $fileData .='</configuration>';
    $fileData .='<combinations>';
    foreach($associatedProducts as $associatedProduct){
        $fileData .= '<product id="'.$associatedProduct->getId().'" price="'.$associatedProduct->getPrice().'">';
        $ctr2 = 0;
        foreach($configurableAttributeCollection as $attribute){
            $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attribute->getProductAttribute()->getAttributeCode())->getFirstItem()->setEntity($product->getResource());
            $fileData .= '<attribute id="'.$attributeInfo->getAttributeId().'" value="'.$associatedProduct[$attributeInfo->getAttributeCode()].'"></attribute>';   
        }
        $fileData .= '</product>';
    }
    $fileData.='</combinations>';
}
header('Content-type: text/xml');
echo $fileData.='</xml>';
   
?>

No comments:

Post a Comment