Creating New Product Type and Product Attribute in Magento 2

In Magento, there are 6 types of products by default: simple, configurable, virtual, downloadable, bundle and grouped products, and they delivers various unique features and options that common merchants will find it sufficient for their webstore. However, sometimes we need more than those, so In this post we will find out how to create a new product type and also how to create a new attribute for a product type.

1. Create a new product type

To add a new product type, you just have to create a new file named product_types.xml in etc folder. The content of the file should be something like:

Above we are creating a new product type named “Magenest” and have the type id of “magenest”. The custom attributes is of your choice. Now you should create a file at Vendor\Module\Model\Product\Type and have the name “Magenest” with the following content:

This is the minimum amount of code that you should implement. In the future, maybe you will need to write some helper methods that you can call on the object of the product of this type.

Done, the above steps should create a new product type for you. If you check the Add new product dropdown, here is what you should see:

creat product type in magento 2

2. Create a new attributes

This part should also be no trouble for you. Lets go ahead and create a new file named InstallData.php in Setup folder and add some lines of code:

This will add a new product attribute in the Product Details group of your backend product detail page. This attribute will be of type varchar and will be displayed as a dropdown since the input is set to Boolean. Other options is up to you to choose.

One more thing here, if you create a new product of type Magenest but you can’t see where to set the price, add these lines into your InstallData.php, method install.

This will add some fields into your product types. Now if you look back, you should see an attribute as following:

create product attribute in magento 2

That’s about it for this post. Hope you can soon apply these into your extension.

Share

Comments (8)

  1. Tajinder
    I want to create custom product type having exact functionality as of Bundle product but having its own files for templates, etc. I extended the type class from \Magento\Bundle\Model\Product\Type, but in admin it just come as Simple product. Any input?
  2. FrancJaw
    Generic Cealis With No Script Legal Usa Online Pharmacies Viagra In Farmacia viagra Where Can I Buy Macrobid Bacterial Infections Amoxicillin Dosage For Bladder Infection Xenical Orlistat 120 Mg Prix Sildenafil Kumagai Pfizer Prezzo Kamagra Use Of Keflex For Dogs
  3. MaribelKomin
    I see your site needs some unique & fresh content. Writing manually is time consuming, but there is solution for this. Just search for; Masquro's strategies
  4. Dennisendof
    Zhheherhrh eg egemtr hrggwe wes egemtrghdfbsgd rwtwrqw
  5. IsaacCloma
    Я делюсь секретами заработка в интернете и досконально все расписываю на моем секретном сайте: http://1-million-rubley.xyz Информация для поисковых систем: источник заработка интернете 72 успешные идеидополнительный заработок страховании 4015 1самые реальные СЃРїРѕСЃРѕР±С‹ заработка интернете 3 буквыкак заработать деньги онлайн без вложенийкак можно зарабатывать РІ интернете подросткам, заработать 200 СЂСѓР± РІ деньсколько можно заработать РЅР° копирайтинге РІ месяц отзывыp можно заработать жизни вторги РІ интернете как заработать icei можно заработать сочиняя стихи, заработать интернете 3 деньна чем можно заработать деньги РІ украине видеозаработок интернете написание комментариев htmlРЅР° чем можно заработать деньги бизнес идеи 6 РєРІ мможно зарабатывать деньги СЃРёРґСЏ декрете 2016.
  6. ND
    This post is helpful for me!!!Thanks!!
  7. Xavier
    I have done one like this but I get no price on the newly created product. Do you know what else do I need to do? Any other product types work fine!

Speak Your Mind

− 5 = 3