Magento released


Another version of Magento ( was released and this one promises some welcome fixes!

As always here’s a download link off my VPS which should be faster than the official download location:
md5sum: 79ca01aa9736a402e68ec34361222b96 magento-

The full release notes can be found here:

The most notable changes/fixes for me are:

  • Magento Community Edition 1.9.1 works with MySQL 5.6 and PHP 5.5
  • Improved product save performance with a large number of rule-based product relations.
  • Catalog price rule expiration dates are observed.
  • Improved indexing performance.
  • The Update on Save option works properly (reindexing is not required).

Fixing indexing errors Magento

After importing lots of data into Magento I had problems reindexing. I had no experience with fixing indexing errors Magento before and digging through the EAV structure in MySQL is not something you look forward to. Turns out there was a pretty easy fix for this which basically makes sure that all the tables are actually linking to an existing product. If there is a link to a product that doesn’t exist (anymore) for some reason you can expect to see errors like:

It’s as easy as running the following SQL commands:

Original post where I found this:

Add a simple to configurable product in Magento

Another nice little function I created during my import adventures where I had to add a simple to configurable product in Magento. I’m sure this will come in handy for someone..

Add an unpaid invoice to Magento order

Sometimes you’d just like to add an unpaid invoice to Magento order without it being set to paid status (Cash on Delivery anyone?). Once again I found a tutorial on Inchoo which described the biggest part of generating an invoice programmatically for an order, but it was always set to paid status. Well, I found the solution:

It’s mostly the line $invoice->setState() which I changed. And I switched to offline capturing, all other options are documented.

I was calling this function from an event observer but you could also just load an order using:

Xtento Product Export Cron Broken With Aoe Scheduler

Like the title says, the cron was broken when using Aoe_Scheduler so I decided to write my own little script from Xtento’s own code.

I put this file in the shell directory and actually just call it with a crontab at 00:00 every day:

The contents of the export function could also just be placed in the contruct, and it might not necessarily need the secureArea and setCurrentStore but it’s the contstruct I always use and it works ;)

How to update options of a configurable product in the Magento Cart

Magento Configurable Option UpdateFor a project I had to figure out how to update options of a configurable product in the Magento Cart.

Considering the code from the famous Inchoo post from 2009 does not work anymore in Magento 1.8+ and I managed to get it working I decided to document the function for my fellow Magento developers out there on the interwebs. The code from the Inchoo post does change a few parts of the quote item but misses a few vital parts like changing the SKU. So on the frontend you might think it has properly changed the product, it will even show up fine in your cart, but once you checkout it will still use the old product! Turns out there’s a cart function called updateItem which can not only change the quantity but also the selected option of configurable.

Hope you’re all happy with this one, it took one of our developers more than 2 weeks to not get it working and I managed it in a day, once again. Mind you, a day is still frustratingly long for me, hence the post because everyone should be able to save that amount of time while working in a project..

The function I wrote to update options of a configurable product in the Magento Cart

To update the flavor of a configurable project we currently use a url like this:

Some explanation of the various variables you’re supposed to pass to the function:

  • $superAttributeId is the id of the attribute, in our case flavor which has id 175.
  • $childId is the id of the selected option of the attribute
  • $itemId is the id of the item in the cart
  • $productId is the id of the actual product, in this case the configurable
  • $refresh: if set will force the current page to refresh after updating the cart (handy for cart page since you want to not only refresh the ajax cart but also the whole cart page)

I cleaned up the code while writing the post so an error might have slipped in during the process, if you find anything wrong with it please don’t hesitate to comment and I will fix the code

Remove the username requirement from Zizaco Confide

These days it’s very uncommon for websites to user usernames and most sites just use the user’s email address.

Laravel has many, many very handy packages we can use to quickly get up and running and save us countless hours when developing a website but sometimes they do not do exactly what we want. In this case I relied on a package called Confide by Zizaco, commonly referred to as Zizaco/Confide. It started off pretty great with me having user creation, login, password reminders etc all working within 30 minutes. However, Zizaco/Confide heavily relies on the existance of a username for creating users and logging in. To get around this you will have to extend Zizaco\Confide\UserValidator and override $rules and also extend Zizaco\Confide\EloquentRepository and override the function getUserByEmailOrUsername.

To do this you can create a file in app/controllers with two classes in it and modify app/start/local.php to re-bind the Confide classes to your new ones so the original classes get overridden.



UPDATE: Had to override the function validateIsUnique as well which required me to “use Zizaco\Confide\ConfideUserInterface;” to get it to work. Code fragment updated to reflect the new situation.


If you ever experience the error ERR_INCOMPLETE_CHUNKED_ENCODING in WordPress (you should be able to find this in your Nginx error log) then you should check the following things:

  • Nginx and PHP-FPM should both be run as the same user
  • The directory /var/lib/nginx and all underlying directories should be chowned to that user

I my case Nginx and PHP-FPM were both running as Apache, but the directory /var/lib/nginx was owned by nginx:root. This meant the dir has to be chowned to apache:apache to fix the problem:

Don’t forget to restart nginx & php-fpm to be on the safe side.

Pass Validation Errors to the Master Template in Laravel

laravelSo I am developing an invoicing system in Laravel and ran into the problem that I couldn’t figure out how to pass validation errors to the master template in Laravel. Normally you can only Redirect::to()->withErrors($validator); and I wasn’t trying to Redirect but output them straight to the View. After having read a few silly solutions which involved View::make()->with(‘errors’, $errors); and then writing a whole new foreach loop in the view instead of the template. That is clearly not an efficient solution since I would mean copy/pasting code from the template to the view.

Doing the following does not work:

So I figured out you can share a variable across all currently loaded views/templates.

Here’s the piece of code that works for me now:

So I get the validator messages and store those in a variable $messages. I then “share” that variable as $errors across all views and my template picks it up in the following piece of code:

CentOS 7 WordPress with Percona and Redis

Moved logo-centos-7distro again because I somehow managed to break MariaDB on Ubuntu.. So instead I’m back to Percona on CentOS, which I upgraded to v7 now. CentOS 7 WordPress with Percona and Redis! Mind you I am not running HHVM anymore so the site will be slower. Turns out there’s a memory leak when it comes to Crayon, the syntax highlighting plugin I use. I have to look for a nice caching solution, preferably using Redis..

UPDATE: Found my redis solution!
Without being logged in the blog loads in 13ms now, that’s even faster than varnish :)

UPDATE: Turns out I was overloading my VPS and the dreaded OOM killer struck and killed Percona. So I’ve upgraded to a 2GB VPS and I’ve added DataDog monitoring to Nginx, Percona and Redis just to see what’s going on. Here’s an example of my dashboard at DataDog. It’s a bit of a build it yourself NewRelic and free up to 5 hosts!