- Implement tests for product publication status. - Add tests for product orderability based on various conditions. - Enhance pricing calculation tests for different discount scenarios. - Remove outdated PricingServiceTest and refactor ProductAvailabilityServiceTest.
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Policies\Frontend;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\Product;
|
|
use App\Models\User;
|
|
use Domain\Ports\Repositories\ProductRepository;
|
|
|
|
class ProductPolicy
|
|
{
|
|
public function __construct(
|
|
private readonly ProductRepository $productRepository
|
|
) {
|
|
}
|
|
|
|
public function viewPublished(null | Customer | User $_, Product $product): bool
|
|
{
|
|
$domainProduct = $this->productRepository->find($product->getId());
|
|
|
|
return $domainProduct && $domainProduct->isPublished();
|
|
}
|
|
|
|
public function addToBasket(null | User | Customer $_, Product $product): bool
|
|
{
|
|
$domainProduct = $this->productRepository->find($product->getId());
|
|
|
|
return $domainProduct && $domainProduct->isOrderable();
|
|
}
|
|
|
|
public function viewPrices(null | User | Customer $_, Product $product): bool
|
|
{
|
|
if (! ($_ instanceof Customer || $_ instanceof User)) {
|
|
return false;
|
|
}
|
|
|
|
$domainProduct = $this->productRepository->find($product->getId());
|
|
|
|
return $domainProduct && $domainProduct->isPublished();
|
|
}
|
|
}
|