Your IP : 216.73.217.77


Current Path : /home/users/unlimited/www/api.xalonx.com/vendor/bavix/laravel-wallet/src/Services/
Upload File :
Current File : /home/users/unlimited/www/api.xalonx.com/vendor/bavix/laravel-wallet/src/Services/BasketService.php

<?php

declare(strict_types=1);

namespace Bavix\Wallet\Services;

use Bavix\Wallet\Interfaces\ProductLimitedInterface;
use Bavix\Wallet\Internal\Dto\AvailabilityDtoInterface;

/**
 * @internal
 */
final class BasketService implements BasketServiceInterface
{
    public function availability(AvailabilityDtoInterface $availabilityDto): bool
    {
        $basketDto = $availabilityDto->getBasketDto();
        $customer = $availabilityDto->getCustomer();
        foreach ($basketDto->items() as $itemDto) {
            $product = $itemDto->getProduct();
            if ($product instanceof ProductLimitedInterface && ! $product->canBuy(
                $customer,
                $itemDto->count(),
                $availabilityDto->isForce()
            )) {
                return false;
            }
        }

        return true;
    }
}