Updated the OrderService to utilize the new fromBasket method for creating orders, enhancing code clarity and maintainability. Removed the ProductAvailabilityService as its functionality is now integrated into the ProductRepository.
34 lines
746 B
PHP
34 lines
746 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Policies\Frontend;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\User;
|
|
use Domain\Models\ValueObjects\BasketProduct;
|
|
use Domain\Ports\Repositories\ProductRepository;
|
|
|
|
class BasketPolicy
|
|
{
|
|
public function __construct(
|
|
private readonly ProductRepository $productRepository
|
|
) {
|
|
}
|
|
|
|
public function viewTotal(null | User | Customer $_): bool
|
|
{
|
|
return $_ !== null;
|
|
}
|
|
|
|
public function viewPrices(null | User | Customer $_, BasketProduct $product): bool
|
|
{
|
|
if ($_ === null) {
|
|
return false;
|
|
}
|
|
|
|
$domainProduct = $this->productRepository->find($product->id);
|
|
|
|
return $domainProduct && $domainProduct->isPublished();
|
|
}
|
|
}
|