Shopware AG opensources SwagEssentials

Shopware AG has just opensourced SwagEssentials, a key element of its Shopware 5 Enterprise Edition (EE) suite. The code can be found here: https://github.com/shopwareLabs/SwagEssentials

This step, which went almost silently, is in fact great news for all Shopware 5 users who could/did not afford to buy the EE, but have run into performance issues. Key features that comes with SwagEssentials are

  • support for multi-server operation
  • support for MySQL read/write replicas
  • redis number ranges (replacing the rather slow MySQL number range table)

If you have an questions on how your Shopware 5 installation would benefit from these features, or what it would take to get these implemented, feel free to contact me!

Smarty, Shopware 5 and PHP 8

When Shopware 5 was created, obviously PHP 8 was far away in the future and no one would have been able to foresee the details of its impact on Smarty. The nice thing with Smarty is that it allows you to use PHP functions directly. For example, to check for the number of elements of an array you could use something like this (‘modifier notation’):

You could have even written this in a PHP function style as

Now obviously a PHP update of your server or your development environment directly reflects in your Smarty templates.

A typical pitfall is that many PHP functions have, in effect, been kind of null safe up to 7.4. That is, given $myArray === null, the function would just have issued a warning. This in turn would most likely have gone unnoticed in your Smarty template. What you’ll see with PHP 8 instead is something like

In case of the count function it seems to be sufficient to omit the PHP function call notation and to use the straight forward Smarty format, i.e. {$myArray|count}. How comes? The answer is simply that when using the PHP function style, the PHP function would be called directly. Whilst when using the modifier notation, Smarty will call a modifier function smarty_modifier_count provided with Shopware 5 (!), and, surprise, surprise, this will check the variable for being an instance of Countable and if not so, just return 0.

Now what works fine for count doesn’t neccessarily work for other PHP functions, as most of them do not have dedicated Smarty modifiers. There are functions like number_format that behave slightly different in PHP 8, and these differences sometimes are not explicitly documented.

View Post