darvis / manta-product
Products, attributes & variants with unit pricing (meter/m2/m3) for Laravel. Includes gift cards, shopping cart, and reservation compatibility.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/darvis/manta-product
Requires
- php: ^8.2
- illuminate/support: ^12.0
Requires (Dev)
- orchestra/testbench: ^10.6
This package is auto-updated.
Last update: 2025-11-05 14:38:07 UTC
README
A powerful Laravel package for managing products, attributes and variants with advanced unit pricing (meter/mยฒ/mยณ). Perfect for e-commerce and reservation systems.
โจ Features
- ๐ท๏ธ Products with dimensions (mm) and unit pricing (piece/meter/mยฒ/mยณ)
- ๐จ Attributes & Values (e.g. Color, Size, Material)
- ๐ Product Variants with per-variant price/stock/capacity/dimension overrides
- ๐งฎ Variant Matrix Generator (cartesian product builder)
- ๐ Gift Cards with balance tracking and redemption system
- ๐ Shopping Cart with product and gift card support
- ๐ Reservations & Availability (optional)
- ๐ Zero routes - pure Eloquent package with migrations & config
- ๐งช Laravel 12 compatible with PHP 8.2+
Opinionated design: Integers for dimensions (mm), alphabetically sorted keys, clean code comments.
๐ Table of Contents
๐ Installation
composer require darvis/manta-product php artisan vendor:publish --tag=manta-product-config php artisan migrate
Laravel will auto-discover the service provider.
โ๏ธ Configuration
See config/manta-product.php for all options like tax rate, rounding mode and SKU pattern.
๐ Full configuration documentation
โก Quick Start
use Manta\Products\Models\Product; use Manta\Products\Models\Attribute; use Manta\Products\Services\VariantMatrixService; // 1. Create a product $product = Product::create([ 'title' => 'Aluminum Profile', 'unit_type' => 'meter', 'price_per_unit' => 14.95, 'calc_mode' => 'direct_length', ]); // 2. Add attributes $color = Attribute::create(['name' => 'Color', 'code' => 'color']); $product->attributes()->attach($color->id); // 3. Generate variants $service = new VariantMatrixService(); $service->generate($product, ['color' => ['red', 'blue']]); // 4. Calculate pricing $pricing = $product->priceForUnits(['length_mm' => 2500]); // 2.5m echo "Price: โฌ{$pricing['price_incl']}";
๐ Documentation
- ๐ฆ Installation
- โ๏ธ Configuration
- ๐๏ธ Models
- ๐ก Usage
- ๐ Variants
- ๐ฐ Unit Pricing
- ๐ง Extending
- ๐ Reservations
- ๐ Availability
- ๐ง Troubleshooting
- ๐ Gift Cards
๐๏ธ Database Overview
productsโ Base product with unit pricing and dimensions (mm)attributes,attribute_valuesโ Properties like Color/Sizeproduct_attributesโ Pivot table for product โ attribute linkingproduct_variants,product_variant_valuesโ Variant matrix + valuesmanta_gift_cardsโ Digital gift cards with balance trackingmanta_carts,manta_cart_itemsโ Shopping cart functionality
This package does not include orders or reservations โ keep those in your app.
๐๏ธ Models & Helpers
Product
use Manta\Products\Models\Product; $product = Product::create([ 'active' => true, 'title' => 'Aluminium profiel', 'slug' => 'aluminium-profiel', 'product_type' => 'sellable', // or bookable|both 'unit_type' => 'meter', // meter|m2|m3|piece 'price_per_unit' => 14.95, 'tax_rate' => 21.00, 'calc_mode' => 'direct_length', // direct_length|dimensions_2d|dimensions_3d 'unit_step' => 0.01, ]); // Set dimensions in meters via accessors (stored as mm) $product->lengthM = 2.5; // => length_mm = 2500 $product->save(); $units = $product->normalizeUnits(['length_mm' => 2750]); // 2.75m -> step/rounding applied $prices = $product->priceForUnits($units);
Attributes & Values
use Manta\Products\Models\Attribute; use Manta\Products\Models\AttributeValue; $color = Attribute::create(['name' => 'Kleur','code' => 'color','type' => 'color_swatches']); AttributeValue::create(['attribute_id'=>$color->id,'value'=>'Rood','code'=>'red','hex'=>'#ff0000']); AttributeValue::create(['attribute_id'=>$color->id,'value'=>'Blauw','code'=>'blue','hex'=>'#0000ff']);
Attach attribute to product (defines axis order in UI):
$product->attributes()->attach($color->id, ['is_required'=>true, 'sort'=>1]);
Variants
use Manta\Products\Services\VariantMatrixService; $service = new VariantMatrixService(); $service->generate($product, [ 'color' => ['red','blue'], ]);
Find variant by selected values:
use Manta\Products\Models\ProductVariant; $variant = ProductVariant::where('product_id', $product->id) ->where('variant_key', 'color:red') ->first();
Variants can override pricing/dimensions/capacity:
$variant->update([ 'price_override_excl' => 15.95, 'capacity' => 2, // useful for bookable stock 'length_mm' => 3000, ]);
Tips
- Store raw mm in DB; use
lengthM/widthM/heightMto work in meters from code. - Use
variant_key(e.g.color:red|size:l) for fast lookups in UI. - Keep orders/reservations in your app, but store
product_idand optionalproduct_variant_idon line items.
Extending
- Add your own Price Rules table and reference
product_id(and optionalproduct_variant_id) with aprioritycolumn. - Add media tables to link images per product/variant.
- Create observers or policies as needed; package keeps concerns minimal.
๐งช Testing
The package includes basic test setup. Recommended tests:
# Run tests (when available) composer test # Run static analysis composer analyse
Recommended test coverage:
- Model factories for Product/Attribute/Variant
- Unit tests for
VariantMatrixService - Unit calc helpers testing
- Integration tests for pricing
๐ค Contributing
We welcome contributions! See CONTRIBUTING.md for details.
- ๐ Bug reports: Use the bug report template
- โจ Feature requests: Use the feature request template
- ๐ง Pull requests: Follow the PR template
๐ Security
For security issues, see SECURITY.md for responsible disclosure.
๐ License
This package is open source software licensed under the MIT license.
Reservations & Availability (optional add-on in this package)
This package includes neutral tables to support booking flows:
resources,roomsopening_hours,calendar_exceptionsreservations,reservation_items,holds
The package does not define your
users,staff, orcustomerstables. Foreign keys are nullable for portability.
Basic availability
Use Manta\Products\Services\AvailabilityService to compute used quantity (reservations + active holds) for an interval. Compare that to your products.capacity or rooms.capacity to decide availability.
Demo (optioneel)
Enable demo screens and routes:
// config/manta-product.php 'enable_demo' => true, 'demo_prefix' => 'manta-product-demo',
Then visit /manta-product-demo to see:
- Product list
- 7-day slot generator based on opening hours & exceptions
Seed demo data:
php artisan db:seed --class="Manta\Products\Database\Seeders\MantaProductsDemoSeeder"
Tables (overview)
- products (now includes optional resource_id)
- attributes, attribute_values
- product_attributes (pivot productโattribute)
- product_variants, product_variant_values
- resources, rooms
- opening_hours (polymorphic: products/resources/rooms)
- calendar_exceptions (polymorphic)
- price_rules
- reservations, reservation_items, holds