mivita/app/Services/ProductOrderContext.php
2026-04-10 17:15:27 +02:00

51 lines
1.3 KiB
PHP

<?php
namespace App\Services;
use App\Models\Product;
class ProductOrderContext
{
/**
* @return list<string>
*/
public static function allowedShowOnIds(bool $isAbo, string $shippingIsFor): array
{
if ($shippingIsFor === 'me' || $shippingIsFor === 'abo-me') {
return $isAbo ? ['12', '13'] : ['2'];
}
return $isAbo ? ['12', '13'] : ['3'];
}
/**
* @param list<string> $allowedIds
*/
public static function productMatchesShowOn(Product $product, array $allowedIds): bool
{
$showOn = $product->show_on;
if (! is_array($showOn)) {
return false;
}
foreach ($allowedIds as $id) {
foreach ($showOn as $value) {
if ((string) $value === (string) $id) {
return true;
}
}
}
return false;
}
public static function isProductAllowedInContext(Product $product, bool $isAbo, string $shippingIsFor): bool
{
return self::productMatchesShowOn($product, self::allowedShowOnIds($isAbo, $shippingIsFor));
}
public static function isProductAllowedInCustomerWebshop(Product $product): bool
{
return self::isProductAllowedInContext($product, false, 'ot-customer');
}
}