Magento

eCommerce Software for Online Growth

Tutorial: Creating Attributes (custom fields)

So you’re ready to add some custom data to your products?  Luckily, this isn’t complicated.  Today we’re going to create an attribute called “Hard Drive Size” for the external hard drives we’re about to sell in our store, and also an attribute called “Manufacturer” to use in our layered navigation.  Let’s start with the simpler one - Hard Drive Size.  In the front-end, this will appear on products like “Hard Drive Size:  {whatever options you create and select}” - For example: “Hard Drive Size: 100GB”.

Creating a simple attribute - Hard Drive Size

  1. Log into the Magento admin panel
  2. Navigate to “Manage Attributes” under Catalog -> Attributes -> Manage Attributes
  3. In the top right, click on “Add New Attribute”
  4. You’re now on the Attribute edit page and Properties tab.  It looks like this:

Properties Tab

image

  • Attribute Identifier: This is the name of the attribute used by the system.  Spaces can not be used in this field. We’ll type hard_drive_size.
  • Scope: This determines the store level at which this attribute will save for all products. If you choose Global, and edit “Hard Drive Size” for product 123 in store A to “50 GB”, product 123’s hard drive size in store B (and any other stores) will also update to “50 GB”.  For hard drive size, we’ll make it globally editable - we won’t sell the exact same hard drive in different stores with different sizes… that’s not possible.  An example where we might want globally editable: no is “Price.” We might want to sell the Hard drive for $20 more in Store A.
  • Catalog Input Type: This describes what kind of data the attribute will store. What’s set here determines how data entry for this attribute will take place.  We’ll use Text Field since we want to enter the value for each product manually into a text field.
  • Default Value: You can enter a value that will automatically populate for new products. We have many different hard drive sizes, so we will leave this blank.
  • Unique Value: If “yes”, the data saved in this attribute has to be unique for each product. In this case, we’ll say “no”, because multiple hard drives can have the same hard drive size.
  • Values Required: If “yes”, you will be required to enter data in this attribute field when saving a product that uses it.
  • Input Validation: This decides whether the data entered by the store owner is validated when the product is saved.  If validation is set to “Digits”, we’ll only be able to enter 0-9 in this field.  An error will be thrown if we try to put letters in the field.  In the case of Hard Drive Size, we don’t need validation on this field.
  • Apply To: This determines for which Product Types this attribute will display.  For example, price wouldn’t make sense in a grouped product, as each Simple Product associated to the Grouped Product will have its own price.  Therefore, you can set price to not apply to grouped product, and you won’t be scratching your head over what numbers to write in there.
  • Use in quick/advanced search: If “yes”, the data saved in this attribute will be searchable in the front-end in the quick search and advanced search, respectively (ie, if i type “100GB” it should return all products with this value saved in the Hard Drive Size field).
  • Comparable on Front-end: If “yes”, this attribute will be displayed in a product comparison, so long as at least one product in the Compare List contains a value for this attribute.
  • Use in Layered Navigation: If “filterable”, this data will be available as a filter in Magento’s layered navigation. Filterable (with results) means that only values that are associated to specific products in a given category page will list in the Layered Navigation menu. Filterable (no results) means that all existing values for an attribute will display in the menu, even if using this as a filter will produce no results. There’s one condition to use attributes in layered navigation - the Input Type has to be Dropdown, Multiple Select, or Price.
  • Position: This determines the position of this attribute in the Layered Nav menu.
  • Visible on Catalog Pages on Front-end: If “no”, this attribute will not be displayed in the product info page. The “visibility” only controls whether or not the attribute displays in the front-end. Keep in mind - if you set an attribute to “Visible: No”, and leave it as “Comparable: Yes”, this attribute will still show up in comparison charts.

  • Manage Label / Options

    image
    Under this tab, you can enter the label for the attribute in the front-end.  If you control stores in multiple languages, you can enter the label in each language under this tab.  If a store’s label is blank, this store will look to the default label and use this one.  Here we’ll enter “Hard Drive Size” under “Default”.

    Frontend Properties

    Click here to see how the attribute appears in the front-end.

    Creating an attribute with controlled options - Manufacturer

    The next attribute we’ll create is going to be “Manufacturer.” Let’s say you carry televisions by 4 manufacturers.  Rather than having to type the name of each manufacturer, why not just make it an attribute and assign four possible options to it:  Varien, Panasonic, JVC, and Sony.

    Attribute Properties

    For our “Manufacturer” attribute, we’ll use Catalog Input Type “Dropdown” since we want this attribute to have limited data.  Using “Dropdown” also enables us to show the attribute as a layered navigation filter.  Below is what the Properties tab looks like for “Manufacturer”:
    image

    Manage Label/Options

    Since we select Dropdown as the input type, we have the ability to create the possible options for this attribute from this tab.  Under “Manage Labels” tab is “Manage Options”.  Press “Add Option” to add an option.  It functions similarly to labels - any blank fields will look to the “default”.  You can also set the positions of each value and select one of the values as the default. See below for how it looks after adding four manufacturers as options.
    image

    Applying to a product

    Now, to apply this selectable attribute to a product, just add it to an attribute set and create a new product using this set.  Below is a simplified example of the General tab of creating a new product in the admin:
    image

    Front-end

    Click here to see how the attribute appears in the front-end.
    image

    Mmm, nice.  Now you’ll never have to type these manufacturers again.  Also, data entry will be more consistent, since it is impossible to have a typo or spelling error if a drop-down is used.

    RSS comments feed for this entry

    User Comments

    |7 comments
    1. tierralogic

      1tierralogic from planet xenon, zeti cluster|posted December 10 2007

      how can i add an upload field for a file, and have the system show a link to it on the front end? this would be for a user manual, etc, like a pdf file.

      thanks!

    2. Ross

      2Ross from Scarborough, North Yorkshire, UK|posted January 14 2008

      This is great, but I do agree with the previous comment - it would be nice to be able to have an attribute of type ‘file’ (or similar).  There is the ‘image’ type of attribute (which is close), but a more general purpose one would be good.

      For example, a shop selling CDs may wish to have a track listing with the track titles linked to preview audio samples.  If attributes could do that it would be really great!

    3. johannes

      3johannes |posted January 15 2008

      Yes, it would be great to upload files!  In fact, we are working on supporting this type of attribute smile

    4. Ross

      4Ross from Scarborough, North Yorkshire, UK|posted January 15 2008

      Great to hear!  It sounds like not much is being overlooked!

      Thanks for the reply.

    5. DragonZoul

      5DragonZoul |posted January 22 2008

      The concept is fine. We’ll see how far “attrbiutes” may be used, especially on the programmatric way in “my own” new classes ...
      what other types of attributes are planed?

    6. tierralogic

      6tierralogic from planet xenon, zeti cluster|posted January 22 2008

      so how does this work? are any of the responding parties part of the magento team?

      basicly, if i wanted to try and do this myself, which i think i can do with some effort, should i just go ahead and give it a shot and then what? submit the code to the group or smth?

      sorry just a little new to this! smile

    7. Ross

      7Ross from Scarborough, North Yorkshire, UK|posted January 22 2008

      @tierralogic - the posts that have the blue gradient are the Magento team (eg. johannes).

      If you want to try it yourself, go ahead!  Although if they are working on it, it might be worth waiting a couple of weeks for the next release (release candidate I think) - and see what changes have been made.

      At the moment there is no place to submit code.  It has been said that a development community (and ways to contribute code - and sell add-ons and services) will be launched after the production release (when the APIs etc are more stable and documented).

    • Comments in this section are now closed, please check out the forum for discussions about this topic.

    Explore the Knowledge Base

    Magento User Guide

    Magento Enterprise Available now

    Professional Services from the Magento Team

    Magento Job Board - Some sort of tag line goes here

    Latest Posts| View all Jobs
    © Copyright 2010 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
    Privacy Policy|Terms of Service
    Magento Community Count
    177665 users|1096 users currently online|277230 forum posts