1

I'd like to display the unit of measurement after each product attribute with some dimension (mm, g, …).

To prevent duplicated code in each PHTML template file that probably displays a product with attributes, I thought it might be a good idea, to add a handler to the output helper, which could append those units.

For example attributes.phtml uses <?= $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?> to output the attributes value. I guess the sense behind using $_helper->productAttribute instead of simply outputting $_data['value'], is that the value might be translated to another format or something similar.

From the code in the Magento\Catalog\Helper\Output-helper, I figured out, that one might add handlers to the output helper. But I couldn't find any documentation on how to do so or where to add such a handler.

0

Looking for the same thing, found this issue on magento github : https://github.com/magento/magento2/issues/12371

In the thread, found this work around: https://gist.github.com/quisse/b78ee3d121a4c9b8dd141334c8fa27a8

There also a PR https://github.com/magento/magento2/pull/14527, which would permit a more elegant solution : https://gist.github.com/quisse/10e2a5a90f8dc55f82f972efe138e3ad, but it seems it haven't been merge

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.