Search by

itmosoft / laravel-product-variants

adeelrao007

Product variants, SKUs, option values and price overrides for Laravel eCommerce applications.

Package info

github.com/ITMOSOFT/laravel-product-variants

pkg:composer/itmosoft/laravel-product-variants

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-14 08:24 UTC

This package is auto-updated.

Last update: 2026-11-14 08:26:04 UTC


README

Product variants, SKUs, option values and variant-level price overrides for Laravel 12 and 13.

Features

  • Attach variants to any Eloquent product model through a polymorphic relation.
  • SKU and barcode fields.
  • JSON option values such as size, color, material and capacity.
  • Optional price, compare-at price, cost and weight overrides.
  • Active/inactive state and sort order.
  • One default variant per product through manager operations.
  • Configurable variant model and table prefix.
  • Laravel package auto-discovery and migrations.

Requirements

  • PHP 8.3+
  • Laravel 12 or 13

Installation

composer require itmosoft/laravel-product-variants
php artisan vendor:publish --tag=product-variants-config
php artisan migrate

Add variants to your product model

use Illuminate\Database\Eloquent\Model;
use ItmoSoft\ProductVariants\Concerns\HasProductVariants;

class Product extends Model
{
    use HasProductVariants;
}

Create variants

use ItmoSoft\ProductVariants\ProductVariantsManager;

$variant = app(ProductVariantsManager::class)->create($product, [
    'name' => 'Large / Black',
    'sku' => 'TSHIRT-L-BLK',
    'barcode' => '1234567890123',
    'options' => [
        'size' => 'Large',
        'color' => 'Black',
    ],
    'price' => 29.99,
    'compare_at_price' => 34.99,
    'cost' => 12.50,
    'weight' => 0.350,
    'is_default' => true,
]);

Query variants

$product->variants;
$product->activeVariants;
$product->defaultVariant();

Update and manage variants

$manager = app(ProductVariantsManager::class);

$manager->update($variant, ['price' => 27.99]);
$manager->setDefault($variant);
$manager->deactivate($variant);
$manager->activate($variant);
$manager->delete($variant);

Configuration

Publish product-variants-config to customize:

  • table_prefix
  • models.variant
  • allow_duplicate_skus
  • sku.required
  • sku.max_length

SKU uniqueness is global at the database table level in this initial release. If your store needs SKU uniqueness per tenant or per vendor, customize the migration and validation policy accordingly.

Testing

composer install
composer validate --strict
composer test

Scope and integration boundaries

This package manages variant identity, option data and optional variant-level commercial values. It does not create product attributes or option definitions, generate every possible option combination, manage inventory/stock, reserve stock, calculate final prices, manage images, or expose HTTP routes/controllers. Those responsibilities belong to the catalog, attributes, inventory, pricing and storefront layers.

The application must validate option names and values against its product attribute rules. Do not trust client-supplied prices, costs, SKU ownership or variant IDs without authorization and server-side validation.

License

MIT.