feat(inventory): add InventorySubject enum and integrate into catalog item management
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Purchase\Services\Checkout;
|
||||
|
||||
use App\Domains\Catalog\Enums\InventorySubject;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
|
||||
class InsufficientStockMessageBuilder
|
||||
{
|
||||
public function build(
|
||||
CatalogItem $catalogItem,
|
||||
CatalogItem|Variant $selection,
|
||||
int $availableQuantity,
|
||||
): string {
|
||||
return match ($catalogItem->inventory_subject) {
|
||||
InventorySubject::Seat => __('api.purchase.stock.seat_unavailable', [
|
||||
'selection' => $selection->getSelectionLabel(),
|
||||
]),
|
||||
InventorySubject::Ticket => __('api.purchase.stock.ticket_unavailable', [
|
||||
'selection' => $selection->getSelectionLabel(),
|
||||
]),
|
||||
InventorySubject::Product => __('api.purchase.stock.product_unavailable', [
|
||||
'selection' => $this->productSelectionLabel($catalogItem, $selection),
|
||||
'max' => $availableQuantity,
|
||||
]),
|
||||
};
|
||||
}
|
||||
|
||||
private function productSelectionLabel(
|
||||
CatalogItem $catalogItem,
|
||||
CatalogItem|Variant $selection,
|
||||
): string {
|
||||
if ($selection instanceof CatalogItem) {
|
||||
return $selection->getSelectionLabel();
|
||||
}
|
||||
|
||||
return __('api.purchase.stock.product_selection', [
|
||||
'product' => $catalogItem->getName(),
|
||||
'selection' => $selection->getSelectionLabel(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user