Adding new category attribute in Magento 2

Sometimes you need to extend functionality of Magento 2 categories. In this article I would like to show you how to add a new custom category attribute. Let’s say, this attribute is needed to display/hide some content on the category page.

Now let’s write our installation script under Setup folder. I’ve included comments within to guide you along. Note that the custom variable I’m adding is called hide_this_category. This attribute will be used for hide particular category from menu.

In this case I’ve added a Boolean field that will be stored in used as Yes/No, but you can change this according to your requirement.

Lets check code to add custom category attribute.

Please setup this installation script with your extension and run upgrade command via command line. If things didn’t work out, check to see if the installation script actually ran and make sure that you cleared your cache and double-check your installation script filename, path and version number with Magento 2 extension structure.

Enjoy Cool stuff with Magewallet!!

Magento 2 – How to add calendar in admin configuration options?

Recently I have found one solution to add calendar in system configuration options. Lets discuss in detail.

In order to add calendar in system configuration options, we have to add one system field and require one Block file.

Use below code to add system field.

Now lets create Block file – Calendar.php

Download Free Most Viewed Products Extension

Lets discuss some terms used in this block.
Magewallet – Vendor Name
SytemCalendar – Module Name
calendar.png – add calendar icon image at pub/media/systemcalendar/ directory

Thats it. Enjoy Magento 2!! Enjoy Magewallet!!!

How to get current CMS page id in Magento2

To get the id of current CMS page in Magento 2, use the following code snippet.

There are so many other methods to get CMS page details like title, identifier, content, and content heading. Lets check one by one.

To get the identifier of the current CMS page you can use

To get the Page Title :

To get the Page Content :

To get the Page Content Heading:

Thats it. Enjoy Magento 2!! Enjoy Magewallet!!!

Magento 2 – How to add WYSIWYG editor in admin configuration options?

In this blog post, we learn how to add WYSIWYG editor with textarea in admin system configuration options.

First we will add one system config field in system.xml file. Use below code to add new field with the type Editor.

Download Free New Order Notification Extension

In order display WYSIWYG editor with this textarea we need one frontend block. so you can create editor.php file at below location.

Download Free Most Viewed Products Extension

In this block you can write below code snippet.

Now please clear cache file and then go to module system configuration, you will get textarea with WYSIWYG option.

That’s it. Enjoy Magento 2! Enjoy Magewallet!!

How to get parent product id in Magento 2?

As you know when we works with any customization work related to configurable product and simple product, we need some code snippet that helps us to find out the relation between parent and child product.

Lets take one example, when we have one simple product (child product) and we need all the simple (child) product associated with its parent product. In this case we require solution that gives us Parent product id and using this parent product we are able to find all its simple (child) products.

In order to get the parent product id in Magento 2, you can use below code at any file.

If you want to use this code at block file in Magento 2, then use below code snippet.

That’s it. Enjoy with Magento 2!