Skip to content

Getting Started

A product type in Bagisto decides how a product behaves: whether it ships, how its stock and price are checked, and what goes into the cart. This section registers a custom type from a package, explains the class behind it, then turns it into a subscription a customer can buy, without editing a core package.

What You'll Build

Webkul\SubscriptionProduct, a package that adds the product type subscription:

  • Subscription in the admin's product type list, backed by its own class
  • no shipping step at checkout for a cart of subscriptions
  • a weekly, monthly or yearly frequency the customer picks on the product page, kept on the cart item and the order item

The type records the frequency the customer chose; it doesn't bill renewals.

How It Works

Paths are relative to packages/Webkul/SubscriptionProduct/src.

PartFilePlugs into
Product type configurationConfig/product_types.phpMerged into config('product_types'); the admin's type list reads it, and Product::getTypeInstance() resolves its class
Product type classType/Subscription.phpExtends Webkul\Product\Type\AbstractType; decides shipping, stock, the cart rows and the price indexer
TranslationsResources/lang/en/app.phpThe subscription:: namespace: the type's name and the storefront labels
Product page fieldResources/views/shop/products/frequency.blade.phpThe bagisto.shop.products.short_description.after view render event
Service providerProviders/SubscriptionServiceProvider.phpMerges the configuration and loads the translations, views and listener; listed in bootstrap/providers.php

Unlike a shipping or payment method, a product type has no section in the admin configuration. A product's data stays in the attributes of its attribute family; the type class decides what Bagisto does with it.

Prerequisites

The Path

  1. Creating Your First Product Type: register the type and create a product of it in the admin.
  2. Understanding Product Type Configuration: the product_types.php keys, core's seven types, and overriding one.
  3. Understanding the AbstractType Class: the properties and methods a type overrides.
  4. Building Your Subscription Product Type: the frequency field, the cart rows and a checkout without shipping.

Next Step

Start by registering the type.

Continue to: Creating Your First Product Type

Released under the MIT License.