Magento 1: JSON in layout xml
Fabian Blechschmidt
Today I learned, one can use JSON in Magento 1’s layout xml.
Tell Magento which action parameter are json and that’s it.
You can tell Magento that only one parameter is json, like this. Then Magento decodes the json and uses it. I was very lucky to see it today, because I needed an array. With json no problem
<action method="setData" json="value"><key>some_data</key><value>setIt!</value></action>
<reference name="content">
<block type="catalog/product_list_toolbar"
name="product_list_toolbar"
template="catalog/product/list/toolbar.phtml">
<action method="setDefaultDirection"><param>desc</param></action>
<action method="setAvailableOrders" json="order"><order>["created_at"]</order></action>
<action method="setData"><key>_current_grid_order</key><param>created_at</param></action>
</block>
</block>
</reference>
Other articles from this category
Shopware 6 Hidden Gems #16: CloneBehavior — entity duplication with overrides, one call
You know the admin’s „duplicate“ button on products. Now the ticket says: „We need that, but from code — duplicate a product per sales channel, with adjusted name and its own product number.“ Or: „Campaign landing pages: clone this CMS page 20 times with different headlines.“ I’ve watched this get implemented as: load entity with […]
Shopware 6 Hidden Gems #15: ChangeSet — before/after values for every write, no second query
The requirement sounds harmless every time: „Log when a product price changes, with old and new value.“ Or: „When an order’s email changes, notify the old address.“ Or the audit-trail classic: „Who changed what, from what, to what?“ And every time, the naive implementation is the same sad shape: subscribe to product.written, load the entity […]
Shopware 6 Hidden Gems #14: WriteProtected & ApiAware — field-level security without a single subscriber
A code review scenario. A plugin adds a purchasePrice-style field to a custom entity — internal margin data. The review question: „Can the Store API read this?“ Followed by: „Can the Admin API write that computed field you recalculate in a subscriber?“ The answers, in the plugin at hand, were „yes“ and „yes, and then […]