browse the blogs

[ 27 May 2016 ]

Magento’s documentation tells you to run tests with the following

php bin/magento dev:tests:run unit

This isn’t wrong, but it pretty time consuming. You’re running every test in the suite. This one liner will let you run an individual test

vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist path/to/Test/Unit/SomeTest.php

Thanks to Vinai Kopp for the reminder, and don’t forget to checkout his Mage 2 Katas series on youtube.

[ 17 May 2016 ]

Magento 2: Set a PHP umask:

It sounds like the latest version of Magento adds the ability to set a umask for PHP, which means another barrier to getting Magento up and running in industry standard, mod_php system (i.e. shared hosting and your laptop) has been knocked down. Looking forward to giving this a try when I have a moment. I know Miguel Balparda and Nexcess have been working hard to get something like this through, so give the a beverage or a hat tip the next time you see them.

[ 13 May 2016 ]

Magento 2: Sort Order gets Weird for “Around” Plugins:

Interesting bit of insight from Anton Kril on plugin firing order. My naive assumption on how this would work was

  • All before plugins fire
  • The around plugin chaining happens
  • All after plugins fire

However, based on what Anton’s said here, it sounds like an around plugin will fire before a before plugin if it has a lower sort order that the before plugin. Beyond the trickiness of following a chain of execution, this has extra implications for an around plugin that decides to skip the call to $proceed() – not only can it cancel the actual method call, it can also cancel other calls to before plugins as well.

[ 13 May 2016 ]

If you grab the latest version of pestle (updated minutes ago) you should be able to use the following set of commands to create a base module with a working admin route.

$ pestle.phar generate_module Pulsestorm HelloAdminPestle2 0.0.1

$ php bin/magento module:enable Pulsestorm_HelloAdminPestle2

$ php bin/magento setup:upgrade

$ pestle.phar generate_route Pulsestorm_HelloAdminPestle2 adminhtml pulsestorm_hello_admin_pestle2

$ pestle.phar generate_acl Pulsestorm_HelloAdminPestle2 Pulsestorm_HelloAdminPestle2::top,Pulsestorm_HelloAdminPestle2::menu_1

$ pestle.phar generate_menu Pulsestorm_HelloAdminPestle2 Magento_Backend::system_other_settings Pulsestorm_HelloAdminPestle2::a_menu_item Pulsestorm_HelloAdminPestle2::menu_1 "Hello Admin Pestle" pulsestorm_hello_admin_pestle2/index/index 1

$ pestle.phar generate_view Pulsestorm_HelloAdminPestle2 adminhtml pulsestorm_hello_admin_pestle2_index_index Main content.phtml ""

Previous versions of pestle could get you part of the way there, but a few adjustments (no layout="" attribute in adminhtml handle XML files, different admin block base class, removing block input from generate_view) needed to be made for admin generation to work.

If you’re curious about what the …

[ 12 May 2016 ]

Magestead – The Vagrant Solution for Magento Developers:

Magestead just released version 2.0, with support for Magento 2. Another vagrant box to checkout if you’re looking for a way to get a sane Magento 2 enviornment up and running.

[ 11 May 2016 ]

While phrases like “should we be be doing this in 2016” abound in engineering discussions, down in the trenches an arbitrary SQL query is often the fastest, most expedient way to get at the data you want. While I still regularly encourage developers new to Magento to embrace using the models and API resource models when they’re not sure where to find a piece of data, for more experienced developers sometimes a good old fashioned SQL query is the right choice.

If you’re in that situation, something like the following should serve you well

<?php namespace Package\Namespace\Helper

class Someclass
protected $resourceConnection;
public function __construct(
\Magento\Framework\App\ResourceConnection $resourceConnection ...

[ 9 May 2016 ]

Two good Stack Exchange answers from Raphael at Digital Pianism covering how to add a custom icon to your Magento Admin Menu Items.

In short – these menu items use a custom font character, defined in svg file that’s (somehow? via LESS CSS?) converted to an embedded OpenType font. This custom font uses the Private Use Area of Unicode to define a custom code point for the new font character. The <li/> of each menu item gets its own CSS class, and that classes uses the content style to set the unicode character as the <li/>’s content.

So, high level, if you want to add your own custom icon you need to

  1. Use a program …

[ 2 May 2016 ]

In Magento 2, when you’re working in phtml template files, you’ll see two ways to make method calls to the block object, one using $this, another using $block


The $block variable is new in Magento 2. It contains a reference to an instance of a template’s block type. We say an instance because, unlike Magento 1, its not safe to assume you can set data on a block in one context (a controller action) and fetch it in another (a phtml template).

Why is there a $block variable? Because in Magento 2 $this refers to the template engine object. (a Magento\Framework\View\TemplateEngine\Php object by default). Magento uses a bit of magic PHP in this class

#File: vendor/magento/framework/View/TemplateEngine/Php.php
public function ...

[ 29 Apr 2016 ]

Creating an MCV/MVVM landing page for Magento 2’s frontend cart application is relatively simple. You create a routes.xml file so your module can “claim” a frontname, then then create a controller class that’s named correctly to catch a particular URL pattern. This is even easier with pestle, my PHP CLI module framework and Magento code generation tool.

$ pestle.phar generate_route Pulsestorm_HelloGenerate frontend pulsestorm_hellogenerate

Admin landing pages, however, are a bit trickier. That’s because, in addition to a standard routes.xml and controller file, you also need to contend with

  1. Every Admin URL needs a nonce/key to prevent XSS attacks, which means adding a formal “Admin Menu Item” to the system
  2. Every formal “Admin Menu Item” needs to be associated with …
[ 29 Apr 2016 ]

Just a quick bit of advice for folks getting into Magento 2 development, which probably applies to Magento 2 development as well. If you’re building backend admin components, it’s a good idea to not rely on the default, Super User admin account when you’re developing and testing.

There’s a few parts of the admin system that are completely bypassed for super users. For example, Magento admin controllers require an _isAllowed method where, as a module developer, you need to perform an ACL check. If you don’t perform this check, users will be rejected for having in sufficient permission. However, if you’re logged in as a super user, this check is de-facto skipped, and you’ll probably ship a module …