Configurable associative product API magento

Configurable associative product API magento

Configurable associative product API magento
<?php
error_reporting(0);
include("../app/Mage.php");
umask(0);
Mage::app();
$result_array = array();
$result_array_associated = array();
$productid=$_POST["productid"];
$store=$_POST["store_id"];
if(isset($store) || is_numeric($store)){
$current_currency_code=Mage::app()->getStore($store)->getCurrentCurrencyCode();
$currency_code=$current_currency_code;
}
else
{
$currency_code = Mage::app()->getStore()->getBaseCurrencyCode();
}
$base_currency_code=Mage::app()->getStore()->getBaseCurrencyCode();
if($productid=="" or $productid=="0")
{
$result_array["message"]="please insert configuration product id !!";
$result_array["status"]="2";
echo json_encode($result_array);
exit();
}
else
{
$_product = Mage::getModel('catalog/product')->load($productid);
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($simple_collection as $simple_product){
$result_array_associated["product_id"]= $simple_product->getId();
$result_array_associated["product_name"]=$simple_product->getName();
$result_array_associated["product_image"]=$simple_product->getImageUrl();
$result_array_associated["product_small_image"]=$simple_product->getSmallImageUrl();
$result_array_associated["product_thumbnail_image"]=$simple_product->getThumbnailUrl();
$product_regular_price=$simple_product->getPrice();
$result_array_associated["currency_code"]=$currency_code = $currency_code;
$result_array_associated["currency_symbol"]=$currency_symbol = Mage::app()->getLocale()->currency( $currency_code )->getSymbol();
$result_array_associated["product_regular_price"]= Mage::helper('directory')->currencyConvert($product_regular_price, $base_currency_code , $currency_code);
$product_special_price=$simple_product->getSpecialPrice();
$result_array_associated["product_special_price"]=Mage::helper('directory')->currencyConvert($product_special_price, $base_currency_code , $currency_code);
$result_array_associated["sku"]=$simple_product->getSku();
$result_array_associated["product_short_description"]=htmlentities(preg_replace('/"/',' ',$simple_product->getShortDescription()));
$result_array_associated["product_long_description"]=htmlentities(preg_replace('/"/',' ',$simple_product->getDescription()));
$result_array_associated["product_qty"]=$simple_product->getStockItem()->getQty();
$result_array_associated["product_attribute"]=$color=$simple_product->getAttributeText('color');
$result_array_associated["option_id"]= $simple_product->getResource()->getAttribute(92)->getSource()->getOptionId($color);
$result_array_associated["product_type"]=$simple_product->getTypeId();
$result_array_associated["product_status"]=$simple_product->getStatus();
$result_array_associated["visibility"]= $simple_product->getVisibility();
array_push($result_array,$result_array_associated);
}
if(empty($result_array))
{
$result_array["message"]="Your Product is not Config Check again !!";
$result_array["status"]="0";
echo json_encode($result_array);
exit();
}
else
{
echo json_encode($result_array);
}
}
?>

No comments:

Powered by Blogger.