If a product has constraints on how many times it can be purchased (e.g., a one-time service), implement ProductLimitedInterface on your Item model.
You must implement the canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool method to define your constraint logic.
Recommendation: For shopping cart implementations, do not use the limited interface. Instead, use PurchaseQuery and PurchaseQueryHandlerInterface as the primary API for checking purchase availability.
use Bavix//
use Bavix//
use Bavix//
use Bavix//
class Item extends Model implements ProductLimitedInterface
{
use HasWallet;
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
{
// Implement constraint logic here
return true;
}
public function getAmountProduct(Customer $customer): int|string
{
return 100;
}
public function getMetaProduct(): ?array
{
return [
'title' => $this->title,
'description' => 'Purchase of Product #' . $this->id,
];
}
}