* Product catalogue * Product categories * Physical, digital, service, and bundle product types * Product variants and option storage * SKU management * Product publishing states * Pricing and comparison pricing * Inventory quantities * Low-stock thresholds * Inventory movement history * Customer records and addresses * Orders and order items * Payment and fulfilment statuses * Payment transaction storage * Promotions and coupon codes * Shipping methods * Tax rates * Payment, shipping, tax, and inventory provider contracts * Default manual payment provider * Default flat-rate shipping provider * Public product REST API * Administration navigation * Commerce permissions * Module registration * Module boot tests
15 lines
751 B
PHP
15 lines
751 B
PHP
<?php
|
|
namespace Modules\Commerce\Services;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\Commerce\Contracts\InventoryProvider;
|
|
use Modules\Commerce\Models\InventoryMovement;
|
|
use Modules\Commerce\Models\Product;
|
|
final class DatabaseInventoryProvider implements InventoryProvider
|
|
{
|
|
public function adjust(Product $product, int $quantity, string $reason, ?int $userId = null): void
|
|
{
|
|
DB::transaction(function () use ($product,$quantity,$reason,$userId) { $product->increment('stock_quantity',$quantity); InventoryMovement::create(['product_id'=>$product->id,'quantity'=>$quantity,'reason'=>$reason,'created_by'=>$userId]); });
|
|
}
|
|
public function available(Product $product): int { return max(0,(int)$product->stock_quantity); }
|
|
}
|