itmosoft / laravel-contract-pricing
Customer-specific contract price lists and quantity-based negotiated product pricing for Laravel applications.
Package info
github.com/ITMOSOFT/laravel-contract-pricing
pkg:composer/itmosoft/laravel-contract-pricing
Requires
- php: ^8.3
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.5|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Customer-specific price lists and negotiated product prices for Laravel 12 and 13.
Requirements
- PHP 8.3+
- Laravel 12 or 13
Installation
composer require itmosoft/laravel-contract-pricing php artisan vendor:publish --tag=contract-pricing-config php artisan migrate
Laravel package discovery registers the service provider automatically.
Create a customer-specific price list
Customer and product references are polymorphic, so this package does not require a specific company, customer, or product model.
use ItmoSoft\ContractPricing\Models\ContractPriceList; $list = ContractPriceList::create([ 'name' => 'Acme annual contract', 'customer_type' => App\Models\Company::class, 'customer_id' => $company->id, 'currency' => 'USD', 'priority' => 50, 'is_active' => true, 'valid_from' => now(), 'valid_until' => now()->addYear(), ]); $list->prices()->create([ 'product_type' => App\Models\Product::class, 'product_id' => $product->id, 'min_quantity' => 1, 'unit_price' => 89.50, ]); $list->prices()->create([ 'product_type' => App\Models\Product::class, 'product_id' => $product->id, 'min_quantity' => 25, 'unit_price' => 82.00, ]);
Resolve a contract price
use ItmoSoft\ContractPricing\ContractPriceResolver; $price = app(ContractPriceResolver::class)->resolve( customer: $company, product: $product, quantity: 30, currency: 'USD', ); if ($price) { $unitPrice = $price->unitPrice; $currency = $price->currency; }
Resolution behavior:
- Match price lists assigned to the customer.
- Ignore inactive or out-of-date lists.
- Apply the requested currency when supplied.
- Check lists by descending priority.
- Within the first list with a matching product, select the highest
min_quantitythat does not exceed the requested quantity.
A missing match returns null. The caller can then fall back to standard
catalog pricing.
Important pricing rules
prioritydetermines which matching price list wins.- Quantity breaks use
min_quantitythresholds. - Currency belongs to the price list, not individual price rows.
unit_priceis stored to four decimal places.- The resolver returns a value object and does not mutate cart or order prices.
- Applications should snapshot the resolved unit price and currency onto checkout/order line items.
Scope boundaries
This package resolves negotiated prices. It does not implement customer authentication, contract signatures, quote negotiation, tax calculation, discount stacking, cart integration, price approval workflows, or order price snapshots. Those concerns belong in the relevant application or commerce packages.
Testing
composer install
composer test
License
MIT.