background

March 29, 2024

Yireo Category Extended module for Magento 2

Yireo Blog Post

For years, when people would ask me how to add a CMS page to the category menu of Magento, I would have told them to opt for a third party extension. Now I've got something else to tell them.

The problem of third party extensions

The problem of these third party Magento extensions is mainly that they don't keep their functionality simple: Instead of just solving the problem of how to add a CMS page to the main menu, they come up with their own menu manager, add features that are not needed and sometimes lack pretty much in code quality.

Why can't this be more simple? That was the question that my friends Ruud van Zuidam (Siteation) and Sean van Zuidam (Hyvä) asked me during a code-along session together.

Well, why not?

So we set down to create a Magento module that only made sure to extend a category entity with minimal settings to make that category act either as a CMS page or a custom URL. First of all, the UIComponent for editing a category in the backend was extended. Next, some EAV attributes were added via a setup patch (including some source models). And this allowed us to select that the category had - besides the display modes "CMS Block" and "Products" - also the additional modes "CMS Page" and "Custom URL".

Nothing showed yet on the frontend: For this, first of all, the additional values always needed to be added to the SELECT-query (done via an observer on the event catalog_category_collection_load_before). And finally, with some observers and plugins, the value of the display mode was checked to either modify the category URL to become either the CMS Page URL or the Custom URL (in the category menu) and a request for the old URL was being redirected to the new URL as well. Done.

Upsides

This module has little impact to performance. It is simple. It doesn't add fluff or anything. And it still uses the original Magento UI for category settings, so people will require just a little bit of time to dive into using this module. Plus, now that the extension exists, new display modes can be added quite easily.

Downsides

One downside is that this module extends upon category settings that are already on its own a bit confusing: A category could be showing products or a static block or both. And did you know that such a static block is actually referred to as a landing_page in the code?

Another downside is that each category that is configured with one of these new display modes, could potentially still have products attached. This could potentially lead into weird issues with search or layered navigation. Hence the advice would be not to adding products to these categories. Lack of knowledge could break more things in Magento, I guess.

But it's simple

However, when thing is to say: This module is simple. It only took 3 hours to put together, it might need a bit more love, but it is simple. Whether this is your piece of cake, is up to you.

Visit its repository here: github.com/yireo/Yireo_CategoryExtended

Posted on March 29, 2024

About the author

Author Jisse Reitsma

Jisse Reitsma is the founder of Yireo, extension developer, developer trainer and 3x Magento Master. His passion is for technology and open source. And he loves talking as well.

Sponsor Yireo

Looking for a training in-house?

Let's get to it!

We schrijven niet te commerciële dingen, we richten ons op de technologie (waar we dol op zijn) en we komen regelmatig met innovatieve oplossingen. Via onze nieuwsbrief kun je op de hoogte blijven van al deze coolness. Inschrijven kost maar een paar seconden.

Do not miss out on what we say

This will be the most interesting spam you have ever read

We schrijven niet te commerciële dingen, we richten ons op de technologie (waar we dol op zijn) en we komen regelmatig met innovatieve oplossingen. Via onze nieuwsbrief kun je op de hoogte blijven van al deze coolness. Inschrijven kost maar een paar seconden.