# Product Type
# Introduction
Bagisto provides several default product types, including simple, configurable, virtual, grouped, downloadable, bundled, and bookings. However, if these default product types do not meet your requirements, you can create your own custom product types.
# Creating a New Product Type
To create a new product type in Bagisto, follow these steps:
Note: In this example, we will create a new product type called "coupon".
Create your own package. If you need assistance with package development, you can refer to the Package Development section.
Inside the Config folder of your package, create a file named
product_types.php
.Add the following code to the
product_types.php
file. This code will define the new product type and its properties:<?php return [ 'coupon' => [ 'key' => 'coupon', 'name' => 'Coupon', 'class' => 'Webkul\Blog\Type\Coupon', 'sort' => 7 ], ];
# Merging the Configuration
To merge the
Config/product_types.php
with the core product types configuration, use themergeConfigFrom()
method in theregister()
method of your service provider. For example, in theCouponServiceProvider.php
file:<?php namespace Webkul\Blog\Providers; use Illuminate\Support\ServiceProvider; class CouponServiceProvider extends ServiceProvider { /** * Register services. * * @return void */ public function register() { //... $this->mergeConfigFrom( dirname(__DIR__) . '/Config/product_types.php', 'product_types' ); } }
In the code snippet above, notice the
class
key mentioned in step 3. This key specifies the class that loads the coupon product type. Create a file namedCoupon.php
within your package under thesrc/Type
folder, and add the following code:<?php namespace Webkul\Blog\Type; use Webkul\Product\Type\AbstractType; class Coupon extends AbstractType { }
After completing the above steps, your product type will be created. However, the
Type/Coupon.php
file does not have any code specific to the coupon type product yet. To inherit the basic functionality of any product type, you need to extend the classes from the Product package, specifically thetype/AbstractType.php
file.By extending the
AbstractType.php
class in your product type (Type/Coupon.php
), you can provide the core functionality of a product. Additionally, if you need to define custom methods for your product type, you can do so within theCoupon.php
file.