How to Change Favicon in Magento

I would guess that 30% of stores leave the default Magento favicon. Changing this is quite important as many stores are using the default icon which means your store has nothing to differentiate itself. Follow this guide to change your favicon.

What is a favicon?

You might asking what a favicon is. It is the image that is displayed in the browser tab when accessing your site and it is also displayed when a user bookmarks your site. Here is the favicon of Extendware:

Favicon Browser Tab

Notice the small yellow graphic in the top left corner of the browser tab? That is the favicon.

How to change the favicon

Changing the favicon is simple. Just follow these steps:

  1. Click System -> Configuration in the backend of your store
  2. In the left hand menu click Design
  3. Click the HTML Head fieldset and you will see a form like the following:
    html-head-configuration

To change the favicon simply click the “Browse” button for the Favicon Icon field and upload a new image. The new image must be 16px by 16px or 32px by 32px.

How to Disable Magento extensions

It is common when improving your Magento store that you will install new Magento extensions and sometimes you will need to troubleshoot an issue. The best way to do this is to disable extensions and see if they contribute to a particular issue. If you disable an extension and the issue disappears, then it could be the extension contributes to the issue.

How NOT to disable a Magento extension

There are many resources online that will tell you to go to System -> Configuration -> Advanced in order to disable a Magento extension. This will NOT disable the extensions! The only thing this can do is disable the extensions output. The extension will still be running in the background and could be causing issues with your store. In fact, disabling its output could cause even more issues.

How to disable a Magento extension the right way

To disable it correctly is quite simple. Just follow these simple steps:

  1. Go to System -> Cache Management in your backend
  2. Select all caches and set their status to disabled. This ensures that when you disable an extension the cache will not interfere and if you need to re-enable it quickly you will be able to do it.
  3. Open the extensions xml file in [Magento root]/app/etc/modules and you will see xml in the file like the following:

    Change the true to false and it should be disabled.

The really easy way to disable a Magento extension

Are you the proud user of an Extendware Magento extension? Then we provide you a very easy way to disable extensions in your store that will handle the cache, dependencies, and more when disabling. All you need to do is go to Extendware -> Manage Extensions -> Overview, find the extension and click it, and on the next page change its Status to Disabled and save.

Fixing Magento “Service Temporarily Unavailable” error

Sometimes Magento will display a “Service Temporarily Unavailable” message. The message will look like the following:

Service Temporarily Unavailable

The most common cause of this issue is a file located at [Magento root]/maintenance.flag. If this file exists, then Magento will display this message. The purpose of the file is to put the store into maintenance mode when doing maintenance. However, if someone forgets to delete it, then it will continue to display the message even after maintenance. To resolve, simply delete this file.

If you are looking for an easy way to put your site into maintenance mode while still making it accessible to designers / administrators, then you should get our Magento maintenance mode extension.

How to Change Magento Meta Title / Description

Adding Magento meta title / description to your store should be one of the first things you do after installing Magento. To do this is very simple:

What is meta information?

Meta information is important because it is one of the things bots such as Google look at your site to determine page relevancy. In addition, the meta title is especially important because this is the data the browser displays in the title bar / tab when viewing your store.

How to change default meta information

  1. Click System -> Configuration in the backend of your store
  2. In the left hand menu click Design
  3. Click the HTML Head fieldset and you will see a form like the following:
    html-head-configuration

To change the default meta data for your store you will want to edit the Default Title, Default Keywords, and Default Description.

How to Change your Magento Logo

Normally your store will display a logo so that your business can be identified. Sometimes it is necessarily to change this especially if you are just creating your first store. To do this is fairly simple if you follow these steps.

  1. Go to System -> Configuration in your backend.
  2. Click on Design in the left menu.
  3. Click on the Header fieldset.

You will see some form fields that look like this:

Change Logo Form

You will notice you can change the alt text (the text displayed when the mouse hovers over the logo) by changing the Logo Alt Img field. To change the path to the image file you will need to change the Logo Image Src field.

The logo image src will be relative to your skin directory. By default, the magento skin directory is [Magento root]/skin/frontend/base/default/. So, if your logo src is images/logo.png it would need to be located at [Magento root]/skin/frontend/base/default/images/logo.png

How to Display Latest Products on Home Page

You might have noticed when browsing our Magento extensions that we display the list of new products on our home page. In order to do this we are our using our Magento product sorting extension.

To create something similar on your site, all you need to do is follow these steps:

  1. Go to CMS -> Pages in your Magento backend
  2. Click on whichever CMS page is your homepage
  3. Click the Design tab to edit the design of the page
  4. Add the following XML to the design:

There are a few lines from this xml code that you can edit in order to better serve your needs:

You can specify to only show products within a certain category. To do that, you will want to uncomment this line. You can replace the category ID with any category ID from teh store

This is the number of products displayed in a row when viewed in grid mode. You can change the number to any number you want.

This is the most important line and is what will determine how the products are sorted. In this instance we are sorting by creation. As a result, newest products will display first. You can also sort by bestseller, popularity, revenue per view, revenue per order, featured, review count, and more. More information is in the user guide of the Magento product sorting extension.

Direct SQL Queries in Magento

Magento includes a database abstraction layer and object relationship manager that is really great at ensuring data integrity and consistent data access. In general, you should avoid writing to the database and instead use a well-written Magento extension that performs the task for you. However, sometimes a direct query needs to be made whether for performance or convenience and in this case you need to know how to do direct queries the right way.

Step 1: Get the database connection

To get the database connection, so you can execute the direct query you should use one of the following depending on whether you need to read or write:

Step 2: Get the table names

Almost every SQL query will require the use of a table name. Magento tables can be prefixed, so it is important to not hardcode the table name. There are two methods to get a table name that will include the prefix:

Get the table name from an entity

Get the table name from a string

Step 3: Reading from a table

Now that we have the read connection and table name we are ready to read from a table. It is oftentimes much faster to perform a direct read of a Magento database, than to the load the object property. In this example we will read the product table in get all products with their ID and SKU:

Step 4: Writing to a table

Just as direct reading can be faster, so can direct writing. Sometimes much faster. Here is a simple example of how to update the SKU of a product with the ID of 1:

Conclusion

Direct reading / writing can be faster or more convenient than using Magento models. However, it is important to do it with cautsion especially when doing direct writing. Magento models ensure data integrity and allow triggers that do things like the Magento full page cache or Magento indexing. Directly writing can create unforeseen issues.

Form Validation in Magento

What is Form Validation?

When we say form validation we specifically mean client-side Javascript form validation. Have you ever filled out a Magento from and been told that a specific field is incomplete or includes bad data? That is form validation. This graphic might look familiar to you:

validation-example

How does Magento perform form validation?

Magento utilizes the Javascript library called Prototype to do this. Specifically, the file [Magento root]/js/prototype/validation.js is where the magic happens. Looking around line 414 you can see the list of validation CSS class names and their error messages. An example of this is:

A full list of all Magento CSS validatoin classes and their error messages is found at the end of the post.

How to use the CSS validation classes to validate your custom forms

All you need to do is reference the validation CSS class in the input type in order to make your forms validate. For example:

Full list of Magento CSS validation classes

  • validate-no-html-tags – HTML tags are not allowed
  • validate-select – Please select an option.
  • required-entry – This is a required field.
  • validate-number – Please enter a valid number in this field.
  • validate-number-range – The value is not within the specified range.
  • validate-digits – Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.
  • validate-digits-range – The value is not within the specified range.
  • validate-alpha – Please use letters only (a-z or A-Z) in this field.
  • validate-code – Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.
  • validate-alphanum – Please use only letters (a-z or A-Z) or numbers (0-9) only in this field. No spaces or other characters are allowed.
  • validate-alphanum-with-spaces – Please use only letters (a-z or A-Z), numbers (0-9) or spaces only in this field.
  • validate-street – Please use only letters (a-z or A-Z) or numbers (0-9) or spaces and # only in this field.
  • validate-phoneStrict – Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.
  • validate-phoneLax – Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.
  • validate-fax – Please enter a valid fax number. For example (123) 456-7890 or 123-456-7890.
  • validate-date – Please enter a valid date.
  • validate-email – Please enter a valid email address. For example [email protected].
  • validate-emailSender – Please use only visible characters and spaces.
  • validate-password – Please enter 6 or more characters. Leading or trailing spaces will be ignored.
  • validate-admin-password – Please enter 7 or more characters. Password should contain both numeric and alphabetic characters.
  • validate-cpassword – Please make sure your passwords match.
  • validate-url – Please enter a valid URL. Protocol is required (http://, https:// or ftp://)
  • validate-clean-url – Please enter a valid URL. For example http://www.example.com or www.example.com
  • validate-identifier – Please enter a valid URL Key. For example “example-page”, “example-page.html” or “anotherlevel/example-page”.
  • validate-xml-identifier – Please enter a valid XML-identifier. For example something_1, block5, id-4.
  • validate-ssn – Please enter a valid social security number. For example 123-45-6789.
  • validate-zip – Please enter a valid zip code. For example 90602 or 90602-1234.
  • validate-zip-international – Please enter a valid zip code.
  • validate-date-au – Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.
  • validate-currency-dollar – Please enter a valid $ amount. For example $100.00.
  • validate-one-required – Please select one of the above options.
  • validate-one-required-by-name – Please select one of the options.
  • validate-not-negative-number – Please enter a number 0 or greater in this field.
  • validate-zero-or-greater – Please enter a number 0 or greater in this field.
  • validate-greater-than-zero – Please enter a number greater than 0 in this field.
  • validate-state – Please select State/Province.
  • validate-new-password – Please enter 6 or more characters. Leading or trailing spaces will be ignored.
  • validate-cc-number – Please enter a valid credit card number.
  • validate-cc-type – Credit card number does not match credit card type.
  • validate-cc-type-select – Card type does not match credit card number.
  • validate-cc-exp – Incorrect credit card expiration date.
  • validate-cc-cvn – Please enter a valid credit card verification number.
  • validate-ajax
  • validate-data – Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.
  • validate-css-length – Please input a valid CSS-length. For example 100px or 77pt or 20em or .5ex or 50%.
  • validate-length – Text length does not satisfy specified text range.
  • validate-percents – Please enter a number lower than 100.
  • required-file – Please select a file
  • validate-cc-ukss – Please enter issue number or start date for switch/solo card type.

Fixing front controller reached 100 router match iterations

The problematic Magento Front controller reached 100 router match iterations exception is not a common issue, but it is certainly a big issue to the usability of a store and can be difficult to solve.

Where is this Magento exception thrown?

In app/code/core/Mage/Core/Controller/Varien/Front.php inside of the dispatch() function. The following code snippet will give you an idea:

When is this exception thrown?

This exception is thrown whenever Magento cannot find a proper route for a request. In general, it should always be able to match a request with the router that handles 404 Not Found requests. As a result, in practice, this exception is only triggered when Magento has properly failed to generate routers or the cache has become corrupted.

How to solve this issue?

In our experience, there are two primary causes:

  1. CMS Module Disabled – The CMS module handles 404 not found requests which is the fallback router. As a result, if this module is disabled, then no router may be found. To resolve, simply enable the CMS module
  2. Cache is Corrupted – It could be the Magento cache became corrupted. In this case, the list of routers never gets loaded since it tries to load from cache and the cache does not have this data. As a result, fully flushing the Magento cache will resolve this issue.