Engine23

Magento Ecommerce Strategy, Design & Development

Magento - How many events are fired during a normal page load

I have been doing a bunch of work lately using the event observers system.  This powerful feature of Magento community and Magento Enterprise allows for so much flexibility.  I did find myself kind of stuck trying to find the right event to observe.  My issue was I need to find an event that was after the customer was initialized, but before the Header.php and Header.phtml were brought in.  I needed to change the status of some text based on the customers logged in/out status.

Fastforward to me using the wrong event.  I found, what I thought was the perfect event, customer_session_init.  So, after patting myself on the back for being so smart, I wrote all my logic, and did a happy dance that it was so easy.  Well, after running the code, it turns out that because I was checking if the customer was logged in or not, and if not, AND I had some Header information, I was logging them in...well, sadly that "re-initiallized" the customer session!!!! So, I got the dreaded 

Front controller reached 100 router match iterations

Well, I instantly figured out that I had found a great place to start my check but it was too early in the execution.  I needed a better place, something later in the request flow.  Just to prove things worked  I chose the last "non-generic" event that was fired: controller_front_send_response_after

Read more

Magento - Chrome always asks to enable cookies and not able to log into admin

I recently had a Windows computer, using Chrome get stuck where I could not log into my local magento installation.  I then tried to log into the admin, and it appears as though things worked fine, but the login page reloads, with no error or messaging.  Welcome to COOKIE purgatory.

Turns out that Chrome, being somewhat neurotic, does not like something about the configuration and/or the domain that the cookie is set.  

The fix:  

Step 1: Using some sort of method to update the mysql database ( adminer, phpmyadmin, command line )

Update core_config_data 2 paths and set the values to null

  1. web/cookie/cookie_httponly
  2. web/browser_capabilities/cookies
The following is the raw sql from my instance, you could use a different WHERE clause and use path LIKE 'web/cookie/cookie_httponly' for example, but using ID's is much safer.

Read more

Magento - Limiting US Cities and Territories

I was recently asked if I can build a module that will exclude certain US cities and territories from showing up on the checkout, join, etc. 

The biggest reason is that America Samoa and Armed Forces Africa are never going to be places that customers will be from! 

I had considered selling this as an extension on Magento commerce, but I figured its been a while since I gave back to the community.

After this is installed, the settings are in System->Configuration->General->States Options In the new area: Exclude the selected US States

 http://www.engine23.com/limit-us-states-and-territories.html

Magento - Adding to existing getChildHtml elements using local.xml

So, ironically in the past 2 days, I was asked to perform the same task (on two separate projects!)

Basically, in both requests, there is a current template that has getChildHtml and instead of adding a new one to include a new template file, I wanted to be able to just append my to the existing one.

Several benefits, the main one being I am not over-writting a core template file that may change during upgrades...and there is existing placeholders on the template that I can add my custom data inside.

This one that I will be showing is the customer accout create form.

That form had all the elements I wanted, except in this case they wanted to add some extra content.

Now, yes,  I could of just got the main template, app/frontend/base/default/template/persistent/customer/form/register.phtml and put it in my theme, and just hard coded my new content.  BUT that is not the magento way, that does not allow for fallback, and that means that if we switch themes I need to remember to move that code, and hope that things dont change or break in the future.

The better way, just add your new section via xml!

I struggled with the exact syntax until I remembered I did a similar thing when I added captcha to a magento website earlier.

Read more

Seamless CSS and JavaScript Minification in PhpStorm

If you are using PhpStorm then css and javascript minification is a set it and forget it process that requires no maintenance after setup.  As a programmer it doesn’t get any better than that, so I felt very silly for not doing a good job of it over the years when I figured out this trick.  It took a minute to figure out as i’m using Mac OSX Maverick, and all of the articles on it were for Windows.  So, if you’re stuck and on windows you should be good to find specifics with a quick google.  Alright, lets get going.

 

First, this was also my introduction to Node.js, but not to worry if it is yours too, we will only be using it as a simply command line utility.  Head over to http://nodejs.org/ and click install to download, and then run the pkg, defaults will work.  Then go into PhpStorm and install the node.js plugin to finish that integration.  A little note, /usr/local/lib/node_modules  is the important directory and it should hold by default npm ( Node Package Manager ). And by default everything should be symlinked so the npm command will work anywhere.

 

Download:

Read more

Magento - Remove the trailing slash getUrl

Here is how you can use the URL key for a product, using getUrl and avoid the trailing slash

If you use

$box_url = Mage::getUrl('our-box.html');

and echo that string you will get something like

http://whatever.com/our-box.html/

That of course is not right and you probably will get a 404 page. Unless you did a URL rewrite but that is another topic all together. Here is how to use the same function, but use a parameter instead

$box_url = Mage::getUrl('', array('_direct'=>'our-box.html'));

That will get us what is needed so echoing this string gets us

http://whatever.com/our-box.html

Magento - Getting rid of the sidebar Compare Products

Some times, your theme does not need the compare products in the sidebar for a 2 column layout.

Here is the xml you add to your app/desing/PACKAGENAME/THEMEFOLDER/layout/local.xml

<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<span ><reference name="right">
<span ><action method="unsetChild"><name>catalog.compare.sidebar</name></action>
</reference>

</default>
</layout>

Make sure you refresh your caches and you should see that go away.

Read more