Home » Archive

Articles tagged with: attribute

Magento, Magento 2 »

[16 Jan 2017 | No Comment]

This article shows how you can get attribute name or label, id, entity_type, etc. by attribute code.
Here is the code that you need to write in your Block class.

Below are the code to be written in template file. The sample output of the codes are also given below.
Multiple entity types can have same attribute code. For example: entity type ‘catalog_product’ & ‘catalog_category’ both have ‘name’ attribute code. So, “getAttributesByCode” function can return object of size greater than 1.


Get Product Attribute data by attribute code.


Hope this helps. Thanks.

Miscellaneous »

[10 Jun 2016 | No Comment]

This article shows how to load product by it’s ID and then get all attributes associated with that product in Magento 2. We print the attribute code, attribute name, and attribute value of all the attributes related to any particular product.
We will be using Magento 2’s Service Layer for this task. Use of Service Layer is highly encouraged by Magento.

Magento »

[11 Apr 2016 | No Comment]

This article shows how to get / filter products based on it’s attribute id, or the attribute’s options id.
Get all products by a single attribute option id

Magento »

[29 Mar 2016 | No Comment]

This article shows how you can filter child products associated with a configurable product by the child product’s attribute value.
Suppose, we have a configurable product with two attributes (‘size‘ and ‘color‘) and we want to select only those child products with certain size and/or certain color. Let’s say, we want to select only those products that have color as ‘Red‘.

Magento »

[11 Mar 2013 | No Comment]

This article contains code snippet to get customer attributes in Magento.
Get Customer Collection

Magento »

[10 May 2012 | 3 Comments]

Here is a quick code to get all attributes and their name and value associated with any particular product.
First of all we have to load the product by it’s ID. And then get all it’s attributes. Here is the code:-

Magento »

[9 Feb 2011 | 9 Comments]

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 we send single value from the selection list, the filter doesn’t work properly.

Magento »

[23 Dec 2010 | 2 Comments]

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 ‘Samsung’ manufacturer/brand.

Magento »

[15 Nov 2010 | 12 Comments]

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 filtering collection object.

Magento »

[7 Aug 2010 | 32 Comments]

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 to category from the mysql setup file of the module.
By mysql setup file, I mean the file inside the directory YourNamespace/YourModule/sql/yourmodule_setup/

Magento »

[7 Jan 2010 | 2 Comments]

Suppose, you have the product data, i.e. you have a loaded product information stored in a variable named ‘$_product‘. Now, when you type $_product->getManufacturer() , you will get the manufacturer ID. To get the manufacturer name, you have to use the following: $_product->getAttributeText(‘manufacturer’). Below is the complete code:
Get Manufacturer Name and ID from Product

Magento »

[9 Dec 2009 | 22 Comments]

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 “YourModule/sql/yourmodule_setup” directory.

Magento »

[2 Dec 2009 | 53 Comments]

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.

Magento »

[27 Nov 2009 | 7 Comments]

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.