Question

I have my custom product attributes in magento.i want to set the product description dynamically.is their any way in magento so that we can find the attribute is custom created by us not by default magento.

i had searched.but not got any success.

Please Help.

Thanks in Advance.

Was it helpful?

Solution

Let's say you have an attribute with code some_code.
Here is how you can check if it's a system attribute or if it's a custom one.

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'some_code');
if ($attribute->getIsUserDefined()) {
    //then you created the attribute
}
else {
   //then it's a system attribute
}

OTHER TIPS

Use the magento soap/rest api for creating a custom attribute for Product and update with values as well,

  $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
  $sessionId = $proxy->login('apiUser', 'apiKey');

 echo "<pre>";
// Create new attribute
 $attributeToCreate = array(
"attribute_code" => "new_attribute",
"scope" => "store",
"frontend_input" => "select",
"is_unique" => 0,
"is_required" => 0,
"is_configurable" => 0,
"is_searchable" => 0,
"is_visible_in_advanced_search" => 0,
"used_in_product_listing" => 0,
"additional_fields" => array(
    "is_filterable" => 1,
    "is_filterable_in_search" => 1,
    "position" => 1,
    "used_for_sort_by" => 1
     ),
"frontend_label" => array(
    array( "store_id" => 0,"label" => "A new attribute" )
     )
   );

$attributeId = $proxy->call($sessionId,"product_attribute.create",
    array(
           $attributeToCreate
      )
    );

 // Update attribute
$attributeToUpdate = array(
"scope" => "global",
"is_unique" => 1,
"is_required" => 1,
"is_configurable" => 1,
"is_searchable" => 1,
"is_visible_in_advanced_search" => 0,
"used_in_product_listing" => 0,
"additional_fields" => array(
    "is_filterable" => 01,
    "is_filterable_in_search" => 0,
    "position" => 2,
    "used_for_sort_by" => 0
),
"frontend_label" => array(
    array(
        "store_id" => 0,
        "label" => "A Test Attribute"
    )
  )
);
$proxy->call(
 $sessionId,
 "product_attribute.update",
array(
     "new_attribute",
     $attributeToUpdate
  )
 );

I hope this will solve your problem..

You can use Magento default API to get default product list

For more details you can refer to following url:

http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.listOfAdditionalAttributes.html

Code used will be:

$proxy    =    new SoapClient('localhost/api/soap/?wsdl');
$sessionId    =    $proxy->login('apiUser', 'apiKey');
$listAttributes    =    $proxy->call($sessionId, 'product.listOfAdditionalAttributes', array( 'simple', 13 ));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top