Attribute in Magento is like a property. All Products, Categories, Orders, Customers, etc. have attributes. For example, the attribute of a product is its name, sku, description, image, etc.<?php
require_once '../app/Mage.php';
Mage::app();
//header("Content-Type: application/json");
?>
<?php
if($_REQUEST['prodid']!='')
{
$productId=$_REQUEST['prodid'];
$store = Mage::app()->getDefaultStoreView();
$storeId = $store->getStoreId();
$product = Mage::getModel('catalog/product')->load($productId);
$product->setStoreId($storeId);
$attributes = $product->getAttributes();
//print_r($attributes);
// get all attributes of a product
/*foreach($attributes as $attribute){
echo $attributeCode = $attribute->getAttributeCode();
echo $label = $attribute->getStoreLabel($product);
echo $value = $attribute->getFrontend()->getValue($product);
echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";
}
*/
//get only frontend attributes of a product
$i=0;
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront()) {
$attributeCode = $attribute->getAttributeCode();
$label = $attribute->getFrontend()->getLabel($product);
$value = $attribute->getFrontend()->getValue($product);
echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";
$prodattribute[$i]=array("attributeCode"=>$attributeCode,"label"=>$label,"value"=>$value);
$i++;
}
}
$productdetail=array("productId"=>$productId,"productAttribute"=>$prodattribute);
$data['responseCode']="1";
$data['msg']="successful";
$data['result']=$productdetail;
}
else
{
$data['responseCode']="0";
$data['msg']="failed";
}
$data2 = json_encode($data);
echo $data2;
?>
require_once '../app/Mage.php';
Mage::app();
//header("Content-Type: application/json");
?>
<?php
if($_REQUEST['prodid']!='')
{
$productId=$_REQUEST['prodid'];
$store = Mage::app()->getDefaultStoreView();
$storeId = $store->getStoreId();
$product = Mage::getModel('catalog/product')->load($productId);
$product->setStoreId($storeId);
$attributes = $product->getAttributes();
//print_r($attributes);
// get all attributes of a product
/*foreach($attributes as $attribute){
echo $attributeCode = $attribute->getAttributeCode();
echo $label = $attribute->getStoreLabel($product);
echo $value = $attribute->getFrontend()->getValue($product);
echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";
}
*/
//get only frontend attributes of a product
$i=0;
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront()) {
$attributeCode = $attribute->getAttributeCode();
$label = $attribute->getFrontend()->getLabel($product);
$value = $attribute->getFrontend()->getValue($product);
echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";
$prodattribute[$i]=array("attributeCode"=>$attributeCode,"label"=>$label,"value"=>$value);
$i++;
}
}
$productdetail=array("productId"=>$productId,"productAttribute"=>$prodattribute);
$data['responseCode']="1";
$data['msg']="successful";
$data['result']=$productdetail;
}
else
{
$data['responseCode']="0";
$data['msg']="failed";
}
$data2 = json_encode($data);
echo $data2;
?>
EmoticonEmoticon