browse the blogs

[ 22 Sep 2016 ]

Magento 2: Approximating Local Code Pool Overrides:

Not sure if I like the idea of this becoming a common practice, but if you know your composer autoloading you can replace any class in Magento with a version of your own.

[ 13 Sep 2016 ]

Knockoutjs context debugger:

Chrome extension for peeking at a node’s KnockoutJS context. Useful if you’re doing frontend Magento work and hewing to their view of the world. via Daniel Sloof.

[ 9 Sep 2016 ]

Another javascript debugging snippet for the intrepid Magento 2 javascript programmer. The Magento_Ui/js/core/app RequireJS module/application/program is an important part of Magento 2’s UI Component system. This is the program that registers KnockoutJS views and makes them available for use in the (custom to Magento 2) Knockout.js scope binding.

data-bind="scope: some-viewmodel"

While the binding process still remains a bit of a mystery, I’ve recently unearthed a way to view all the available Knockout.js view models.

reg = requirejs('uiRegistry')

The uiRegistry RequireJS module (pointing to Magento_Ui/js/lib/registry/registry by default (located in vendor/magento//module-ui/view/base/web/js/lib/registry/registry.js)) returns an object that’s a very fancy dictionary/array. This is the object that Magento registers view models to. You can fetch individual view models …

[ 6 Sep 2016 ]

Magento 2: Syncing Backend and Frontend State/Cache:

Haven’t had time to check this out yet, but this is a far more cogent explaination of Magento 2’s mysterious sections.xml than anything I’ve seen so far.

[ 3 Sep 2016 ]

When I started work on pestle’s Magento 2 code generation, I deliberately left the the <preference/> feature of Magento’s di.xml files off the list of commands. This was, in short, to help encourage the use of plugins over preferences. i.e. to encourage developers to use the system that allowed multiple extensions to change system behavior – and not use the system that behaved like Magento 1 rewrites with a winner-take-all end result.

Unfortunately, while the plugin system shows promise, I’ve seen too many situations where it fails to provide the stable functionality a Magento developer needs. I suspect preferences will be the order of the day in the wild, and withholding easy code generation from pestle users seems short …

[ 3 Sep 2016 ]

This one’s more interesting than it is useful (or its main use is as a debugging exercise), but while I was working on a UI Component tutorial I wanted to turn off the XSD validation for ui_component files.

It turns out there’s a dedicated object that can control whether the XSD validations are applied ($this->validationState->isValidationRequired() below.

#File: vendor/magento/framework/View/Element/UiComponent/Config/DomMerger.php
public function createDomDocument($xml)
$domDocument = new \DOMDocument();
if ($this->validationState->isValidationRequired() && $this->schema) {
$errors = $this->validateDomDocument($domDocument);
if (count($errors)) {
throw new \Magento\Framework\Exception\LocalizedException(

[ 1 Sep 2016 ]

For folks using pestle, my PHP command line frameworking + Magento code generation tool, I’ve just added a selfupdate command. This will make a backup of your current version, grab the latest version, and update your local copy (permissions allowing, of course)

$ pestle.phar selfupdate
Downloaded to /private/tmp/pestle_DZOXou
Backing up /Users/alanstorm/Documents/github_private/GeneralCode/bin/pestle.phar to /Users/alanstorm/Documents/github_private/GeneralCode/bin/pestle.phar.1472763047
Backed up current pestle to /Users/alanstorm/Documents/github_private/GeneralCode/bin/pestle.phar.1472763047
Reaplced /Users/alanstorm/Documents/github_private/GeneralCode/bin/pestle.phar

Next up along these lines is formalizing the concept of pestle versions and adding some sort of “you haven’t updated in 30 days and there’s a new version” feature.

I don’t have any regrets about setting out to create my own CLI framework, but it really makes me appreciate everything you get “for free” from somethings like Symfony console.

[ 9 Aug 2016 ]

I’m knee deep in a rewrite of No Frills Magento Layout for Magento 2 – I know the systems well enough to use them, but I’m still coming up to speed on the underlying object implementations. This is important, since my approach in No Frills is

Here’s how you’d do this in PHP, here’s how to do the same thing in XML, hey look, all that XML means you don’t need to write PHP

When I was looking at the layout arguments, I was pleased to an xsi:type attribute

<argument name="block" xsi:type="string">integration_edit_tab_info</argument>

In Magento’s di.xml files and the UI Component XML files, these typed nodes usually meant you can sneak an actual object manager object in as an argument using …

[ 8 Aug 2016 ]

Although the technique still works, various members of Magento’s engineering team have discouraged using Magento 1’s <action method="..."/> syntax to call methods on blocks from layout update XML files.

<block ...>
    <action method="addTab">
        <argument name="name" xsi:type="string">info_section</argument>
        <argument name="block" xsi:type="string">integration_edit_tab_info</argument>

Other members of the engineering team have suggested an <arguments/> node as a replacement.

<referenceBlock name="block_name">
        <argument name="field1" xsi:type="string">foo</argument>
        <argument name="field_two" xsi:type="string">bar</argument>

Whenever you see an <argument/> or <arguments/> node in a bit of Magento 2 XML, …

[ 3 Aug 2016 ]

Magento 2 module creator and code generator | Mage2Gen:

Haven’t had a chance to check this out yet, but it looks like another Magento 2 module generation tool. This one seems to be an “everything and the kitchen sink” approach (vs. pestle which lets you build only the parts you need) but that approach does mean you get a fully featured module (whereas pestle requires you to know what a module does before you add the feature).