browse the blogs

[ 14 Jul 2016 ]

Can’t Add a new UI Component Type · Issue #5647 · magento/magento2:

An interesting side effect of the new XML schemas – the definition.xml files for UI components have their top nodes locked down, which means developers can’t add their own UI component types.

[ 11 Jul 2016 ]

Formatting Dates in Magento Javascript:

If you’re doing any work in Magento’s RequireJS based javascript modules and see a dateFormat string

defaults: {
    dateFormat: 'MMM d, YYYY h:mm:ss A'

Chances are its a Moment.js date format string.

You can pull in the main moment function via a RequireJS shim

define(['moment'], function(moment){

And the mageUtils RequireJS library (an alias for mage/utils/main) appears to export a normalizeDate function that will convert Magento’s old custom date format into a Moment.js based format.

define(['mageUtils'], function(mageUtils){
    momentFormat = mageUtils.normalizeDate(oldMageFormat);
[ 9 Jul 2016 ]

Demystifying Plugins (MageTitans Italy 2016):

Concise explanation of the code involved in using a Magento 2 Plugin to change core system behavior, with the talk over here if you’re the sort who likes context.

[ 7 Jul 2016 ]

I’ve been digging through Magento’s UI Components this week and hit a stumbling block. The main KnockoutJS template that kicks off rendering (vendor/magento//module-ui/view/base/web/templates/collection.html) looks like this

<each args="data: elems, as: 'element'"><render if="hasTemplate()"></render></each>

This sort of thing is exactly where Magento hits the unsweet spot of being new, and using a technology I’m not super familiar with (KnockoutJS).

I’m pretty sure the HTML5 kids haven’t added there’s an <each></each> or <render></render> tag to HTML.

In my readings through KnockoutJS’s docs I discover that component bindings create custom tags, but some unfruitful searching through Magento’s code doesn’t show any obvious place where this has been done for an each or render tag. Some more digging into KnockoutJS’s implementation let me rule this …

[ 5 Jul 2016 ]

I just updated pestle with a new magento2:generate:ui:grid command. Magento 2.1+ only, not likely to be ported backwards to the 2.0.x branch. A longer article over on is forthcoming, but here’s the quickie version.

Here’s the arguments to use to create a UI Component Listing.

$ pestle.phar magento2:generate:ui:grid
Which Module? (Pulsestorm_Gridexample)] Pulsestorm_ToDoCrud
Create a unique ID for your Listing/Grid! (pulsestorm_gridexample_log)] pulsestorm_todo_listing
What Resource Collection Model should your listing use? (Magento\Cms\Model\ResourceModel\Page\Collection)] Pulsestorm\ToDoCrud\Model\ResourceModel\TodoItem\Collection
What's the ID field for you model? (pulsestorm_gridexample_log_id)] pulsestorm_todocrud_todoitem_id

The above assumes you’ve create a “To Do CRUD Model” by working through the Magento2: CRUD Models for Database Access tutorial, and then created yourself an admin/backend controller endpoint.

The Which Module? argument determines the already create module where pestle will …

[ 5 Jul 2016 ]

If you’re following along with Magento 2 development, you’ve probably heard the drum beat that the Model/Resource Model/Collections are old and tired, and the Repository classes are new and wired. While the move towards repositories is is a Good Thing™, a Magento 2 developers still needs to know the old CRUD system, and that CRUD system is likely to remain with us for a long time coming.

I was reminded of this recently as I took some time to dig into some changes in the UI Component feature in Magento 2.1. Most of (all of?) the Grid listings in Magento 2 still rely on collection models.

The pattern is a UI component configuration binds something called a data provider …

[ 5 Jul 2016 ]

How Interceptors are Generated:

TLDR; The object manager appends Interceptor to the class name you asked for if there’s a plugin. Then a second PHP Autoloader will look for Interceptor at the end of a classes name, and if it can’t find a definition via normal means, the autoloader generates the class.

[ 28 Jun 2016 ]

One of the things Magento 2.1 doesn’t bring to the table is the ability to symlink your modules and other components. It’s hard to tell if this is a deliberate omission, or just something that’s not a priority for the development team and keeps getting lost in the shuffle. If you checkout the Context section of this GitHub bug, you can see Magento’s template validation does still check the allow symlinks setting, but the immediately does another check that could never pass with a module available via a symlink outside the Magento system’s folder structure.

Maddening, but something we can at least work around. If we create a module that has a plugin for the Magento\Framework\View\Element\Template\File\Validator class

pestle.phar ...

[ 28 Jun 2016 ]

This is another one of those 10,000 foot view posts, as much to get my own head straight about something as anything else.

In programming, the term scope usually means

If I’ve defined variable X “here”, where else can I access it?

Magento’s core team have borrowed the term scope to described Magento’s multi-store features.

Websites, Store Groups, and Store Views

Magento allows you to create CRUD objects called “Websites”. A Website is a simple object and has two main pieces of data – a unique alphanumeric code for identification, and a reference to a default “Store Group”.

A “Store Group” is another CRUD object. It is similarly simple, and two two primary pieces of data – a default category ID, and …

[ 20 Jun 2016 ]

How Can I Resolve a RequireJS Alias in Magento 2?:

A quick command line that will, usually, resolve those RequireJS map/shim/alias things that often obscure where a file lives in Magento 2. Spoilers

find vendor/magento/ -name requirejs-config.js -exec grep addToCart '{}' +