Monday, January 18, 2010

HOWTO: Fix access denied after install a new extension

When you install a new extension, you might see new menu appear on Magento Admin menu, or new configuration section in Configuration Page, but when you click on the menu item or config section you only get a "Access denied" message, like below.




Here is two things you can check to solve the problem:

1. Clear session data:
Magento stores permission in session, so permission entries from new extension is not stored yet, that's why you get "access denied" message. You can just simply logout and login again, everything should work for you. If it's not then you can clear cookie or use a different browser.

2. Check your administrator role
Sometime your configuration stops you from manage your site. You can check it by go to System -> Permissions -> Roles and then choose Administrator role. Click on Role Resources tab and change Resource Access to All. This will make sure you have right to access to everywhere of your site.

If none of the above methods works for you, leave a comment and I will try to solve it for you.

Friday, November 6, 2009

BUG: Entity attribute option collection order

I confirm with everyone that Magento 1.3.2 (latest version at the moment) has a bug. This is not a real bug and will not cause any problem to your magento site, but it will give you some unexpected result when you do some custom modification to Magento.

The bug happens when you retrieve a option list of a custom attribute by the order that you have defined in admin. The code should look like following:

$_options = Mage::getResourceModel('eav/entity_attribute_option_collection')
  ->setStoreFilter(0)
  ->setAttributeFilter($attribute_id)
  ->setPositionOrder('asc')
  ->load();

foreach ($_option as $option)
{
  // doing stuff
}

We use setPositionOrder method here, because we want to the query result follows the order that we define in Magento Backend. You can check the method in app\code\core\Mage\Eav\Model\Mysql4\Entity\Attribute\Option\Collection.php.

But due to a bug in the collection class, you will always get the result in alphabet order. So right now, the correct way to retrieve the collection in position order is to use the follow code:

$_options = Mage::getResourceModel('eav/entity_attribute_option_collection')
  ->setPositionOrder('asc')
  ->setStoreFilter(0)
  ->setAttributeFilter($attribute_id)
  ->load();

It's easy to understand because when you call the setStoreFilter first, Magento will set the order by value for the query, that's why you always get the result in value order. But if you call the setPositionOrder first, the default value order is put behind the position order, and it works.

I will report this bug to Magento and hope they will fix it in the next version.

Monday, November 2, 2009

HOWTO: Fix login problem after a fresh installtion

This post is for people who have problem with login to admin panel on a fresh installation of Magento (man, this bug has been reported one year ago!). I myself got the bug on my computer this morning too, I did some searches and finally got a solution that worked for me. I don't know why Magento Team do not fix this bug yet, it's not so complicated too fix anyway. So here is a few thing for you to check if you can't login to Magento panel.

1. Use your IP Address
Use your local ip address as hostname. It should be 127.0.0.1 for 99% cases.

I must admit this is a very stupid bug. If you know how browser works, you will understand the problem. Magento want the cookie is also available for sub-domains as well, and to do it you will have to prefix the host name with a "." (dot). If you hostname is magento.com, then the host name to save the cookie is .magento.com. So when you work on local machine, your domain is localhost and magento will save the cookie under .localhost and the problem begin: browser does not save cookie on top-level domain, i.e: .com, .net, .org, etc ... And .localhost is a top-level domain (you can count the dots) and Magento broken. When you use your ip address, Magento will save it under .127.0.0.1 and it's not a top-level domain, so it works. For people who don't like to use your ip address, you can try to edit your local hosts file. I usually use local.dev for my development.

Noted: if you have already setup your url in configuration page to localhost then using the IP won't work, refer to the next section to know how to change your configuration directly in the database.

2. Check your setting
Sometime, thing goes wrong because of your configuration. You can check for timezone setting and base url setting. If your url is wrong, browser won't save your cookie at correct location and the result is you can't login to your Magento site. The same with Magento Timezone setting too.

If you can't access your admin panel to change your timezone setting. You can do this via phpmyadmin or similar tools. Go to core_config_data table and search for general/locale/timezone by path field then change it to your current timezone (use this list to look up your timezone)


You can do the same with  web/unsecure/base_url and web/secure/base_url. These are url configuration entries. Make sure you change values for all scopes and scope id, this is to avoid mistake.

3. Change session storage to file system
I don't think this is a correct solution, but some people say that it works for them so I include it here for reference.

Open app/etc/local.xml, look for

<session_save><![CDATA[db]]></session_save>
and replace with
<session_save><![CDATA[files]]></session_save>

Flush all sessions by truncate the core_session table and delete every items in var/session and var/cache. Hope it may work :)

Here are some links for your references:

Monday, October 5, 2009

HOWTO: Write Magento module

Magento is great, but it's even greater if you know how to write Magento module. I have collected a bunch of articles that published by Magento folks before. After reading some of these articles I'm sure that you will know how to write a magento module.

And here are the links:

And did I miss any articles that should be in the above list ?

Friday, September 25, 2009

What the hell is this blog about?

Well "everything happens for a reason" I like that sentence from my favorite band Limp Bizkit, and so does this blog. We start up this blog devriving from a demand to share what we know about magento to all of developers who want to work or have been working with Magento. Not like other resources they just talk about the business logics in the magento ecommerce. There are very few talks in deep into the implementation, even offical manual, wiki, forum don't. Unlike ExtJS which has a very good support system, most the posts in Magento forum don't receive responses from the technical support staff. Maybe it's because of the company's strategy ;) you know like other companies which have Enterprise versions for their products

We don't make a tutorial place, a guidelines, manuals, or whatever of those kinds. This is just a place to share the tips or experiences or simply our thoughts that we think that it may be useful to you guys.
We also want to talk anything about Magento, from potential bugs, glitches, strange behaviors or weird stuff that make you annoyed.

Finally, this is an open space, we welcome you guys to contribute your experiences over here. There's a section for guess to contribute. You don't have to register at all, just leave any words you have in mind.

Ok, you guys need to know PHP, Mysql of course, because that's what Magento is built on. But advanced knowledge on web developement and OOP are highly recommended :)