32 lines
985 B
PHP
32 lines
985 B
PHP
<?php
|
|
|
|
namespace App\Domains\Purchase\Exceptions;
|
|
|
|
use App\Domains\Catalog\Models\CatalogItem;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class PurchaseLimitExceededException extends ValidationException
|
|
{
|
|
public readonly int $catalogItemId;
|
|
|
|
public readonly string $catalogItemName;
|
|
|
|
public readonly int $maximumAddableQuantity;
|
|
|
|
public function __construct(CatalogItem $catalogItem, int $maximumAddableQuantity, string $field)
|
|
{
|
|
$this->catalogItemId = (int) $catalogItem->getKey();
|
|
$this->catalogItemName = $catalogItem->nombre;
|
|
$this->maximumAddableQuantity = $maximumAddableQuantity;
|
|
|
|
parent::__construct(validator([], []));
|
|
|
|
$message = trans_choice('api.purchase_limit.exceeded', $maximumAddableQuantity, [
|
|
'max' => $maximumAddableQuantity,
|
|
'product' => $this->catalogItemName,
|
|
]);
|
|
$this->message = $message;
|
|
$this->validator->errors()->add($field, $message);
|
|
}
|
|
}
|