<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mukesh Chapagain&#039;s Blog &#187; attribute</title>
	<atom:link href="http://blog.chapagain.com.np/tag/attribute/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.chapagain.com.np</link>
	<description>PHP Magento jQuery SQL Wordpress Joomla Programming &#38; Tutorial</description>
	<lastBuildDate>Tue, 07 Feb 2012 00:54:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Magento: How to search or filter by multiselect attribute in admin grid?</title>
		<link>http://blog.chapagain.com.np/magento-how-to-search-or-filter-by-multiselect-attribute-in-admin-grid/</link>
		<comments>http://blog.chapagain.com.np/magento-how-to-search-or-filter-by-multiselect-attribute-in-admin-grid/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 02:57:29 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[multiselect]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=1184</guid>
		<description><![CDATA[Suppose you have a multi select attribute and you have displayed it in admin grid. You have displayed the multi select attribute options as selection list. Now, you want to filter/search the grid by the multiselect attribute. The problem here is that the multiselect attribute value is store as comma separated value in database. When [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/' rel='bookmark' title='Permanent Link: Magento: How to get / filter all products by attribute value?'>Magento: How to get / filter all products by attribute value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-remove-list-or-grid-mode-as-display-option/' rel='bookmark' title='Permanent Link: Magento: Remove list or grid mode as display option'>Magento: Remove list or grid mode as display option</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-remove-or-rename-add-new-button-from-admin-grid/' rel='bookmark' title='Permanent Link: Magento: How to remove or rename &#8216;Add New&#8217; button from Admin Grid?'>Magento: How to remove or rename &#8216;Add New&#8217; button from Admin Grid?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/' rel='bookmark' title='Permanent Link: Magento: How to get attribute name and value?'>Magento: How to get attribute name and value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-filter-product-collection-using-2-or-more-category-filters/' rel='bookmark' title='Permanent Link: Magento: How to filter product collection using 2 or more category filters?'>Magento: How to filter product collection using 2 or more category filters?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Suppose you have a multi select attribute and you have displayed it in admin grid. You have displayed the multi select attribute options as selection list. Now, you want to filter/search the grid by the multiselect attribute.</p>
<p>The problem here is that the multiselect attribute value is store as comma separated value in database. When we send single value from the selection list, the filter doesn&#8217;t work properly.</p>
<p><span id="more-1184"></span></p>
<p>The solution is to use <strong>filter_condition_callback</strong> in <strong>addColumn</strong>.</p>
<p>Here is the code:-</p>
<pre class="brush: php; title: ; notranslate">
$this-&gt;addColumn('categories',
                array(
                    'header'=&gt; Mage::helper('mymodule')-&gt;__('Categories'),
                    'index' =&gt; 'categories',
                    'width' =&gt; '150px',
                    'type' =&gt; 'options',
                    'options' =&gt; $categories,
                    'filter_condition_callback'
                                =&gt; array($this, '_filterCategoriesCondition'),
            ));
</pre>
<p>The callback function is:-</p>
<pre class="brush: php; title: ; notranslate">
protected function _filterCategoriesCondition($collection, $column)
{
	if (!$value = $column-&gt;getFilter()-&gt;getValue()) {
		return;
	}

	$this-&gt;getCollection()-&gt;addFieldToFilter('categories', array('finset' =&gt; $value));
}
</pre>
<p>The similar thing is done in <strong>Mage_Adminhtml_Block_Cms_Block_Grid</strong> class to filter <strong>Store View</strong>.</p>
<p>Hope this helps. Thanks.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=1184&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/' rel='bookmark' title='Permanent Link: Magento: How to get / filter all products by attribute value?'>Magento: How to get / filter all products by attribute value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-remove-list-or-grid-mode-as-display-option/' rel='bookmark' title='Permanent Link: Magento: Remove list or grid mode as display option'>Magento: Remove list or grid mode as display option</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-remove-or-rename-add-new-button-from-admin-grid/' rel='bookmark' title='Permanent Link: Magento: How to remove or rename &#8216;Add New&#8217; button from Admin Grid?'>Magento: How to remove or rename &#8216;Add New&#8217; button from Admin Grid?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/' rel='bookmark' title='Permanent Link: Magento: How to get attribute name and value?'>Magento: How to get attribute name and value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-filter-product-collection-using-2-or-more-category-filters/' rel='bookmark' title='Permanent Link: Magento: How to filter product collection using 2 or more category filters?'>Magento: How to filter product collection using 2 or more category filters?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-how-to-search-or-filter-by-multiselect-attribute-in-admin-grid/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Magento: How to get / filter all products by attribute value?</title>
		<link>http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/</link>
		<comments>http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 10:10:34 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[brand]]></category>
		<category><![CDATA[manufacturer]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=1108</guid>
		<description><![CDATA[Here, I will show you how you can filter or fetch products related to any particular attribute and value. A simple scenario will be filtering products by manufacturer/brand. Suppose, I want to get all products under &#8216;Samsung&#8217; manufacturer/brand. For this, you need the attribute code and attribute value ID for which you are fetching products. [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-how-to-search-or-filter-by-multiselect-attribute-in-admin-grid/' rel='bookmark' title='Permanent Link: Magento: How to search or filter by multiselect attribute in admin grid?'>Magento: How to search or filter by multiselect attribute in admin grid?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/' rel='bookmark' title='Permanent Link: Magento: How to get attribute name and value?'>Magento: How to get attribute name and value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/' rel='bookmark' title='Permanent Link: Magento: Adding attribute from MySql setup file'>Magento: Adding attribute from MySql setup file</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/' rel='bookmark' title='Permanent Link: Magento: How to delete System Attribute?'>Magento: How to delete System Attribute?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-up-sells-cross-sells-and-related-products-are-not-showing-up/' rel='bookmark' title='Permanent Link: Magento: Up-sells, Cross-sells and Related products are not showing up'>Magento: Up-sells, Cross-sells and Related products are not showing up</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here, I will show you how you can filter or fetch products related to any particular attribute and value.</p>
<blockquote><p>
A simple scenario will be filtering products by manufacturer/brand. Suppose, I want to get all products under &#8216;Samsung&#8217; manufacturer/brand.
</p></blockquote>
<p><span id="more-1108"></span></p>
<p>For this, you need the <strong>attribute code</strong> and <strong>attribute value ID</strong> for which you are fetching products. </p>
<p>To fetch attribute name and value, you can see my previous post here:- <strong><a href="http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/">Magento: How to get attribute name and value?</a></strong></p>
<p>Now, lets move on to the code. Here is how you can do this:-</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Get all products related to any particular brand
 * Let us suppose that we are fetching the products related to 'Samsung' brand
 * Let us suppose the Manufacturer ID of Samsung = 3
 */

$manufacturerId = 3;
$attributeCode = 'manufacturer';

$products = Mage::getModel('catalog/product')
					-&gt;getCollection()
					-&gt;addAttributeToFilter($attributeCode, $manufacturerId);

// print all products
echo &quot;&lt;pre&gt;&quot;; print_r($products-&gt;getItems()); echo &quot;&lt;/pre&gt;&quot;;
</pre>
<p>Hope this helps. Thanks.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=1108&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-how-to-search-or-filter-by-multiselect-attribute-in-admin-grid/' rel='bookmark' title='Permanent Link: Magento: How to search or filter by multiselect attribute in admin grid?'>Magento: How to search or filter by multiselect attribute in admin grid?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/' rel='bookmark' title='Permanent Link: Magento: How to get attribute name and value?'>Magento: How to get attribute name and value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/' rel='bookmark' title='Permanent Link: Magento: Adding attribute from MySql setup file'>Magento: Adding attribute from MySql setup file</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/' rel='bookmark' title='Permanent Link: Magento: How to delete System Attribute?'>Magento: How to delete System Attribute?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-up-sells-cross-sells-and-related-products-are-not-showing-up/' rel='bookmark' title='Permanent Link: Magento: Up-sells, Cross-sells and Related products are not showing up'>Magento: Up-sells, Cross-sells and Related products are not showing up</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Magento: Join, filter, select and sort attributes, fields and tables</title>
		<link>http://blog.chapagain.com.np/magento-join-filter-select-and-sort-attributes-fields-and-tables/</link>
		<comments>http://blog.chapagain.com.np/magento-join-filter-select-and-sort-attributes-fields-and-tables/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 14:34:06 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=981</guid>
		<description><![CDATA[In my previous article (Magento: Very Useful Collection Functions), I had written about database interaction functions present in class Varien_Data_Collection_Db. Here, I am going to explain some database interaction functions present in the class Mage_Eav_Model_Entity_Collection_Abstract. These collection functions are very useful to select data from Magento database. We need them almost all the time for [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-how-to-filter-product-collection-using-2-or-more-category-filters/' rel='bookmark' title='Permanent Link: Magento: How to filter product collection using 2 or more category filters?'>Magento: How to filter product collection using 2 or more category filters?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-collection-functions/' rel='bookmark' title='Permanent Link: Magento: Very Useful Collection Functions'>Magento: Very Useful Collection Functions</a></li>
<li><a href='http://blog.chapagain.com.np/magento-adding-category-attributes/' rel='bookmark' title='Permanent Link: Magento: Adding category attributes'>Magento: Adding category attributes</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-search-or-filter-by-multiselect-attribute-in-admin-grid/' rel='bookmark' title='Permanent Link: Magento: How to search or filter by multiselect attribute in admin grid?'>Magento: How to search or filter by multiselect attribute in admin grid?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-sort-latest-product-by-created-date-and-new-from-date/' rel='bookmark' title='Permanent Link: Magento: Sort latest product by &#8216;created date&#8217; and &#8216;new from date&#8217;'>Magento: Sort latest product by &#8216;created date&#8217; and &#8216;new from date&#8217;</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In my previous article (<strong><a href="http://blog.chapagain.com.np/magento-collection-functions/">Magento: Very Useful Collection Functions</a></strong>), I had written about database interaction functions present in class <strong>Varien_Data_Collection_Db</strong>.</p>
<p>Here, I am going to explain some database interaction functions present in the class <strong>Mage_Eav_Model_Entity_Collection_Abstract</strong>. These collection functions are very useful to select data from Magento database. We need them almost all the time for filtering collection object.</p>
<p><span id="more-981"></span></p>
<p>Below are some of the useful functions that we use most often.</p>
<p><strong>Class: Mage_Eav_Model_Entity_Collection_Abstract</strong></p>
<p><strong>addAttributeToFilter</strong>: adds WHERE clause on $attribute specified by $condition</p>
<blockquote><p>
/**<br />
* Add attribute filter to collection<br />
*<br />
* If $attribute is an array will add OR condition with following format:<br />
* array(<br />
*     array(&#8216;attribute&#8217;=&gt;&#8217;firstname&#8217;, &#8216;like&#8217;=&gt;&#8217;test%&#8217;),<br />
*     array(&#8216;attribute&#8217;=&gt;&#8217;lastname&#8217;, &#8216;like&#8217;=&gt;&#8217;test%&#8217;),<br />
* )<br />
*<br />
* @see self::_getConditionSql for $condition<br />
* @param Mage_Eav_Model_Entity_Attribute_Interface|integer|string|array $attribute<br />
* @param null|string|array $condition<br />
* @param string $operator<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
addAttributeToFilter($attribute, $condition=null, $joinType=&#8217;inner&#8217;)
</p></blockquote>
<p><strong>addAttributeToSelect</strong>: gets the value for $attribute in the SELECT clause; specify * to get all attributes (i.e. to execute SELECT *)</p>
<blockquote><p>
/**<br />
* Add attribute to entities in collection<br />
*<br />
* If $attribute==&#8217;*&#8217; select all attributes<br />
*<br />
* @param   array|string|integer|Mage_Core_Model_Config_Element $attribute<br />
* @param   false|string $joinType flag for joining attribute<br />
* @return  Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
addAttributeToSelect($attribute, $joinType=false)
</p></blockquote>
<p>If an array is passed but no attribute code specified, it will be interpreted as a group of OR conditions that will be processed in the same way.<br />
If no attribute code is specified, it defaults to eq.</p>
<pre class="brush: php; title: ; notranslate">
$collection = Mage::getModel('catalog/product')-&gt;getCollection();

// select all attributes
$collection-&gt;addAttributeToSelect('*');

// select specific attributes
$collection-&gt;addAttributeToSelect(array('name', 'url_key', 'type_id'));

// select only those items whose status = 1
$collection-&gt;addAttributeToFilter('status', 1);

// alternative to select only those items whose status = 1
$collection-&gt;addAttributeToFilter('status', array('eq' =&gt; 1));

// using LIKE statement
$collection-&gt;addAttributeToFilter('sku', array('like' =&gt; '%CH%'));

// using IN statement,
// i.e. selecting only those items whose ID fall in the given array
$collection-&gt;addAttributeToFilter('id', array('in' =&gt; array(1, 14, 51, 52)));

// selecting only those items whose ID is greater than the given value
$collection-&gt;addAttributeToFilter('id', array('gt' =&gt; 5));

// select by date range
$collection-&gt;addAttributeToFilter('date_field', array(
    'from' =&gt; '10 September 2010',
    'from' =&gt; '21 September 2010',
    'date' =&gt; true, // specifies conversion of comparison values
    ));

// Add OR condition:
$collection-&gt;addAttributeToFilter(array(
    array(
        'attribute' =&gt; 'field_name',
        'in'        =&gt; array(1, 2, 3),
        ),
    array(
        'attribute' =&gt; 'date_field',
        'from'      =&gt; '2010-09-10',
        ),
    ));
</pre>
<p><strong>Below is the full filter condition codes with attribute code and its sql equivalent</strong></p>
<blockquote><p>
eq	:	=<br />
neq	:	!=<br />
like :	LIKE<br />
nlike :	NOT LIKE<br />
in	:	IN ()<br />
nin	:	NOT IN ()<br />
is	:	IS<br />
notnull :	IS NOT NULL<br />
null :	IS NULL<br />
moreq :	>=<br />
gt	:	><br />
lt	:	<<br />
gteq :	>=<br />
lteq :	<=<br />
finset :	FIND_IN_SET()<br />
from :	>=	 (for use with dates)<br />
to	:	<=	 (for use with dates)<br />
date :	optional flag for use with from/to to specify that comparison value should first be converted to a date<br />
datetime :	optional flag for use with from/to to specify that comparison value should first be converted to a datetime
</p></blockquote>
<p><strong>addFieldToFilter</strong>: alias for addAttributeToFilter(). This filters the database table fields.</p>
<blockquote><p>
/**<br />
* Wrapper for compatibility with Varien_Data_Collection_Db<br />
*<br />
* @param mixed $attribute<br />
* @param mixed $condition<br />
*/<br />
addFieldToFilter($attribute, $condition=null)
</p></blockquote>
<p><strong>addAttributeToSort</strong>: adds ORDER BY clause on $attribute</p>
<blockquote><p>
/**<br />
* Add attribute to sort order<br />
*<br />
* @param string $attribute<br />
* @param string $dir<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
addAttributeToSort($attribute, $dir=&#8217;asc&#8217;)
</p></blockquote>
<p><strong>addExpressionAttributeToSelect</strong>: adds SQL expression $expression, using $alias, to SELECT clause (typically containing aggregate functions such as SUM(), COUNT()); when $attribute specifies a single attribute as a string, $expression can reference the attribute as simply {{attribute}}, but when passing an array of attributes, each attribute must be referenced in $expression by the name of the specific attribute;</p>
<blockquote><p>
/**<br />
* Add attribute expression (SUM, COUNT, etc)<br />
*<br />
* Example: (&#8216;sub_total&#8217;, &#8216;SUM({{attribute}})&#8217;, &#8216;revenue&#8217;)<br />
* Example: (&#8216;sub_total&#8217;, &#8216;SUM({{revenue}})&#8217;, &#8216;revenue&#8217;)<br />
*<br />
* For some functions like SUM use groupByAttribute.<br />
*<br />
* @param string $alias<br />
* @param string $expression<br />
* @param string $attribute<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
addExpressionAttributeToSelect($alias, $expression, $attribute)
</p></blockquote>
<p><strong>groupByAttribute</strong>: adds $attribute to GROUP BY clause</p>
<blockquote><p>
/**<br />
* Groups results by specified attribute<br />
*<br />
* @param string|array $attribute<br />
*/<br />
groupByAttribute($attribute)
</p></blockquote>
<p><strong>joinAttribute</strong>: joins another entity and adds attribute from joined entity, using $alias, to SELECT clause.</p>
<p>Here are the parameters for joinAttribute function:-</p>
<p><strong>$alias</strong> = selected field name. You can keep it&#8217;s name whatever you want.</p>
<p><strong>$attribute</strong> = joined entity type code and attribute code = <strong>entity_type_code/attribute_code</strong><br />
<strong>entity_type_code</strong> is present in <strong>eav_entity_type table</strong><br />
<strong>attribute_code</strong> is present in <strong>eav_attribute table</strong><br />
attribute_code is attribute of the corresponding entity you want to select out.</p>
<p><strong>$bind</strong> = attribute code of the main entity to link to the joined entity.</p>
<p><strong>$filter</strong> = primary key for the joined entity (entity_id default)</p>
<blockquote><p>
/**<br />
* Add attribute from joined entity to select<br />
*<br />
* Examples:<br />
* (&#8216;billing_firstname&#8217;, &#8216;customer_address/firstname&#8217;, &#8216;default_billing&#8217;)<br />
* (&#8216;billing_lastname&#8217;, &#8216;customer_address/lastname&#8217;, &#8216;default_billing&#8217;)<br />
* (&#8216;shipping_lastname&#8217;, &#8216;customer_address/lastname&#8217;, &#8216;default_billing&#8217;)<br />
* (&#8216;shipping_postalcode&#8217;, &#8216;customer_address/postalcode&#8217;, &#8216;default_shipping&#8217;)<br />
* (&#8216;shipping_city&#8217;, $cityAttribute, &#8216;default_shipping&#8217;)<br />
*<br />
* Developer is encouraged to use existing instances of attributes and entities<br />
* After first use of string entity name it will be cached in the collection<br />
*<br />
* @todo connect between joined attributes of same entity<br />
* @param string $alias alias for the joined attribute<br />
* @param string|Mage_Eav_Model_Entity_Attribute_Abstract $attribute<br />
* @param string $bind attribute of the main entity to link with joined $filter<br />
* @param string $filter primary key for the joined entity (entity_id default)<br />
* @param string $joinType inner|left<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
joinAttribute($alias, $attribute, $bind, $filter=null, $joinType=&#8217;inner&#8217;, $storeId=null)
</p></blockquote>
<p><strong>joinTable</strong>: joins table $table</p>
<p>Here are the parameters of the function joinTable:-</p>
<p>$table = table name to join<br />
$bind = ( parent_key = foreign_key )<br />
$fields = array of fields to select<br />
$cond = where condition<br />
$joinType = join type</p>
<blockquote><p>
/**<br />
* Join a table<br />
*<br />
* @param string|array $table<br />
* @param string $bind<br />
* @param string|array $fields<br />
* @param null|array $cond<br />
* @param string $joinType<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
joinTable($table, $bind, $fields=null, $cond=null, $joinType=&#8217;inner&#8217;)
</p></blockquote>
<p><strong>Using joinAttribute and joinTable</strong></p>
<p>In the code below, all order invoice items are selected, i.e. all products that have been invoiced.<br />
joinTable is used to join sales_order_entity table to fetch increment_id and store_id of the invoice for each product.<br />
joinAttribute is used to fetch order_id, product_name, and store_id.<br />
joinTable is used again to fetch the order status of each invoice item.</p>
<pre class="brush: php; title: ; notranslate">
$collection = Mage::getModel('sales/order_invoice_item')
					-&gt;getCollection()
					-&gt;joinTable('sales_order_entity', 'entity_id=parent_id', array('invoice_id'=&gt;'increment_id', 'store_id' =&gt; 'store_id'), null , 'left')
					-&gt;joinAttribute('order_id', 'invoice/order_id', 'parent_id', null, 'left')
					-&gt;joinAttribute('product_name', 'invoice_item/name', 'entity_id', null, 'left')
					-&gt;joinAttribute('store_id', 'invoice/store_id', 'parent_id', null, 'left')

					-&gt;joinTable('sales_order', 'entity_id=order_id', array('order_status'=&gt;'status'), null , 'left')
					;
</pre>
<p><strong>joinField</strong>: joins regular table field using an attribute as foreign key</p>
<blockquote><p>
/**<br />
* Join regular table field and use an attribute as fk<br />
*<br />
* Examples:<br />
* (&#8216;country_name&#8217;, &#8216;directory/country_name&#8217;, &#8216;name&#8217;, &#8216;country_id=shipping_country&#8217;, &#8220;{{table}}.language_code=&#8217;en&#8217;&#8221;, &#8216;left&#8217;)<br />
*<br />
* @param string $alias &#8216;country_name&#8217;<br />
* @param string $table &#8216;directory/country_name&#8217;<br />
* @param string $field &#8216;name&#8217;<br />
* @param string $bind &#8216;PK(country_id)=FK(shipping_country_id)&#8217;<br />
* @param string|array $cond &#8220;{{table}}.language_code=&#8217;en&#8217;&#8221; OR array(&#8216;language_code&#8217;=&gt;&#8217;en&#8217;)<br />
* @param string $joinType &#8216;left&#8217;<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
joinField($alias, $table, $field, $bind, $cond=null, $joinType=&#8217;inner&#8217;)
</p></blockquote>
<p><strong>removeAttributeToSelect</strong>: removes $attribute from SELECT clause; specify null to remove all attributes</p>
<blockquote><p>
/**<br />
* Remove an attribute from selection list<br />
*<br />
* @param string $attribute<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
removeAttributeToSelect($attribute=null)
</p></blockquote>
<p><strong>setPage</strong>: sets LIMIT clause by specifying page number (one-indexed) and number of records per page; equivalent to calling setCurPage($pageNum) and setPageSize($pageSize)</p>
<blockquote><p>
/**<br />
* Set collection page start and records to show<br />
*<br />
* @param integer $pageNum<br />
* @param integer $pageSize<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
setPage($pageNum, $pageSize)
</p></blockquote>
<p><strong>importFromArray</strong>: imports 2D array into collection as objects</p>
<blockquote><p>
/**<br />
* Import 2D array into collection as objects<br />
*<br />
* If the imported items already exist, update the data for existing objects<br />
*<br />
* @param array $arr<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
importFromArray($arr)
</p></blockquote>
<p><strong>exportToArray</strong>: returns collection data as a 2D array</p>
<blockquote><p>
/**<br />
* Get collection data as a 2D array<br />
*<br />
* @return array<br />
*/<br />
exportToArray()
</p></blockquote>
<p><strong>setOrder</strong>: alias for addAttributeToSort() q.v., identical except that it can accept array of attributes, and default $dir is desc</p>
<blockquote><p>
/**<br />
* Set sorting order<br />
*<br />
* $attribute can also be an array of attributes<br />
*<br />
* @param string|array $attribute<br />
* @param string $dir<br />
* @return Mage_Eav_Model_Entity_Collection_Abstract<br />
*/<br />
setOrder($attribute, $dir=&#8217;desc&#8217;)
</p></blockquote>
<blockquote><p>Inspired by Magento Wiki:<br />
<a href="http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/using_collections_in_magento" rel="nofollow" target="_blank">http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/using_collections_in_magento</a>.<br />
However, more of my code, text &#038; understanding are added in this article.
</p></blockquote>
<p>Hope this helps. Thanks.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=981&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-how-to-filter-product-collection-using-2-or-more-category-filters/' rel='bookmark' title='Permanent Link: Magento: How to filter product collection using 2 or more category filters?'>Magento: How to filter product collection using 2 or more category filters?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-collection-functions/' rel='bookmark' title='Permanent Link: Magento: Very Useful Collection Functions'>Magento: Very Useful Collection Functions</a></li>
<li><a href='http://blog.chapagain.com.np/magento-adding-category-attributes/' rel='bookmark' title='Permanent Link: Magento: Adding category attributes'>Magento: Adding category attributes</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-search-or-filter-by-multiselect-attribute-in-admin-grid/' rel='bookmark' title='Permanent Link: Magento: How to search or filter by multiselect attribute in admin grid?'>Magento: How to search or filter by multiselect attribute in admin grid?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-sort-latest-product-by-created-date-and-new-from-date/' rel='bookmark' title='Permanent Link: Magento: Sort latest product by &#8216;created date&#8217; and &#8216;new from date&#8217;'>Magento: Sort latest product by &#8216;created date&#8217; and &#8216;new from date&#8217;</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-join-filter-select-and-sort-attributes-fields-and-tables/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Magento: Adding category attributes</title>
		<link>http://blog.chapagain.com.np/magento-adding-category-attributes/</link>
		<comments>http://blog.chapagain.com.np/magento-adding-category-attributes/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 08:30:58 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[category]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=821</guid>
		<description><![CDATA[Here, I will be showing you how you can add attributes for your categories in Magento. From the admin panel, you can only add attributes to product. To add attributes to category, you need to write sql query in your phpmyadmin or a better way would be creating a new custom module and adding attributes [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/' rel='bookmark' title='Permanent Link: Magento: Adding attribute from MySql setup file'>Magento: Adding attribute from MySql setup file</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-filter-product-collection-using-2-or-more-category-filters/' rel='bookmark' title='Permanent Link: Magento: How to filter product collection using 2 or more category filters?'>Magento: How to filter product collection using 2 or more category filters?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-category-name-and-url-from-product/' rel='bookmark' title='Permanent Link: Magento: Get category name and url from product'>Magento: Get category name and url from product</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-current-and-parent-category/' rel='bookmark' title='Permanent Link: Magento: Get current and parent category'>Magento: Get current and parent category</a></li>
<li><a href='http://blog.chapagain.com.np/magento-1-4-no-products-displayed-in-category-listing/' rel='bookmark' title='Permanent Link: Magento 1.4: No products displayed in category listing'>Magento 1.4: No products displayed in category listing</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here, I will be showing you how you can add attributes for your categories in Magento.</p>
<p>From the admin panel, you can only add attributes to product. To add attributes to category, you need to write sql query in your phpmyadmin or a better way would be creating a new custom module and adding attributes to category from the mysql setup file of the module.</p>
<p>By mysql setup file, I mean the file inside the directory <strong>YourNamespace/YourModule/sql/yourmodule_setup/</strong></p>
<p><span id="more-821"></span></p>
<p>Create a new module and write the following in your module&#8217;s mysql setup file. </p>
<pre class="brush: php; title: ; notranslate">
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer-&gt;startSetup();

$setup-&gt;addAttribute('catalog_category', 'my_attribute', array(
	'group'     	=&gt; 'General',
	'input'         =&gt; 'text',
    'type'          =&gt; 'varchar',
    'label'         =&gt; 'My Attribute',
	'backend'       =&gt; '',
	'visible'       =&gt; 1,
	'required'		=&gt; 0,
	'user_defined' =&gt; 1,
    'global'        =&gt; Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$installer-&gt;endSetup();
</pre>
<p>The above code will create a category with the code &#8216;<strong>my_attribute</strong>&#8216; and lable &#8216;<strong>My Attribute</strong>&#8216;. You can view it under <strong>Admin Panel &#8211;> Catalog &#8211;> Manage Categories &#8211;> General Information</strong></p>
<p>Hope this helps. Thanks.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=821&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/' rel='bookmark' title='Permanent Link: Magento: Adding attribute from MySql setup file'>Magento: Adding attribute from MySql setup file</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-filter-product-collection-using-2-or-more-category-filters/' rel='bookmark' title='Permanent Link: Magento: How to filter product collection using 2 or more category filters?'>Magento: How to filter product collection using 2 or more category filters?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-category-name-and-url-from-product/' rel='bookmark' title='Permanent Link: Magento: Get category name and url from product'>Magento: Get category name and url from product</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-current-and-parent-category/' rel='bookmark' title='Permanent Link: Magento: Get current and parent category'>Magento: Get current and parent category</a></li>
<li><a href='http://blog.chapagain.com.np/magento-1-4-no-products-displayed-in-category-listing/' rel='bookmark' title='Permanent Link: Magento 1.4: No products displayed in category listing'>Magento 1.4: No products displayed in category listing</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-adding-category-attributes/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Magento: Get manufacturer name and id from product</title>
		<link>http://blog.chapagain.com.np/magento-get-manufacturer-name-and-id-from-product/</link>
		<comments>http://blog.chapagain.com.np/magento-get-manufacturer-name-and-id-from-product/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 07:11:33 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[manufacturer]]></category>
		<category><![CDATA[product]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=488</guid>
		<description><![CDATA[Suppose, you have the product data. You can get product from either of the following way:- $_product = $this->getProduct(); OR, $_product = Mage::getModel('catalog/product')->load(PRODUCT_ID); Now, here is the code to get manufacturer name and id. Copyright &#169; 2011 This feed is for personal, non-commercial use only. The use of this feed on other websites breaches copyright. [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-get-parent-id-of-simple-product-associated-to-configurable-product/' rel='bookmark' title='Permanent Link: Magento: Get parent id of simple product associated to configurable product'>Magento: Get parent id of simple product associated to configurable product</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-actual-price-and-special-price-of-a-product/' rel='bookmark' title='Permanent Link: Magento: How to get actual price and special price of a product?'>Magento: How to get actual price and special price of a product?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-product-stock-quantity-other-stock-information/' rel='bookmark' title='Permanent Link: Magento: How to get product stock quantity &#038; other stock information?'>Magento: How to get product stock quantity &#038; other stock information?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-list-of-all-manufacturers/' rel='bookmark' title='Permanent Link: Magento: Get list of all manufacturers'>Magento: Get list of all manufacturers</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/' rel='bookmark' title='Permanent Link: Magento: How to get / filter all products by attribute value?'>Magento: How to get / filter all products by attribute value?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Suppose, you have the product data. </p>
<p>You can get product from either of the following way:-</p>
<p><code>$_product = $this->getProduct();</code></p>
<p>OR,</p>
<p><span id="more-488"></span></p>
<p><code>$_product = Mage::getModel('catalog/product')->load(PRODUCT_ID);</code></p>
<p>Now, here is the code to get manufacturer name and id.</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Get manufacturer name
 */
$manufacturerName = $_product-&gt;getAttributeText('manufacturer');

/**
 * Get manufacturer id
 */
$manufacturerId = $_product-&gt;getManufacturer();
</pre>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=488&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-get-parent-id-of-simple-product-associated-to-configurable-product/' rel='bookmark' title='Permanent Link: Magento: Get parent id of simple product associated to configurable product'>Magento: Get parent id of simple product associated to configurable product</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-actual-price-and-special-price-of-a-product/' rel='bookmark' title='Permanent Link: Magento: How to get actual price and special price of a product?'>Magento: How to get actual price and special price of a product?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-product-stock-quantity-other-stock-information/' rel='bookmark' title='Permanent Link: Magento: How to get product stock quantity &#038; other stock information?'>Magento: How to get product stock quantity &#038; other stock information?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-list-of-all-manufacturers/' rel='bookmark' title='Permanent Link: Magento: Get list of all manufacturers'>Magento: Get list of all manufacturers</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/' rel='bookmark' title='Permanent Link: Magento: How to get / filter all products by attribute value?'>Magento: How to get / filter all products by attribute value?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-get-manufacturer-name-and-id-from-product/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Magento: Adding attribute from MySql setup file</title>
		<link>http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/</link>
		<comments>http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 08:16:36 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=379</guid>
		<description><![CDATA[You can add attribute from Admin Panel -> Catalog -> Attributes -> Manage Attributes. You can also add attributes from mysql setup file of your module. MySql setup file is present inside &#8220;YourModule/sql/yourmodule_setup&#8221; directory. In the following example, the version of my module is 0.1.0.  I have added attribute for product. I have added a [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-adding-category-attributes/' rel='bookmark' title='Permanent Link: Magento: Adding category attributes'>Magento: Adding category attributes</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/' rel='bookmark' title='Permanent Link: Magento: How to delete System Attribute?'>Magento: How to delete System Attribute?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-upgrading-mysql-setup-of-a-module/' rel='bookmark' title='Permanent Link: Magento: Upgrading mysql setup of a module'>Magento: Upgrading mysql setup of a module</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/' rel='bookmark' title='Permanent Link: Magento: How to get attribute name and value?'>Magento: How to get attribute name and value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-upload-file/' rel='bookmark' title='Permanent Link: Magento: How to upload file?'>Magento: How to upload file?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>You can add attribute from <strong>Admin Panel -> Catalog -> Attributes -> Manage Attributes</strong>.</p>
<p>You can also add attributes from mysql setup file of your module. MySql setup file is present inside &#8220;<strong>YourModule/sql/yourmodule_setup</strong>&#8221; directory.</p>
<p><span id="more-379"></span></p>
<p>In the following example, the version of my module is <strong>0.1.0</strong>.  I have added attribute for product. I have added a new Attribute Group called &#8220;<strong>Special Attributes</strong>&#8221; and then I have assigned the new attribute called &#8220;<strong>testing_attribute</strong>&#8221; into the &#8220;<strong>Special Attribute</strong>&#8221; group.</p>
<pre class="brush: php; title: ; notranslate">

// file mysql4-install-0.1.0.php

&lt;?php

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer-&gt;startSetup();
/**
 * Adding Different Attributes
 */

// adding attribute group
$setup-&gt;addAttributeGroup('catalog_product', 'Default', 'Special Attributes', 1000);

// the attribute added will be displayed under the group/tab Special Attributes in product edit page
$setup-&gt;addAttribute('catalog_product', 'testing_attribute', array(
	'group'     	=&gt; 'Special Attributes',
	'input'         =&gt; 'text',
    'type'          =&gt; 'text',
    'label'         =&gt; 'Testing',
	'backend'       =&gt; '',
	'visible'       =&gt; 1,
	'required'		=&gt; 0,
	'user_defined' =&gt; 1,
	'searchable' =&gt; 1,
	'filterable' =&gt; 0,
	'comparable'	=&gt; 1,
	'visible_on_front' =&gt; 1,
	'visible_in_advanced_search'  =&gt; 0,
	'is_html_allowed_on_front' =&gt; 0,
    'global'        =&gt; Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$installer-&gt;endSetup();
</pre>
<p>Be careful on <strong>input </strong>and <strong>type</strong>. Input means the input type of the attribute. And type means the input type in database.</p>
<p>For textfield it will be:<br />
<code>'input' => 'text',<br />
'type' => 'text',</code></p>
<p>For textarea it will be:<br />
<code>'input' => 'textarea',<br />
'type' => 'text',</code></p>
<p>For date field it will be:<br />
<code>'input' => 'date',<br />
'type' => 'datetime',</code></p>
<p>For select list it will be:<br />
<code>'input' => 'select',<br />
'type' => 'text',</code></p>
<p>Here is the sample code to add datetime attribute. Please note that the <strong>type </strong>for date should be <code>datetime </code>and <strong>backend </strong>should be <code>eav/entity_attribute_backend_datetime</code>.</p>
<pre class="brush: php; title: ; notranslate">
$setup-&gt;addAttribute('catalog_product', 'delivery_date', array(
	'group'     	=&gt; 'Special Attributes',
	'input'         =&gt; 'date',
    'type'          =&gt; 'datetime',
    'label'         =&gt; 'Delivery',
	'backend'		=&gt; &quot;eav/entity_attribute_backend_datetime&quot;,
	'visible'       =&gt; 1,
	'required'		=&gt; 0,
	'user_defined' =&gt; 1,
	'searchable' =&gt; 1,
	'filterable' =&gt; 0,
	'comparable'	=&gt; 0,
	'visible_on_front' =&gt; 1,
	'visible_in_advanced_search'  =&gt; 0,
	'is_html_allowed_on_front' =&gt; 0,
    'global'        =&gt; Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
</pre>
<h3>Adding custom options to dropdown attribute through setup file</h3>
<p>You can also add custom options to dropdown attribute, like there is in <strong>manufacturer </strong>or <strong>color </strong>attribute.</p>
<p>Here is a sample code for this purpose:-</p>
<pre class="brush: php; title: ; notranslate">
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer-&gt;startSetup();						

$setup-&gt;addAttribute('catalog_product', 'test_attribute', array(
			 'label'             =&gt; 'Test',
			 'type'              =&gt; 'varchar',
			 'input'             =&gt; 'select',
			 'backend'           =&gt; 'eav/entity_attribute_backend_array',
			 'frontend'          =&gt; '',
			 'source'            =&gt; 'yourmodule/source_option',
			 'global'            =&gt; Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
			 'visible'           =&gt; true,
			 'required'          =&gt; true,
			 'user_defined'      =&gt; true,
			 'searchable'        =&gt; false,
			 'filterable'        =&gt; false,
			 'comparable'        =&gt; false,
			 'option'            =&gt; array (
											'value' =&gt; array('optionone' =&gt; array('Sony'),
															 'optiontwo' =&gt; array('Samsung'),
															 'optionthree' =&gt; array('Apple'),
														)
										),
			 'visible_on_front'  =&gt; false,
			 'visible_in_advanced_search' =&gt; false,
			 'unique'            =&gt; false
));

$installer-&gt;endSetup();
</pre>
<p>In the code above, we have added a dropdown attribute named &#8216;<strong>Test</strong>&#8216;. Three options (<strong>Sony</strong>, <strong>Samsung</strong>, and <strong>Apple</strong>) are added to this attribute. </p>
<p><strong>Note</strong>:- In the <strong>source </strong>value, you can see <strong>yourmodule/source_option</strong>. This means, you just need to create a file <strong>YourModule/Model/Source/Option.php</strong> with the following code:-</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

class YourNamespace_YourModule_Model_Source_Option extends Mage_Eav_Model_Entity_Attribute_Source_Table
{

}
</pre>
<h3>Following are the allowed parameters for attributes</h3>
<p>:</p>
<p>(see <strong>Mage_Eav_Model_Entity_Setup::addAttribute</strong>)</p>
<pre class="brush: php; title: ; notranslate">

$data = array(
            'entity_type_id'            =&gt; $entityTypeId,
            'attribute_code'            =&gt; $code,
            'backend_model'             =&gt; $this-&gt;_getValue($attr, 'backend', ''),
            'backend_type'              =&gt; $this-&gt;_getValue($attr, 'type', 'varchar'),
            'backend_table'             =&gt; $this-&gt;_getValue($attr, 'table', ''),
            'frontend_model'            =&gt; $this-&gt;_getValue($attr, 'frontend', ''),
            'frontend_input'            =&gt; $this-&gt;_getValue($attr, 'input', 'text'),
            'frontend_input_renderer'   =&gt; $this-&gt;_getValue($attr, 'input_renderer', ''),
            'frontend_label'            =&gt; $this-&gt;_getValue($attr, 'label', ''),
            'frontend_class'            =&gt; $this-&gt;_getValue($attr, 'frontend_class', ''),
            'source_model'              =&gt; $this-&gt;_getValue($attr, 'source', ''),
            'is_global'                 =&gt; $this-&gt;_getValue($attr, 'global', 1),
            'is_visible'                =&gt; $this-&gt;_getValue($attr, 'visible', 1),
            'is_required'               =&gt; $this-&gt;_getValue($attr, 'required', 1),
            'is_user_defined'           =&gt; $this-&gt;_getValue($attr, 'user_defined', 0),
            'default_value'             =&gt; $this-&gt;_getValue($attr, 'default', ''),
            'is_searchable'             =&gt; $this-&gt;_getValue($attr, 'searchable', 0),
            'is_filterable'             =&gt; $this-&gt;_getValue($attr, 'filterable', 0),
            'is_comparable'             =&gt; $this-&gt;_getValue($attr, 'comparable', 0),
            'is_visible_on_front'       =&gt; $this-&gt;_getValue($attr, 'visible_on_front', 0),
            'is_html_allowed_on_front'  =&gt; $this-&gt;_getValue($attr, 'is_html_allowed_on_front', 0),
            'is_visible_in_advanced_search'
                                        =&gt; $this-&gt;_getValue($attr, 'visible_in_advanced_search', 0),
            'is_used_for_price_rules'   =&gt; $this-&gt;_getValue($attr, 'used_for_price_rules', 1),
            'is_filterable_in_search'   =&gt; $this-&gt;_getValue($attr, 'filterable_in_search', 0),
            'used_in_product_listing'   =&gt; $this-&gt;_getValue($attr, 'used_in_product_listing', 0),
            'used_for_sort_by'          =&gt; $this-&gt;_getValue($attr, 'used_for_sort_by', 0),
            'is_unique'                 =&gt; $this-&gt;_getValue($attr, 'unique', 0),
            'apply_to'                  =&gt; $this-&gt;_getValue($attr, 'apply_to', ''),
            'is_configurable'           =&gt; $this-&gt;_getValue($attr, 'is_configurable', 1),
            'note'                      =&gt; $this-&gt;_getValue($attr, 'note', ''),
            'position'                  =&gt; $this-&gt;_getValue($attr, 'position', 0),
        );
</pre>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=379&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-adding-category-attributes/' rel='bookmark' title='Permanent Link: Magento: Adding category attributes'>Magento: Adding category attributes</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/' rel='bookmark' title='Permanent Link: Magento: How to delete System Attribute?'>Magento: How to delete System Attribute?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-upgrading-mysql-setup-of-a-module/' rel='bookmark' title='Permanent Link: Magento: Upgrading mysql setup of a module'>Magento: Upgrading mysql setup of a module</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/' rel='bookmark' title='Permanent Link: Magento: How to get attribute name and value?'>Magento: How to get attribute name and value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-upload-file/' rel='bookmark' title='Permanent Link: Magento: How to upload file?'>Magento: How to upload file?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Magento: How to get attribute name and value?</title>
		<link>http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/</link>
		<comments>http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 09:06:12 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[attribute]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=292</guid>
		<description><![CDATA[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. This article will show you how to get attribute name and value for any product. The following code is about getting attribute collection and then fetching [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-get-list-of-all-manufacturers/' rel='bookmark' title='Permanent Link: Magento: Get list of all manufacturers'>Magento: Get list of all manufacturers</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/' rel='bookmark' title='Permanent Link: Magento: How to delete System Attribute?'>Magento: How to delete System Attribute?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-adding-category-attributes/' rel='bookmark' title='Permanent Link: Magento: Adding category attributes'>Magento: Adding category attributes</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/' rel='bookmark' title='Permanent Link: Magento: How to get / filter all products by attribute value?'>Magento: How to get / filter all products by attribute value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-parent-id-of-simple-product-associated-to-configurable-product/' rel='bookmark' title='Permanent Link: Magento: Get parent id of simple product associated to configurable product'>Magento: Get parent id of simple product associated to configurable product</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>This article will show you how to get attribute name and value for any product.</p>
<p><span id="more-292"></span></p>
<p>The following code is about getting attribute collection and then fetching that attribute&#8217;s name, value, type, and other parameters.</p>
<p><strong>Note:</strong> The attribute code in the case below is <strong>my_attribute</strong>.</p>
<pre class="brush: php; title: ; notranslate">
/**
 * get attribute collection
 */
$attribute = $_product-&gt;getResource()-&gt;getAttribute('my_attribute');
/**
 * get attribute type
 */
$attribute-&gt;getAttributeType();
/**
 * get attribute Label
 */
$attribute-&gt;getFrontendLabel();
/**
 * get attribute default value
 */
$attribute-&gt;getDefaultValue();
/**
 * check if the attribute is visible
 */
$attribute-&gt;getIsVisible();
/**
 * check if the attribute is required
 */
$attribute-&gt;getIsRequired();
/**
 * get attribute value
 */
$attributeValue = Mage::getModel('catalog/product')-&gt;load($_product-&gt;getId())-&gt;getMyAttribute();
</pre>
<p>Here is the code to fetch value from a select box attribute:-</p>
<p><strong>Note:</strong> I suppose the attribute code to be &#8216;<strong>my_attribute</strong>&#8216;</p>
<pre class="brush: php; title: ; notranslate">
$attributeValue = Mage::getModel('catalog/product')
							-&gt;load($_product-&gt;getId())
							-&gt;getAttributeText('my_attribute');
</pre>
<p><strong>Load any particular attribute by attribute code</strong></p>
<p>Here is the code to get data of any particular attribute by the attribute code.</p>
<pre class="brush: php; title: ; notranslate">
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
						-&gt;setCodeFilter(YOUR_ATTRIBUTE_CODE)
						-&gt;getFirstItem();

// echo &quot;&lt;pre&gt;&quot;; print_r($attributeInfo-&gt;getData()); echo &quot;&lt;/pre&gt;&quot;;
</pre>
<p><strong>Get all option value list for the particular attribute</strong></p>
<p>You can see above that I got attribute information by attribute code. My attribute information is stored as <strong>$attributeInfo</strong>.</p>
<p>Here is the code to get all option values for my attribute <strong>$attributeInfo</strong>.</p>
<pre class="brush: php; title: ; notranslate">
$attributeOptions = $attributeInfo-&gt;getSource()-&gt;getAllOptions(false);
// echo &quot;&lt;pre&gt;&quot;; print_r($attributeOptions); echo &quot;&lt;/pre&gt;&quot;;
</pre>
<p><strong>Get attribute&#8217;s option information by option id</strong></p>
<p>I have my attribute as <strong>$attributeInfo</strong>.<br />
I have my attribute&#8217;s option value array as <strong>$attributeOptions</strong>.</p>
<p>Suppose, I want to get detail information of any option listed in <strong>$attributeOptions</strong> array. Here is the code to do so:-</p>
<pre class="brush: php; title: ; notranslate">
$attributeId = $attributeInfo-&gt;getAttributeId();
$optionId = YOUR_ATTRIBUTE_OPTION_ID;

$attributeOptionSingle = Mage::getResourceModel('eav/entity_attribute_option_collection')
									-&gt;setPositionOrder('asc')
									-&gt;setAttributeFilter($attributeId)
									-&gt;setIdFilter($optionId)
									-&gt;setStoreFilter()
									-&gt;load()
									-&gt;getFirstItem();

// echo &quot;&lt;pre&gt;&quot;; print_r($attributeOptionSingle); echo &quot;&lt;/pre&gt;&quot;;
</pre>
<p><strong>Get attribute of particular entity type</strong></p>
<p>Here, I am going to get information about &#8216;order_id&#8217; attribute of &#8216;invoice&#8217; entity type.</p>
<pre class="brush: php; title: ; notranslate">
$entityType = Mage::getModel('eav/config')-&gt;getEntityType('invoice');
$entityTypeId = $entityType-&gt;getEntityTypeId();

$attribute = Mage::getResourceModel('eav/entity_attribute_collection')
				-&gt;setCodeFilter('order_id')
				-&gt;setEntityTypeFilter($entityTypeId)
				-&gt;getFirstItem();
</pre>
<p><strong>Get attribute options of Configurable product</strong></p>
<pre class="brush: php; title: ; notranslate">
$confAttributes = $_product-&gt;getTypeInstance(true)-&gt;getConfigurableAttributesAsArray($_product);
</pre>
<p>Hope this helps. Thanks.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=292&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-get-list-of-all-manufacturers/' rel='bookmark' title='Permanent Link: Magento: Get list of all manufacturers'>Magento: Get list of all manufacturers</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/' rel='bookmark' title='Permanent Link: Magento: How to delete System Attribute?'>Magento: How to delete System Attribute?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-adding-category-attributes/' rel='bookmark' title='Permanent Link: Magento: Adding category attributes'>Magento: Adding category attributes</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-filter-all-products-by-attribute-value/' rel='bookmark' title='Permanent Link: Magento: How to get / filter all products by attribute value?'>Magento: How to get / filter all products by attribute value?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-parent-id-of-simple-product-associated-to-configurable-product/' rel='bookmark' title='Permanent Link: Magento: Get parent id of simple product associated to configurable product'>Magento: Get parent id of simple product associated to configurable product</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Magento: How to delete System Attribute?</title>
		<link>http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/</link>
		<comments>http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 12:51:27 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[attribute]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=286</guid>
		<description><![CDATA[Suppose, you want to delete an attribute. But there is no delete option while you edit the attribute. This means that the attribute is system attribute. System attributes cannot be deleted. Only user defined attributes can be deleted. To delete the attribute, you have to make it user defined. - Go to phpmyadmin - Go [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-how-to-select-insert-update-and-delete-data/' rel='bookmark' title='Permanent Link: Magento: How to select, insert, update, and delete data?'>Magento: How to select, insert, update, and delete data?</a></li>
<li><a href='http://blog.chapagain.com.np/very-simple-add-edit-delete-display-in-php/' rel='bookmark' title='Permanent Link: Very simple add, edit, delete, display in PHP'>Very simple add, edit, delete, display in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/' rel='bookmark' title='Permanent Link: Magento: Adding attribute from MySql setup file'>Magento: Adding attribute from MySql setup file</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-delete-remove-extension-from-magentoconnect/' rel='bookmark' title='Permanent Link: Magento: How to delete / remove extension from MagentoConnect?'>Magento: How to delete / remove extension from MagentoConnect?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/' rel='bookmark' title='Permanent Link: Magento: How to get attribute name and value?'>Magento: How to get attribute name and value?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Suppose, you want to delete an attribute. But there is no delete option while you edit the attribute. This means that the attribute is system attribute. System attributes cannot be deleted. Only user defined attributes can be deleted.</p>
<p>To delete the attribute, you have to make it user defined.</p>
<p><span id="more-286"></span></p>
<p>- Go to phpmyadmin<br />
- Go to your magento installation database<br />
- Go to eav_attribute table<br />
- Browse table with attribute_code &#8216;YOUR_ATTRIBUTE_CODE&#8217; OR browse the table with the attribute_id of your    attribute (&#8216;your attribute&#8217; means the attribute which you want to remove as system attribute)<br />
- Edit the table row of your attribute<br />
- Find the field &#8216;is_user_defined&#8217;<br />
- Set it to 1</p>
<p>Now your attribute no longer remains System Attribute<br />
Now you can delete it from Attribute manager</p>
<input id="gwProxy" type="hidden"><!--Session data--></input>
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=286&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-how-to-select-insert-update-and-delete-data/' rel='bookmark' title='Permanent Link: Magento: How to select, insert, update, and delete data?'>Magento: How to select, insert, update, and delete data?</a></li>
<li><a href='http://blog.chapagain.com.np/very-simple-add-edit-delete-display-in-php/' rel='bookmark' title='Permanent Link: Very simple add, edit, delete, display in PHP'>Very simple add, edit, delete, display in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/' rel='bookmark' title='Permanent Link: Magento: Adding attribute from MySql setup file'>Magento: Adding attribute from MySql setup file</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-delete-remove-extension-from-magentoconnect/' rel='bookmark' title='Permanent Link: Magento: How to delete / remove extension from MagentoConnect?'>Magento: How to delete / remove extension from MagentoConnect?</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/' rel='bookmark' title='Permanent Link: Magento: How to get attribute name and value?'>Magento: How to get attribute name and value?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-how-to-delete-system-attribute/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
