Show the full SQL query when you get Magento SQL errors

If you’ve ever been coding in Magento you may have seen an error like this:


Obviously an error message like that makes it pretty tough to figure out what is wrong. You can make your SQL error reports show much more data to help with debugging and look like this:


To do this edit your /lib/Zend/Db/Statement/Pdo.php file and replace line 234 in this file with the following code.

Make sure you don’t let this code get into your production environment though as showing the full SQL can sometimes reveal private data in the event of an error.

A ‘Heads’-up about access control orgins and setting content-type

I’m not really sure if this happens on every server, but I recently came across a little annoyance that had me locked up for the greater part of 3 hours trying to figure out what was wrong. I had a javascript application doing an ajax call over to a different server. I wasn’t doing anything fancy, just using jQuery, etc, and using JSON to send data to the remote server.

The first thing to know about trying to do ajax calls to another server is that you need to set your header orgin access control allowances. The easiest way to do this is to edit your .htaccess and drop these lines in somehere at the bottom:

Header add Access-Control-Allow-Origin “*”
Header add Access-Control-Allow-Headers “origin, x-requested-with, content-type”
Header add Access-Control-Allow-Methods “PUT, GET, POST, DELETE, OPTIONS”

After doing this the remote calls started going through for me, but then they started getting duplicated as well. The strange thing is that the chrome developer console didn’t show duplicate ajax calls being sent out!

The problem ended up being that my server didn’t like that I was trying to set the content-type property from my java-script AJAX request so for some reason it was failing in its response back to the client and attempting to redo the server call as a POST request… It is a very weird reaction from the server and caused duplicate actions on the server-side per each single AJAX call on the server side. It was near impossible to prevent with a hack-fix because the issue is controlled neither by the client javascript code, nor the server application code.

The solution? Make sure you don’t try to set the content-type in your ajax call to the server. That means if you’re using the jQuery ajax function then don’t set the contentType attribute. Removing the contentType from my ajax calls solved this crazy problem for me. I hope my solution helps someone else! 


Magento CMS Tutorial/Reference

I was helping someone learn how to use Magento CMS static blocks and pages and I couldn’t find a great reference. I’ve decided to write my own. 

Pages – Pages are what shows up in the front-end. The URL key is what you use to access the page ( and the content is what appears in the page. Title shows up in the title bar. Simple.

Static Blocks – These can be inserted into any page and repeated. For example, if you had a page that had a block of text that you want to appear on another page but you didn’t want to rewrite it and have to sync between both pages then you would want to create a static block and include that static block in each page’s content. The static block si referenced by the Identifier field. Here’s an example of how this would be used. Static blocks and contain other static blocks too. 

Page Content Codes

When working in the Magento CMS you can enter any HTML into the content box, but you can also put in these special things:

  1. Store URLs: {{store url=”path_to_your_media_file_goes_here”}}
  2. Skin Image URLs: {{skin url=”path_to_your_media_file_goes_here”}} 
  3. Media Image URLs: {{media url=”path_to_your_media_file_goes_here”}}
  4. Static Block Content: {{block type=”cms/block” block_id=”page_identifier_goes_here”}}
  5. Other Data Blocks (advanced): {{block type=”module/blockclass” block_id=”choose_a_name” template=”template_file_path”}}

Now I’ll go into a bit more detail:

1. Store URLs
{{store url=”path_to_your_media_file_goes_here“}}

If you want to link to a CMS page or some other page on your site you should use this code.

Example: Click here for customer service

2. Skin Image URLs
{{skin url=”path_to_your_media_file_goes_here“}} 

Skin image urls can be inserted into a page as paths to a skin image or file. These are relative to the skin/frontend/*package*/*theme*/ directory in your website.

Example: Here is a picture of our company logo: <img src=”{{skin url=’images/logo.png’}}” />

3. Media Image URLs
{{media url=”path_to_your_media_file_goes_here“}}

Skin image urls can be inserted into a page path to point to an uploaded image or file. These are relative to the media/ directory of your website.

Example: Here is a picture of a duck: <img src=”{{media url=’ducks/duckpicture.png’}}” /> and click here for a PDF that we created for you.

What’s the difference between skin images and media images?

Great question! Skin images are store layout/theme dependent and may change depending on the store view, but media images are static and don’t care about what theme is currently being displayed to the user. Media images are typically files that are very likely to change over time where skin images 

4. Static Block Content
{{block type=”cms/block” block_id=”page_identifier_goes_here“}}

Static block content can be inserted into the content of one or more pages. This allows you to have repeated content in your pages without having to manage multiple content page coppies every time you make an update.

Example: Here is your navigation menu: {{block type=’cms/block’ block_id=’my_navigation_menu’}}

5. Other Data Blocks (advanced)
{{block type=”module/blockclass” block_id=”choose_a_name” template=”template_file_path}}

If you are coding template files nad custom block classes, you can include any block class as a singleton using this method .The type attribute is the code to create the block class and the block ID is a custom name you can choose for the block. This block name is used in caching sometimes. Finally, the template file path is a reference to the template file from the app/design/frontend/*package*/*theme*/template directory.

TIP: You can also set the the blcok type to core/template to create a simple block that does not have a specific block class.

Example: Here is my footer block content: {{block type=’core/template’ block_id=’footer_block’ template=’page/html/footer.phtml’}}




How to give requirements to a designer without pissing them off


Getting a website designed is pretty important for your business-everyone knows that, but if you can’t provide a proper specification for your designers then you’re going to get a shitty design.

It doesn’t matter what designer you’re working with. Even if your designer is an all-star they are going to have a hard time making something awesome for you when your requirements are tucked away in your brain. Here’s how to do it the right way:

1. Outline your goals.

For every page you want designed, state your goals. What is the purpose of this page? Are you trying to attract customers with a value proposition or are you trying to showcase functionality? Are you trying to direct new traffic to your pricing page or are you trying to inform your existing customers?

2. Show examples of sites you like.

Don’t try to reinvent the wheel and don’t expect your designer to do that either. Instead, your designer is going to look for inspiration from other designs. If you provide several examples of pages that you like and explain why you like their design and what about it you like, then it guides your designer to choose the right inspiration for your own design.

3. Provide minor details

Every page has its own caveats. You’re going to want a particular image somewhere, or some text to be more emphasized. Here’s where you write all that out. Do it in bullet form-don’t write your designer an essay. Also, don’t be too specific.

Following this process lets your designer stay creative and use their own judgement for everything around the content and still meet your goals and expectations. It’s a win-win – nobody gets pissed off you get a much better design 🙂

Taking it from good to great is what will make you a amazing leader.

Every growing company will have problems along the way. It’s a consequence of being distruptive to the market.

Do you think Apple was always so great? Microsoft did not veer from their constant upswing from time to time? Even Google and Facebook consistently receive a flood of love-hate.

Being part of a growing company can be a party one week and a death spiral the next week. 

Recognizing that every company in the world has its ups and downs is tough. 
Getting it back on track when it goes down is what will make you a great leader.

As a leader, you need to identify the problem, invent a solution, let go of your emotions, trust your team and move on – quickly. 

Kik is a great example. 2 years ago RIM hit them with a patent lawsuite in the wake of their exploading success. What Ted Livingston, their CEO, and the Kik team did to revive the messenger’s success up to it’s now 19-million userbase is simply extraordinary. Kik even returned to Blackberry despite the harsh feelings.

Seems hard, right? IT IS HARD! That’s why when you hit the skids with your project and bring it back successfully you’ll be a far better leader than you have ever been.