MODULE TO CREATE A NEW PRODUCT TYPE IN MAGENTO

Firstly you need to follow the basic steps that are used for starting a module:

Step1: Create a vendor folder inside app/code (app is the core folder of Magento)

Folder:- app/code/Pravams (Vendor’s name could be any)

Step2: Create a module folder inside app/code/Pravams

Folder:-app/code/Pravams/Booking

Step3: Now inside Booking create a registration.php file.

File:-app/code/Pravams/Booking/registration.php

<?php
\Magento\Framework\ComponentRegistrar::register(
         \Magento\Framework\Component\ComponentRegistrar::MODULE,
         'Pravams_Booking',
          __DIR__
);

Step4: Create a etc folder inside your Module

Folder:- app/code/Pravams/Booking/etc

Step 5: Now again inside etc folder create another file module.xml and write the below written code

Folder:- app/code/Pravams/Booking/etc/module.xml

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Pravams_Booking" setup_version="1.0.2">  
    </module>
</config>

Step6: Create product_type.xml inside etc folder and write below written code

Folder:- app/code/Pravams/Booking/etc/product_type.xml

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/product_types.xsd">
    <type name="booking" label="booking" modelInstance="Pravams\Booking\Model\Product\Type\Booking" indexPriority ="60" sortOrder="80" isQty="true">
        <priceModel instance="Pravams\Booking\Model\Product\Price" />
    </type>
</config>

Step7: Create Model folder inside app/code/Pravams/Booking

Folder:- app/code/Pravams/Booking/Model

Step8 Create Product folder inside app/code/Pravams/Booking/Model

Folder:- app/code/Pravams/Booking/Model/Product

Step9: Create Type folder inside app/code/Pravams/Booking/Model

Folder:- app/code/Pravams/Booking/Model/Product/Type

Step10: Now create a Booking.php file inside Type folder

File:- app/code/Pravams/Booking/Model/Product/Type/Booking.php

(After creating the file write the given code)

<?php
namespace Pravams\Booking\Model\Product\Type;

class Booking extends \Magento\Catalog\Model\Product\Type\AbstractType {
    const TYPE_ID = 'booking';
    /**
     * Delete data specific for this product type
     * 
     * @param \Magento\Catalog\Model\Product $product
     * @return void
     */
public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product) {
}

public function isVirtual($product) {
        return true;
       }
}

Step11: Now inside Product folder create a file Price.php

File: app/code/Pravams/Booking/Model/Product/Price.php

<?php 
namespace Pravams\Booking\Model\Product;
class Price extends \Magento\Catalog\Model\Product\Type\Price
{

} 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.