Compare commits
1 Commits
feature/al
...
87a4fa6288
| Author | SHA1 | Date | |
|---|---|---|---|
| 87a4fa6288 |
@@ -123,10 +123,6 @@ class CatalogController extends Controller
|
|||||||
$variantId === null ? null : (int) $variantId,
|
$variantId === null ? null : (int) $variantId,
|
||||||
);
|
);
|
||||||
$allowances->attach(collect([$item]), $this->userId($request));
|
$allowances->attach(collect([$item]), $this->userId($request));
|
||||||
abort_unless($allowances->availability(
|
|
||||||
$item->availableStock(),
|
|
||||||
$item->getAttribute('remaining_user_quota'),
|
|
||||||
)->isVisible(), 404);
|
|
||||||
|
|
||||||
return CatalogItemDetailResource::make($item);
|
return CatalogItemDetailResource::make($item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Catalog\Enums;
|
|
||||||
|
|
||||||
enum AvailabilityEffect: string
|
|
||||||
{
|
|
||||||
case Hide = 'hide';
|
|
||||||
case Restrict = 'restrict';
|
|
||||||
case Notice = 'notice';
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Catalog\Enums;
|
|
||||||
|
|
||||||
enum CatalogAction: string
|
|
||||||
{
|
|
||||||
case SelectVariant = 'select_variant';
|
|
||||||
case ChangeQuantity = 'change_quantity';
|
|
||||||
case AddToCart = 'add_to_cart';
|
|
||||||
case BuyNow = 'buy_now';
|
|
||||||
}
|
|
||||||
@@ -27,6 +27,7 @@ use Illuminate\Support\Collection;
|
|||||||
'type',
|
'type',
|
||||||
'slug',
|
'slug',
|
||||||
'nombre',
|
'nombre',
|
||||||
|
'group_order',
|
||||||
'descripcion',
|
'descripcion',
|
||||||
'precio',
|
'precio',
|
||||||
'inventory_policy',
|
'inventory_policy',
|
||||||
@@ -47,6 +48,7 @@ class CatalogItem extends Model
|
|||||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||||
'inventory_subject' => InventorySubject::Product->value,
|
'inventory_subject' => InventorySubject::Product->value,
|
||||||
'has_tickets' => false,
|
'has_tickets' => false,
|
||||||
|
'group_order' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
@@ -56,6 +58,7 @@ class CatalogItem extends Model
|
|||||||
'brand_id' => 'integer',
|
'brand_id' => 'integer',
|
||||||
'inventory_id' => 'integer',
|
'inventory_id' => 'integer',
|
||||||
'type' => CatalogItemType::class,
|
'type' => CatalogItemType::class,
|
||||||
|
'group_order' => 'integer',
|
||||||
'precio' => 'decimal:2',
|
'precio' => 'decimal:2',
|
||||||
'inventory_policy' => InventoryPolicy::class,
|
'inventory_policy' => InventoryPolicy::class,
|
||||||
'inventory_subject' => InventorySubject::class,
|
'inventory_subject' => InventorySubject::class,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
'tenant_code',
|
'tenant_code',
|
||||||
'categoria_id',
|
'categoria_id',
|
||||||
'nombre',
|
'nombre',
|
||||||
'is_enabled',
|
|
||||||
])]
|
])]
|
||||||
class Category extends Model
|
class Category extends Model
|
||||||
{
|
{
|
||||||
@@ -23,10 +22,6 @@ class Category extends Model
|
|||||||
|
|
||||||
protected $table = 'categorias';
|
protected $table = 'categorias';
|
||||||
|
|
||||||
protected $attributes = [
|
|
||||||
'is_enabled' => true,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string, string>
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
@@ -34,7 +29,6 @@ class Category extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'categoria_id' => 'integer',
|
'categoria_id' => 'integer',
|
||||||
'is_enabled' => 'boolean',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class StoreCatalogItemRequest extends FormRequest
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
'nombre' => ['required', 'string', 'max:255'],
|
'nombre' => ['required', 'string', 'max:255'],
|
||||||
|
'group_order' => ['sometimes', 'integer', 'min:0'],
|
||||||
'descripcion' => ['sometimes', 'nullable', 'string'],
|
'descripcion' => ['sometimes', 'nullable', 'string'],
|
||||||
'precio' => ['required', 'numeric', 'min:0'],
|
'precio' => ['required', 'numeric', 'min:0'],
|
||||||
'inventory_policy' => [Rule::prohibitedIf($isBundle), 'sometimes', Rule::enum(InventoryPolicy::class)],
|
'inventory_policy' => [Rule::prohibitedIf($isBundle), 'sometimes', Rule::enum(InventoryPolicy::class)],
|
||||||
|
|||||||
@@ -38,13 +38,19 @@ class CatalogFeaturedItemResource extends JsonResource
|
|||||||
'nombre' => $catalogItem->nombre,
|
'nombre' => $catalogItem->nombre,
|
||||||
'descripcion' => $catalogItem->descripcion,
|
'descripcion' => $catalogItem->descripcion,
|
||||||
'precio' => $catalogItem->precio,
|
'precio' => $catalogItem->precio,
|
||||||
'availability' => $this->availability($availableStock, $remainingUserQuota),
|
'maximum_addable_quantity' => $this->maximumAddable(
|
||||||
|
$availableStock,
|
||||||
|
$remainingUserQuota,
|
||||||
|
),
|
||||||
|
'unavailable_message' => $this->unavailableMessage(
|
||||||
|
$availableStock,
|
||||||
|
$remainingUserQuota,
|
||||||
|
),
|
||||||
'variants' => $catalogItem->variants
|
'variants' => $catalogItem->variants
|
||||||
->map(function (Variant $variant) use ($catalogItem): array {
|
->map(function (Variant $variant) use ($catalogItem, $remainingUserQuota): array {
|
||||||
$variantStock = $catalogItem->inventory_policy === InventoryPolicy::Unlimited
|
$variantStock = $catalogItem->inventory_policy === InventoryPolicy::Unlimited
|
||||||
? null
|
? null
|
||||||
: $variant->inventory->availableStock();
|
: $variant->inventory->availableStock();
|
||||||
$availability = $this->availability($variantStock, null);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $variant->id,
|
'id' => $variant->id,
|
||||||
@@ -54,11 +60,17 @@ class CatalogFeaturedItemResource extends JsonResource
|
|||||||
'event_dates' => $variant->selectedEventDates()->map(fn ($eventDate): string => $eventDate->date->format('Y-m-d'))->values(),
|
'event_dates' => $variant->selectedEventDates()->map(fn ($eventDate): string => $eventDate->date->format('Y-m-d'))->values(),
|
||||||
'descripcion' => $variant->getDescription(),
|
'descripcion' => $variant->getDescription(),
|
||||||
'precio' => number_format($variant->getPrice(), 2, '.', ''),
|
'precio' => number_format($variant->getPrice(), 2, '.', ''),
|
||||||
'availability' => $availability,
|
'maximum_addable_quantity' => $this->maximumAddable(
|
||||||
|
$variantStock,
|
||||||
|
$remainingUserQuota,
|
||||||
|
),
|
||||||
|
'unavailable_message' => $this->unavailableMessage(
|
||||||
|
$variantStock,
|
||||||
|
$remainingUserQuota,
|
||||||
|
),
|
||||||
'values' => $variant->selectorOptions($catalogItem->itemAttributes),
|
'values' => $variant->selectorOptions($catalogItem->itemAttributes),
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
->filter(fn (array $variant): bool => $variant['availability']['state'] === 'visible')
|
|
||||||
->values(),
|
->values(),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -78,7 +90,8 @@ class CatalogFeaturedItemResource extends JsonResource
|
|||||||
'descripcion' => $catalogItem->descripcion,
|
'descripcion' => $catalogItem->descripcion,
|
||||||
'precio' => $catalogItem->precio,
|
'precio' => $catalogItem->precio,
|
||||||
'image' => $this->firstImageUrl($catalogItem),
|
'image' => $this->firstImageUrl($catalogItem),
|
||||||
'availability' => $this->availability($availableStock, $remainingUserQuota),
|
'maximum_addable_quantity' => $this->maximumAddable($availableStock, $remainingUserQuota),
|
||||||
|
'unavailable_message' => $this->unavailableMessage($availableStock, $remainingUserQuota),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +107,8 @@ class CatalogFeaturedItemResource extends JsonResource
|
|||||||
'nombre' => $catalogItem->nombre,
|
'nombre' => $catalogItem->nombre,
|
||||||
'precio' => $catalogItem->precio,
|
'precio' => $catalogItem->precio,
|
||||||
'image' => $this->firstImageUrl($catalogItem),
|
'image' => $this->firstImageUrl($catalogItem),
|
||||||
'availability' => $this->availability($availableStock, $remainingUserQuota),
|
'maximum_addable_quantity' => $this->maximumAddable($availableStock, $remainingUserQuota),
|
||||||
|
'unavailable_message' => $this->unavailableMessage($availableStock, $remainingUserQuota),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,13 +122,15 @@ class CatalogFeaturedItemResource extends JsonResource
|
|||||||
return $attachment?->getTemporaryUrl(1440);
|
return $attachment?->getTemporaryUrl(1440);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
private function maximumAddable(?int $stock, ?int $remainingUserQuota): ?int
|
||||||
private function availability(
|
{
|
||||||
?int $stock,
|
|
||||||
?int $remainingUserQuota,
|
|
||||||
): array {
|
|
||||||
return app(CatalogItemAllowanceService::class)
|
return app(CatalogItemAllowanceService::class)
|
||||||
->availability($stock, $remainingUserQuota)
|
->maximumAddableQuantity($stock, $remainingUserQuota);
|
||||||
->toArray();
|
}
|
||||||
|
|
||||||
|
private function unavailableMessage(?int $stock, ?int $remainingUserQuota): ?string
|
||||||
|
{
|
||||||
|
return app(CatalogItemAllowanceService::class)
|
||||||
|
->unavailableMessage($stock, $remainingUserQuota);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,14 +38,20 @@ class CatalogItemDetailResource extends JsonResource
|
|||||||
'max_units_per_user' => $this->max_units_per_user,
|
'max_units_per_user' => $this->max_units_per_user,
|
||||||
'has_tickets' => $this->has_tickets,
|
'has_tickets' => $this->has_tickets,
|
||||||
'attributes' => $this->attributesData(),
|
'attributes' => $this->attributesData(),
|
||||||
'availability' => $this->availability($this->availableStock()),
|
'maximum_addable_quantity' => $this->when(
|
||||||
|
$selectedVariant === null,
|
||||||
|
fn () => $this->maximumAddable($this->availableStock()),
|
||||||
|
),
|
||||||
|
'unavailable_message' => $this->when(
|
||||||
|
$selectedVariant === null,
|
||||||
|
fn () => $this->unavailableMessage($this->availableStock()),
|
||||||
|
),
|
||||||
'images' => $this->when(
|
'images' => $this->when(
|
||||||
$selectedVariant === null,
|
$selectedVariant === null,
|
||||||
fn () => $this->imageUrls($this->attachments),
|
fn () => $this->imageUrls($this->attachments),
|
||||||
),
|
),
|
||||||
'variants' => $this->variants
|
'variants' => $this->variants
|
||||||
->map(fn (Variant $variant): array => $this->variantData($variant))
|
->map(fn (Variant $variant): array => $this->variantData($variant))
|
||||||
->filter(fn (array $variant): bool => $variant['availability']['state'] === 'visible')
|
|
||||||
->values(),
|
->values(),
|
||||||
'selected_variant' => $this->when(
|
'selected_variant' => $this->when(
|
||||||
$selectedVariant !== null,
|
$selectedVariant !== null,
|
||||||
@@ -158,10 +164,6 @@ class CatalogItemDetailResource extends JsonResource
|
|||||||
$values = $variant->selectionOptions($this->itemAttributes);
|
$values = $variant->selectionOptions($this->itemAttributes);
|
||||||
$eventDates = $variant->selectedEventDates();
|
$eventDates = $variant->selectedEventDates();
|
||||||
$variantStock = $this->variantStock($variant);
|
$variantStock = $this->variantStock($variant);
|
||||||
$availability = $this->availability(
|
|
||||||
$variantStock,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $variant->id,
|
'id' => $variant->id,
|
||||||
@@ -171,7 +173,8 @@ class CatalogItemDetailResource extends JsonResource
|
|||||||
'event_dates' => $eventDates->map(fn ($eventDate): string => $eventDate->date->format('Y-m-d'))->values(),
|
'event_dates' => $eventDates->map(fn ($eventDate): string => $eventDate->date->format('Y-m-d'))->values(),
|
||||||
'descripcion' => $variant->getDescription(),
|
'descripcion' => $variant->getDescription(),
|
||||||
'precio' => number_format($variant->getPrice(), 2, '.', ''),
|
'precio' => number_format($variant->getPrice(), 2, '.', ''),
|
||||||
'availability' => $availability,
|
'maximum_addable_quantity' => $this->maximumAddable($variantStock),
|
||||||
|
'unavailable_message' => $this->unavailableMessage($variantStock),
|
||||||
'values' => $values,
|
'values' => $values,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -191,14 +194,19 @@ class CatalogItemDetailResource extends JsonResource
|
|||||||
: $variant->inventory->availableStock();
|
: $variant->inventory->availableStock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
private function maximumAddable(?int $stock): ?int
|
||||||
private function availability(
|
{
|
||||||
?int $stock,
|
return app(CatalogItemAllowanceService::class)->maximumAddableQuantity(
|
||||||
bool $includeUserQuota = true,
|
|
||||||
): array {
|
|
||||||
return app(CatalogItemAllowanceService::class)->availability(
|
|
||||||
$stock,
|
$stock,
|
||||||
$includeUserQuota ? $this->getAttribute('remaining_user_quota') : null,
|
$this->getAttribute('remaining_user_quota'),
|
||||||
)->toArray();
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function unavailableMessage(?int $stock): ?string
|
||||||
|
{
|
||||||
|
return app(CatalogItemAllowanceService::class)->unavailableMessage(
|
||||||
|
$stock,
|
||||||
|
$this->getAttribute('remaining_user_quota'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,16 +28,13 @@ class CatalogSearchItemResource extends JsonResource
|
|||||||
'descripcion' => $this->descripcion,
|
'descripcion' => $this->descripcion,
|
||||||
'precio' => $this->precio,
|
'precio' => $this->precio,
|
||||||
'image' => $attachment?->getTemporaryUrl(1440),
|
'image' => $attachment?->getTemporaryUrl(1440),
|
||||||
'availability' => $this->availability($availableStock),
|
'maximum_addable_quantity' => $this->maximumAddable($availableStock),
|
||||||
|
'unavailable_message' => $this->unavailableMessage($availableStock),
|
||||||
'variants' => $this->variants
|
'variants' => $this->variants
|
||||||
->map(function (Variant $variant): array {
|
->map(function (Variant $variant): array {
|
||||||
$variantStock = $this->inventory_policy === InventoryPolicy::Unlimited
|
$variantStock = $this->inventory_policy === InventoryPolicy::Unlimited
|
||||||
? null
|
? null
|
||||||
: $variant->inventory?->availableStock();
|
: $variant->inventory?->availableStock();
|
||||||
$availability = $this->availability(
|
|
||||||
$variantStock,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $variant->id,
|
'id' => $variant->id,
|
||||||
@@ -47,23 +44,28 @@ class CatalogSearchItemResource extends JsonResource
|
|||||||
'event_dates' => $variant->selectedEventDates()->map(fn ($eventDate): string => $eventDate->date->format('Y-m-d'))->values(),
|
'event_dates' => $variant->selectedEventDates()->map(fn ($eventDate): string => $eventDate->date->format('Y-m-d'))->values(),
|
||||||
'descripcion' => $variant->getDescription(),
|
'descripcion' => $variant->getDescription(),
|
||||||
'precio' => number_format($variant->getPrice(), 2, '.', ''),
|
'precio' => number_format($variant->getPrice(), 2, '.', ''),
|
||||||
'availability' => $availability,
|
'maximum_addable_quantity' => $this->maximumAddable($variantStock),
|
||||||
|
'unavailable_message' => $this->unavailableMessage($variantStock),
|
||||||
'values' => $variant->selectorOptions($this->itemAttributes),
|
'values' => $variant->selectorOptions($this->itemAttributes),
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
->filter(fn (array $variant): bool => $variant['availability']['state'] === 'visible')
|
|
||||||
->values(),
|
->values(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
private function maximumAddable(?int $stock): ?int
|
||||||
private function availability(
|
{
|
||||||
?int $stock,
|
return app(CatalogItemAllowanceService::class)->maximumAddableQuantity(
|
||||||
bool $includeUserQuota = true,
|
|
||||||
): array {
|
|
||||||
return app(CatalogItemAllowanceService::class)->availability(
|
|
||||||
$stock,
|
$stock,
|
||||||
$includeUserQuota ? $this->getAttribute('remaining_user_quota') : null,
|
$this->getAttribute('remaining_user_quota'),
|
||||||
)->toArray();
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function unavailableMessage(?int $stock): ?string
|
||||||
|
{
|
||||||
|
return app(CatalogItemAllowanceService::class)->unavailableMessage(
|
||||||
|
$stock,
|
||||||
|
$this->getAttribute('remaining_user_quota'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Catalog\Services;
|
|
||||||
|
|
||||||
use App\Domains\Catalog\Enums\CatalogAction;
|
|
||||||
|
|
||||||
final readonly class AvailabilityDecision
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param list<CatalogAction> $allowedActions
|
|
||||||
* @param list<array{code: string, message: string}> $reasons
|
|
||||||
*/
|
|
||||||
private function __construct(
|
|
||||||
private bool $visible,
|
|
||||||
private ?int $maximumQuantity,
|
|
||||||
private array $allowedActions,
|
|
||||||
private array $reasons,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/** @param list<array{code: string, message: string}> $reasons */
|
|
||||||
public static function hidden(array $reasons): self
|
|
||||||
{
|
|
||||||
return new self(false, null, [], $reasons);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param list<CatalogAction> $allowedActions
|
|
||||||
* @param list<array{code: string, message: string}> $reasons
|
|
||||||
*/
|
|
||||||
public static function visible(
|
|
||||||
?int $maximumQuantity,
|
|
||||||
array $allowedActions,
|
|
||||||
array $reasons,
|
|
||||||
): self {
|
|
||||||
return new self(true, $maximumQuantity, $allowedActions, $reasons);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isVisible(): bool
|
|
||||||
{
|
|
||||||
return $this->visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
public function toArray(): array
|
|
||||||
{
|
|
||||||
if (! $this->visible) {
|
|
||||||
return [
|
|
||||||
'state' => 'hidden',
|
|
||||||
'reasons' => $this->reasons,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'state' => 'visible',
|
|
||||||
'maximum_quantity' => $this->maximumQuantity,
|
|
||||||
'allowed_actions' => array_map(
|
|
||||||
fn (CatalogAction $action): string => $action->value,
|
|
||||||
$this->allowedActions,
|
|
||||||
),
|
|
||||||
'reasons' => $this->reasons,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Catalog\Services;
|
|
||||||
|
|
||||||
use App\Domains\Catalog\Enums\AvailabilityEffect;
|
|
||||||
use App\Domains\Catalog\Enums\CatalogAction;
|
|
||||||
|
|
||||||
final class AvailabilityPolicyResolver
|
|
||||||
{
|
|
||||||
/** @return array{effect: AvailabilityEffect, denied_actions: list<CatalogAction>} */
|
|
||||||
public function resolve(string $restrictionCode): array
|
|
||||||
{
|
|
||||||
/** @var array{effect?: string, denied_actions?: list<string>} $configured */
|
|
||||||
$configured = config("catalog.availability.rules.{$restrictionCode}", []);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'effect' => AvailabilityEffect::from(
|
|
||||||
$configured['effect'] ?? AvailabilityEffect::Notice->value,
|
|
||||||
),
|
|
||||||
'denied_actions' => array_map(
|
|
||||||
fn (string $action): CatalogAction => CatalogAction::from($action),
|
|
||||||
$configured['denied_actions'] ?? [],
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Domains\Catalog\Services;
|
namespace App\Domains\Catalog\Services;
|
||||||
|
|
||||||
use App\Domains\Catalog\Enums\AvailabilityEffect;
|
|
||||||
use App\Domains\Catalog\Enums\CatalogAction;
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Purchase\Services\UserPurchaseLimitService;
|
use App\Domains\Purchase\Services\UserPurchaseLimitService;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -16,7 +14,6 @@ class CatalogItemAllowanceService
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly UserPurchaseLimitService $purchaseLimits,
|
private readonly UserPurchaseLimitService $purchaseLimits,
|
||||||
private readonly AvailabilityPolicyResolver $policies,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/** @param Collection<int, CatalogItem> $catalogItems */
|
/** @param Collection<int, CatalogItem> $catalogItems */
|
||||||
@@ -45,82 +42,16 @@ class CatalogItemAllowanceService
|
|||||||
return min($availableStock, $remainingUserQuota);
|
return min($availableStock, $remainingUserQuota);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function availability(
|
public function unavailableMessage(?int $availableStock, ?int $remainingUserQuota): ?string
|
||||||
?int $availableStock,
|
{
|
||||||
?int $remainingUserQuota,
|
|
||||||
): AvailabilityDecision {
|
|
||||||
$reasons = [];
|
|
||||||
|
|
||||||
if ($remainingUserQuota !== null && $remainingUserQuota <= 0) {
|
if ($remainingUserQuota !== null && $remainingUserQuota <= 0) {
|
||||||
$reasons[] = [
|
return self::USER_QUOTA_REACHED_MESSAGE;
|
||||||
'code' => 'user_quota_reached',
|
|
||||||
'message' => self::USER_QUOTA_REACHED_MESSAGE,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($availableStock !== null && $availableStock <= 0) {
|
if ($availableStock !== null && $availableStock <= 0) {
|
||||||
$reasons[] = [
|
return self::OUT_OF_STOCK_MESSAGE;
|
||||||
'code' => 'out_of_stock',
|
|
||||||
'message' => self::OUT_OF_STOCK_MESSAGE,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->decision(
|
return null;
|
||||||
$this->maximumAddableQuantity($availableStock, $remainingUserQuota),
|
|
||||||
$reasons,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function purchaseLimitExceededAvailability(
|
|
||||||
int $maximumQuantity,
|
|
||||||
string $message,
|
|
||||||
): AvailabilityDecision {
|
|
||||||
$reasons = [];
|
|
||||||
|
|
||||||
if ($maximumQuantity <= 0) {
|
|
||||||
$reasons[] = [
|
|
||||||
'code' => 'user_quota_reached',
|
|
||||||
'message' => self::USER_QUOTA_REACHED_MESSAGE,
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$reasons[] = [
|
|
||||||
'code' => 'requested_quantity_exceeds_user_quota',
|
|
||||||
'message' => $message,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->decision($maximumQuantity, $reasons);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param list<array{code: string, message: string}> $reasons
|
|
||||||
*/
|
|
||||||
private function decision(?int $maximumQuantity, array $reasons): AvailabilityDecision
|
|
||||||
{
|
|
||||||
/** @var list<string> $configuredActions */
|
|
||||||
$configuredActions = config('catalog.availability.default_actions', []);
|
|
||||||
$allowedActions = collect($configuredActions)
|
|
||||||
->map(fn (string $action): CatalogAction => CatalogAction::from($action));
|
|
||||||
|
|
||||||
foreach ($reasons as $reason) {
|
|
||||||
$policy = $this->policies->resolve($reason['code']);
|
|
||||||
|
|
||||||
if ($policy['effect'] === AvailabilityEffect::Hide) {
|
|
||||||
return AvailabilityDecision::hidden($reasons);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($policy['effect'] === AvailabilityEffect::Restrict) {
|
|
||||||
$deniedActions = $policy['denied_actions'];
|
|
||||||
$allowedActions = $allowedActions->reject(
|
|
||||||
fn (CatalogAction $action): bool => in_array($action, $deniedActions, true),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return AvailabilityDecision::visible(
|
|
||||||
$maximumQuantity,
|
|
||||||
$allowedActions->values()->all(),
|
|
||||||
$reasons,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
|
|
||||||
class CatalogService
|
class CatalogService
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(protected AttachmentService $attachmentService) {}
|
||||||
protected AttachmentService $attachmentService,
|
|
||||||
private readonly VisibleCatalogItemsQuery $visibleCatalogItems,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $data
|
* @param array<string, mixed> $data
|
||||||
@@ -232,7 +229,7 @@ class CatalogService
|
|||||||
$containsPattern = "%{$normalizedTerm}%";
|
$containsPattern = "%{$normalizedTerm}%";
|
||||||
$startsWithPattern = "{$normalizedTerm}%";
|
$startsWithPattern = "{$normalizedTerm}%";
|
||||||
|
|
||||||
$query = CatalogItem::query()
|
$paginator = CatalogItem::query()
|
||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
->where(function (Builder $query) use ($containsPattern): void {
|
->where(function (Builder $query) use ($containsPattern): void {
|
||||||
$query
|
$query
|
||||||
@@ -260,10 +257,7 @@ class CatalogService
|
|||||||
'variants.definitions.itemAttribute.attribute.options',
|
'variants.definitions.itemAttribute.attribute.options',
|
||||||
'bundleComponents.catalogItem',
|
'bundleComponents.catalogItem',
|
||||||
'bundleComponents.variant.catalogItem',
|
'bundleComponents.variant.catalogItem',
|
||||||
]);
|
])
|
||||||
|
|
||||||
$paginator = $this->visibleCatalogItems
|
|
||||||
->apply($query)
|
|
||||||
->orderByRaw(
|
->orderByRaw(
|
||||||
'CASE WHEN LOWER(nombre) = ? THEN 0 WHEN LOWER(nombre) LIKE ? THEN 1 ELSE 2 END',
|
'CASE WHEN LOWER(nombre) = ? THEN 0 WHEN LOWER(nombre) LIKE ? THEN 1 ELSE 2 END',
|
||||||
[$normalizedTerm, $startsWithPattern],
|
[$normalizedTerm, $startsWithPattern],
|
||||||
@@ -283,7 +277,7 @@ class CatalogService
|
|||||||
int $perPage,
|
int $perPage,
|
||||||
int $page,
|
int $page,
|
||||||
): LengthAwarePaginator {
|
): LengthAwarePaginator {
|
||||||
$query = CatalogItem::query()
|
return CatalogItem::query()
|
||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
->where('category_id', $category->id)
|
->where('category_id', $category->id)
|
||||||
->with([
|
->with([
|
||||||
@@ -297,10 +291,7 @@ class CatalogService
|
|||||||
'variants.definitions.itemAttribute.attribute.options',
|
'variants.definitions.itemAttribute.attribute.options',
|
||||||
'bundleComponents.catalogItem',
|
'bundleComponents.catalogItem',
|
||||||
'bundleComponents.variant.catalogItem',
|
'bundleComponents.variant.catalogItem',
|
||||||
]);
|
])
|
||||||
|
|
||||||
return $this->visibleCatalogItems
|
|
||||||
->apply($query)
|
|
||||||
->orderBy('nombre')
|
->orderBy('nombre')
|
||||||
->paginate(perPage: $perPage, pageName: 'page', page: $page);
|
->paginate(perPage: $perPage, pageName: 'page', page: $page);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ class FeaturedGroupService
|
|||||||
/** @return array<array-key, mixed> */
|
/** @return array<array-key, mixed> */
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly CatalogItemAllowanceService $allowances,
|
private readonly CatalogItemAllowanceService $allowances,
|
||||||
private readonly VisibleCatalogItemsQuery $visibleCatalogItems,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function itemsResponse(FeaturedGroup $featuredGroup, int $page, ?int $userId = null): array
|
public function itemsResponse(FeaturedGroup $featuredGroup, int $page, ?int $userId = null): array
|
||||||
@@ -50,15 +49,6 @@ class FeaturedGroupService
|
|||||||
{
|
{
|
||||||
$query = CatalogItem::query()
|
$query = CatalogItem::query()
|
||||||
->where('catalog_items.tenant_code', $featuredGroup->tenant_code)
|
->where('catalog_items.tenant_code', $featuredGroup->tenant_code)
|
||||||
->where(function (Builder $query): void {
|
|
||||||
$query
|
|
||||||
->whereDoesntHave('category')
|
|
||||||
->orWhereHas(
|
|
||||||
'category',
|
|
||||||
fn (Builder $categoryQuery): Builder => $categoryQuery
|
|
||||||
->where('is_enabled', true),
|
|
||||||
);
|
|
||||||
})
|
|
||||||
->with([
|
->with([
|
||||||
'inventory',
|
'inventory',
|
||||||
'attachments',
|
'attachments',
|
||||||
@@ -72,8 +62,6 @@ class FeaturedGroupService
|
|||||||
'bundleComponents.variant.catalogItem',
|
'bundleComponents.variant.catalogItem',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$query = $this->visibleCatalogItems->apply($query);
|
|
||||||
|
|
||||||
return match ($featuredGroup->source_type) {
|
return match ($featuredGroup->source_type) {
|
||||||
FeaturedGroupSource::Manual => $query
|
FeaturedGroupSource::Manual => $query
|
||||||
->select('catalog_items.*')
|
->select('catalog_items.*')
|
||||||
@@ -84,7 +72,9 @@ class FeaturedGroupService
|
|||||||
FeaturedGroupSource::Category => $query
|
FeaturedGroupSource::Category => $query
|
||||||
->where('catalog_items.category_id', $featuredGroup->category_id)
|
->where('catalog_items.category_id', $featuredGroup->category_id)
|
||||||
->orderBy('catalog_items.id'),
|
->orderBy('catalog_items.id'),
|
||||||
FeaturedGroupSource::All => $query->orderBy('catalog_items.id'),
|
FeaturedGroupSource::All => $query
|
||||||
|
->orderBy('catalog_items.group_order')
|
||||||
|
->orderBy('catalog_items.id'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ use Illuminate\Support\Collection;
|
|||||||
|
|
||||||
class VariantSelectionService
|
class VariantSelectionService
|
||||||
{
|
{
|
||||||
public function __construct(
|
|
||||||
private readonly CatalogItemAllowanceService $allowances,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $selectedValues
|
* @param array<string, mixed> $selectedValues
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
@@ -192,17 +188,13 @@ class VariantSelectionService
|
|||||||
/** @return array<string, mixed> */
|
/** @return array<string, mixed> */
|
||||||
private function variantData(CatalogItem $catalogItem, Variant $variant): array
|
private function variantData(CatalogItem $catalogItem, Variant $variant): array
|
||||||
{
|
{
|
||||||
$availableStock = $catalogItem->inventory_policy === InventoryPolicy::Unlimited
|
|
||||||
? null
|
|
||||||
: $variant->inventory?->availableStock();
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $variant->id,
|
'id' => $variant->id,
|
||||||
'descripcion' => $variant->getDescription(),
|
'descripcion' => $variant->getDescription(),
|
||||||
'precio' => number_format($variant->getPrice(), 2, '.', ''),
|
'precio' => number_format($variant->getPrice(), 2, '.', ''),
|
||||||
'availability' => $this->allowances
|
'stock_tecnico' => $catalogItem->inventory_policy === InventoryPolicy::Unlimited
|
||||||
->availability($availableStock, null)
|
? null
|
||||||
->toArray(),
|
: $variant->inventory?->availableStock(),
|
||||||
'values' => $variant->selectorOptions($catalogItem->itemAttributes),
|
'values' => $variant->selectorOptions($catalogItem->itemAttributes),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Catalog\Services;
|
|
||||||
|
|
||||||
use App\Domains\Catalog\Enums\AvailabilityEffect;
|
|
||||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
|
||||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
|
|
||||||
final class VisibleCatalogItemsQuery
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly AvailabilityPolicyResolver $policies,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/** @param Builder<CatalogItem> $query */
|
|
||||||
public function apply(Builder $query): Builder
|
|
||||||
{
|
|
||||||
if ($this->policies->resolve('out_of_stock')['effect'] !== AvailabilityEffect::Hide) {
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query->where(function (Builder $query): void {
|
|
||||||
$query
|
|
||||||
->where(fn (Builder $query) => $this->applyStandardItemAvailability($query))
|
|
||||||
->orWhere(fn (Builder $query) => $this->applyBundleAvailability($query));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param Builder<CatalogItem> $query */
|
|
||||||
private function applyStandardItemAvailability(Builder $query): Builder
|
|
||||||
{
|
|
||||||
return $query
|
|
||||||
->where('catalog_items.type', CatalogItemType::Standard->value)
|
|
||||||
->where(function (Builder $query): void {
|
|
||||||
$query
|
|
||||||
->where('catalog_items.inventory_policy', InventoryPolicy::Unlimited->value)
|
|
||||||
->orWhereHas(
|
|
||||||
'inventory',
|
|
||||||
fn (Builder $query): Builder => $query
|
|
||||||
->whereColumn('inventories.real_stock', '>', 'inventories.reserved_stock'),
|
|
||||||
)
|
|
||||||
->orWhereHas(
|
|
||||||
'variants.inventory',
|
|
||||||
fn (Builder $query): Builder => $query
|
|
||||||
->whereColumn('inventories.real_stock', '>', 'inventories.reserved_stock'),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param Builder<CatalogItem> $query */
|
|
||||||
private function applyBundleAvailability(Builder $query): Builder
|
|
||||||
{
|
|
||||||
return $query
|
|
||||||
->where('catalog_items.type', CatalogItemType::Bundle->value)
|
|
||||||
->whereRaw(<<<'SQL'
|
|
||||||
NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM bundle_components AS availability_components
|
|
||||||
INNER JOIN catalog_items AS availability_items
|
|
||||||
ON availability_items.id = availability_components.component_catalog_item_id
|
|
||||||
LEFT JOIN variantes AS availability_variants
|
|
||||||
ON availability_variants.id = availability_components.component_variant_id
|
|
||||||
INNER JOIN inventories AS availability_inventories
|
|
||||||
ON availability_inventories.id = COALESCE(
|
|
||||||
availability_variants.inventory_id,
|
|
||||||
availability_items.inventory_id
|
|
||||||
)
|
|
||||||
WHERE availability_components.bundle_catalog_item_id = catalog_items.id
|
|
||||||
AND availability_items.inventory_policy = ?
|
|
||||||
GROUP BY availability_inventories.id,
|
|
||||||
availability_inventories.real_stock,
|
|
||||||
availability_inventories.reserved_stock
|
|
||||||
HAVING availability_inventories.real_stock
|
|
||||||
- availability_inventories.reserved_stock
|
|
||||||
< SUM(availability_components.quantity)
|
|
||||||
)
|
|
||||||
SQL, [InventoryPolicy::Tracked->value]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\FiestaFutbolInfantil\Controllers;
|
|
||||||
|
|
||||||
use App\Domains\FiestaFutbolInfantil\Enums\FiestaCategory;
|
|
||||||
use App\Domains\FiestaFutbolInfantil\Requests\UpdateCategoryVisibilityRequest;
|
|
||||||
use App\Domains\FiestaFutbolInfantil\Services\CategoryVisibilityService;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class CategoryVisibilityController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct(private readonly CategoryVisibilityService $visibilityService) {}
|
|
||||||
|
|
||||||
public function show(Request $request): JsonResponse
|
|
||||||
{
|
|
||||||
$category = $this->category($request);
|
|
||||||
$tenant = $request->user()->tenant()->firstOrFail();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'data' => [
|
|
||||||
'is_enabled' => $this->visibilityService->isEnabled($tenant, $category),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(UpdateCategoryVisibilityRequest $request): JsonResponse
|
|
||||||
{
|
|
||||||
$category = $this->category($request);
|
|
||||||
$tenant = $request->user()->tenant()->firstOrFail();
|
|
||||||
$model = $this->visibilityService->update(
|
|
||||||
$tenant,
|
|
||||||
$category,
|
|
||||||
$request->boolean('is_enabled'),
|
|
||||||
);
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'data' => [
|
|
||||||
'is_enabled' => $model->is_enabled,
|
|
||||||
],
|
|
||||||
'message' => $model->is_enabled
|
|
||||||
? 'Mostrar en sitio web se activo correctamente'
|
|
||||||
: 'Mostrar en sitio web se desactivo correctamente',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function category(Request $request): FiestaCategory
|
|
||||||
{
|
|
||||||
return FiestaCategory::from((string) $request->route('category'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\FiestaFutbolInfantil\Enums;
|
|
||||||
|
|
||||||
enum FiestaCategory: string
|
|
||||||
{
|
|
||||||
case Entries = 'entries';
|
|
||||||
case Foods = 'foods';
|
|
||||||
case Accommodations = 'accommodations';
|
|
||||||
case Merchandise = 'merchandise';
|
|
||||||
|
|
||||||
public function categoryName(): string
|
|
||||||
{
|
|
||||||
return match ($this) {
|
|
||||||
self::Entries => 'Entradas',
|
|
||||||
self::Foods => 'Comidas',
|
|
||||||
self::Accommodations => 'Alojamientos',
|
|
||||||
self::Merchandise => 'Merchandising',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\FiestaFutbolInfantil\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class UpdateCategoryVisibilityRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'is_enabled' => ['required', 'boolean'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\FiestaFutbolInfantil\Services;
|
|
||||||
|
|
||||||
use App\Domains\Catalog\Models\Category;
|
|
||||||
use App\Domains\FiestaFutbolInfantil\Enums\FiestaCategory;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
|
|
||||||
class CategoryVisibilityService
|
|
||||||
{
|
|
||||||
public function isEnabled(Tenant $tenant, FiestaCategory $category): bool
|
|
||||||
{
|
|
||||||
return Category::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->where('nombre', $category->categoryName())
|
|
||||||
->value('is_enabled') ?? true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Tenant $tenant, FiestaCategory $category, bool $isEnabled): Category
|
|
||||||
{
|
|
||||||
$model = Category::query()->firstOrCreate([
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'nombre' => $category->categoryName(),
|
|
||||||
]);
|
|
||||||
$model->update(['is_enabled' => $isEnabled]);
|
|
||||||
|
|
||||||
return $model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Domains\FiestaFutbolInfantil\Controllers\AccommodationController;
|
use App\Domains\FiestaFutbolInfantil\Controllers\AccommodationController;
|
||||||
use App\Domains\FiestaFutbolInfantil\Controllers\CategoryVisibilityController;
|
|
||||||
use App\Domains\FiestaFutbolInfantil\Controllers\EntryController;
|
use App\Domains\FiestaFutbolInfantil\Controllers\EntryController;
|
||||||
use App\Domains\FiestaFutbolInfantil\Controllers\FoodController;
|
use App\Domains\FiestaFutbolInfantil\Controllers\FoodController;
|
||||||
use App\Domains\FiestaFutbolInfantil\Controllers\MerchandiseController;
|
use App\Domains\FiestaFutbolInfantil\Controllers\MerchandiseController;
|
||||||
@@ -10,20 +9,6 @@ use Illuminate\Support\Facades\Route;
|
|||||||
Route::prefix('v1/adminapp/tenant')
|
Route::prefix('v1/adminapp/tenant')
|
||||||
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
||||||
->group(function (): void {
|
->group(function (): void {
|
||||||
$visibilityRoutes = static function (string $endpoint, string $category, string $menuCode): void {
|
|
||||||
Route::get("{$endpoint}/visibility", [CategoryVisibilityController::class, 'show'])
|
|
||||||
->defaults('category', $category)
|
|
||||||
->middleware("tenant.menu:{$menuCode}");
|
|
||||||
Route::patch("{$endpoint}/visibility", [CategoryVisibilityController::class, 'update'])
|
|
||||||
->defaults('category', $category)
|
|
||||||
->middleware("tenant.menu:{$menuCode}");
|
|
||||||
};
|
|
||||||
|
|
||||||
$visibilityRoutes('entries', 'entries', 'adminapp.fiesta-futbol-infantil.entradas');
|
|
||||||
$visibilityRoutes('foods', 'foods', 'adminapp.fiesta-futbol-infantil.comida');
|
|
||||||
$visibilityRoutes('accommodations', 'accommodations', 'adminapp.fiesta-futbol-infantil.alojamientos');
|
|
||||||
$visibilityRoutes('merchandise', 'merchandise', 'adminapp.fiesta-futbol-infantil.merchandising');
|
|
||||||
|
|
||||||
Route::get('entries', [EntryController::class, 'index'])
|
Route::get('entries', [EntryController::class, 'index'])
|
||||||
->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.entradas')
|
->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.entradas')
|
||||||
->name('adminapp.fiesta-futbol-infantil.entries.index');
|
->name('adminapp.fiesta-futbol-infantil.entries.index');
|
||||||
|
|||||||
@@ -24,22 +24,13 @@ class PurchaseController extends Controller
|
|||||||
{
|
{
|
||||||
public function index(Request $request, Tenant $tenant): JsonResponse
|
public function index(Request $request, Tenant $tenant): JsonResponse
|
||||||
{
|
{
|
||||||
$statusParam = $request->query('status');
|
|
||||||
$statuses = is_string($statusParam)
|
|
||||||
? collect(explode(',', $statusParam))
|
|
||||||
->map(fn (string $status): string => trim($status))
|
|
||||||
->filter()
|
|
||||||
->unique()
|
|
||||||
->values()
|
|
||||||
->all()
|
|
||||||
: [];
|
|
||||||
|
|
||||||
return PurchaseResource::collection(
|
return PurchaseResource::collection(
|
||||||
Purchase::query()
|
Purchase::query()
|
||||||
->where('tenant_codigo', $tenant->codigo)
|
->where('tenant_codigo', $tenant->codigo)
|
||||||
->where('user_id', $request->user()->id)
|
->where('user_id', $request->user()->id)
|
||||||
->when($statuses !== [], fn ($query) => $query->whereIn('status', $statuses))
|
->when($request->query('status'), function ($query, $status) {
|
||||||
->orderBy('status')
|
$query->where('status', $status);
|
||||||
|
})
|
||||||
->latest()
|
->latest()
|
||||||
->paginateFromRequest()
|
->paginateFromRequest()
|
||||||
)->response();
|
)->response();
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Domains\Auth\Exceptions\AccountLockedException;
|
use App\Domains\Auth\Exceptions\AccountLockedException;
|
||||||
use App\Domains\Catalog\Services\CatalogItemAllowanceService;
|
|
||||||
use App\Domains\Purchase\Exceptions\InsufficientStockException;
|
use App\Domains\Purchase\Exceptions\InsufficientStockException;
|
||||||
use App\Domains\Purchase\Exceptions\PurchaseExpiredException;
|
use App\Domains\Purchase\Exceptions\PurchaseExpiredException;
|
||||||
use App\Domains\Purchase\Exceptions\PurchaseLimitExceededException;
|
use App\Domains\Purchase\Exceptions\PurchaseLimitExceededException;
|
||||||
@@ -101,11 +100,7 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
'errors' => $exception->errors(),
|
'errors' => $exception->errors(),
|
||||||
'catalog_item_id' => $exception->catalogItemId,
|
'catalog_item_id' => $exception->catalogItemId,
|
||||||
'catalog_item_name' => $exception->catalogItemName,
|
'catalog_item_name' => $exception->catalogItemName,
|
||||||
'availability' => app(CatalogItemAllowanceService::class)
|
'maximum_addable_quantity' => $exception->maximumAddableQuantity,
|
||||||
->purchaseLimitExceededAvailability(
|
|
||||||
$exception->maximumAddableQuantity,
|
|
||||||
$exception->getMessage(),
|
|
||||||
)->toArray(),
|
|
||||||
], 422);
|
], 422);
|
||||||
});
|
});
|
||||||
$exceptions->render(function (PurchaseExpiredException $exception, Request $request) {
|
$exceptions->render(function (PurchaseExpiredException $exception, Request $request) {
|
||||||
|
|||||||
@@ -2,33 +2,4 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'stock_reservation_expiration_minutes' => (int) env('STOCK_RESERVATION_EXPIRATION_MINUTES', 30),
|
'stock_reservation_expiration_minutes' => (int) env('STOCK_RESERVATION_EXPIRATION_MINUTES', 30),
|
||||||
'availability' => [
|
|
||||||
'default_actions' => [
|
|
||||||
'select_variant',
|
|
||||||
'change_quantity',
|
|
||||||
'add_to_cart',
|
|
||||||
'buy_now',
|
|
||||||
],
|
|
||||||
'rules' => [
|
|
||||||
'user_quota_reached' => [
|
|
||||||
'effect' => 'restrict',
|
|
||||||
'denied_actions' => [
|
|
||||||
'select_variant',
|
|
||||||
'change_quantity',
|
|
||||||
'add_to_cart',
|
|
||||||
'buy_now',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'out_of_stock' => [
|
|
||||||
'effect' => 'hide',
|
|
||||||
],
|
|
||||||
'requested_quantity_exceeds_user_quota' => [
|
|
||||||
'effect' => 'restrict',
|
|
||||||
'denied_actions' => [
|
|
||||||
'add_to_cart',
|
|
||||||
'buy_now',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::table('categorias', function (Blueprint $table): void {
|
|
||||||
$table->boolean('is_enabled')->default(true)->after('nombre');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('categorias', function (Blueprint $table): void {
|
|
||||||
$table->dropColumn('is_enabled');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||||
|
$table->unsignedInteger('group_order')->default(0)->after('nombre');
|
||||||
|
});
|
||||||
|
|
||||||
|
$footballOrder = [
|
||||||
|
1 => [
|
||||||
|
'slugs' => ['camiseta', 'camiseta-oficial-fnfi'],
|
||||||
|
'names' => ['Camiseta', 'CAMISETA OFICIAL FNFI'],
|
||||||
|
],
|
||||||
|
2 => [
|
||||||
|
'slugs' => ['alojamiento', 'camping'],
|
||||||
|
'names' => ['Alojamiento', 'CAMPING'],
|
||||||
|
],
|
||||||
|
3 => [
|
||||||
|
'slugs' => ['abono'],
|
||||||
|
'names' => ['Abono', 'ABONO'],
|
||||||
|
],
|
||||||
|
4 => [
|
||||||
|
'slugs' => ['comida'],
|
||||||
|
'names' => ['Comida', 'COMIDA'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($footballOrder as $order => $identifiers) {
|
||||||
|
DB::table('catalog_items')
|
||||||
|
->where('tenant_code', 'fiesta_futbol_infantil')
|
||||||
|
->where(function ($query) use ($identifiers): void {
|
||||||
|
$query
|
||||||
|
->whereIn('slug', $identifiers['slugs'])
|
||||||
|
->orWhereIn('nombre', $identifiers['names']);
|
||||||
|
})
|
||||||
|
->update(['group_order' => $order]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn('group_order');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -78,6 +78,7 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
|||||||
$this->createProduct($tenant, [
|
$this->createProduct($tenant, [
|
||||||
'slug' => 'camiseta',
|
'slug' => 'camiseta',
|
||||||
'nombre' => 'Camiseta',
|
'nombre' => 'Camiseta',
|
||||||
|
'group_order' => 1,
|
||||||
'category_id' => $categories['merchandising']->id,
|
'category_id' => $categories['merchandising']->id,
|
||||||
'precio' => 18000,
|
'precio' => 18000,
|
||||||
'attribute_codes' => ['color', 'talle'],
|
'attribute_codes' => ['color', 'talle'],
|
||||||
@@ -92,6 +93,7 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
|||||||
$this->createProduct($tenant, [
|
$this->createProduct($tenant, [
|
||||||
'slug' => 'alojamiento',
|
'slug' => 'alojamiento',
|
||||||
'nombre' => 'Alojamiento',
|
'nombre' => 'Alojamiento',
|
||||||
|
'group_order' => 2,
|
||||||
'category_id' => $categories['alojamientos']->id,
|
'category_id' => $categories['alojamientos']->id,
|
||||||
'precio' => 35000,
|
'precio' => 35000,
|
||||||
'attribute_codes' => ['tipo_alojamiento'],
|
'attribute_codes' => ['tipo_alojamiento'],
|
||||||
@@ -104,6 +106,7 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
|||||||
$this->createProduct($tenant, [
|
$this->createProduct($tenant, [
|
||||||
'slug' => 'comida',
|
'slug' => 'comida',
|
||||||
'nombre' => 'Comida',
|
'nombre' => 'Comida',
|
||||||
|
'group_order' => 4,
|
||||||
'category_id' => $categories['comidas']->id,
|
'category_id' => $categories['comidas']->id,
|
||||||
'precio' => 4000,
|
'precio' => 4000,
|
||||||
'attribute_codes' => ['event_date', 'horario', 'servicio'],
|
'attribute_codes' => ['event_date', 'horario', 'servicio'],
|
||||||
@@ -126,6 +129,7 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
|||||||
$this->createProduct($tenant, [
|
$this->createProduct($tenant, [
|
||||||
'slug' => 'abono',
|
'slug' => 'abono',
|
||||||
'nombre' => 'Abono',
|
'nombre' => 'Abono',
|
||||||
|
'group_order' => 3,
|
||||||
'category_id' => $categories['entradas']->id,
|
'category_id' => $categories['entradas']->id,
|
||||||
'precio' => 40000,
|
'precio' => 40000,
|
||||||
'has_tickets' => true,
|
'has_tickets' => true,
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ class CartControllerTest extends TestCase
|
|||||||
->assertJsonPath('code', 'purchase.limit_exceeded')
|
->assertJsonPath('code', 'purchase.limit_exceeded')
|
||||||
->assertJsonPath('catalog_item_id', $item->id)
|
->assertJsonPath('catalog_item_id', $item->id)
|
||||||
->assertJsonPath('catalog_item_name', $item->nombre)
|
->assertJsonPath('catalog_item_name', $item->nombre)
|
||||||
->assertJsonPath('availability.maximum_quantity', 1)
|
->assertJsonPath('maximum_addable_quantity', 1)
|
||||||
->assertJsonPath(
|
->assertJsonPath(
|
||||||
'message',
|
'message',
|
||||||
"Podés agregar hasta 1 unidad más de “{$item->nombre}”.",
|
"Podés agregar hasta 1 unidad más de “{$item->nombre}”.",
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ class BundleCatalogItemTest extends TestCase
|
|||||||
$this->getJson("/api/tenants/{$this->tenant->codigo}/catalog-items/{$bundleId}")
|
$this->getJson("/api/tenants/{$this->tenant->codigo}/catalog-items/{$bundleId}")
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.type', CatalogItemType::Bundle->value)
|
->assertJsonPath('data.type', CatalogItemType::Bundle->value)
|
||||||
->assertJsonPath('data.availability.maximum_quantity', 4)
|
->assertJsonPath('data.maximum_addable_quantity', 4)
|
||||||
->assertJsonMissingPath('data.stock_tecnico')
|
->assertJsonMissingPath('data.stock_tecnico')
|
||||||
->assertJsonCount(1, 'data.components')
|
->assertJsonCount(1, 'data.components')
|
||||||
->assertJsonPath('data.components.0.catalog_item_id', $component->id)
|
->assertJsonPath('data.components.0.catalog_item_id', $component->id)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class CatalogControllerTest extends TestCase
|
|||||||
$directItem = $this->createItem($tenant, 'Direct', $directInventory);
|
$directItem = $this->createItem($tenant, 'Direct', $directInventory);
|
||||||
$row->featuredItems()->create(['catalog_item_id' => $directItem->id]);
|
$row->featuredItems()->create(['catalog_item_id' => $directItem->id]);
|
||||||
|
|
||||||
$variantItem = $this->createItem($tenant, 'Variants', withoutInventory: true);
|
$variantItem = $this->createItem($tenant, 'Variants');
|
||||||
$firstInventory = Inventory::query()->create([
|
$firstInventory = Inventory::query()->create([
|
||||||
'real_stock' => 5,
|
'real_stock' => 5,
|
||||||
'reserved_stock' => 1,
|
'reserved_stock' => 1,
|
||||||
@@ -56,7 +56,7 @@ class CatalogControllerTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
$variantItem->variants()->create(['inventory_id' => $firstInventory->id]);
|
$variantItem->variants()->create(['inventory_id' => $firstInventory->id]);
|
||||||
$variantItem->variants()->create(['inventory_id' => $secondInventory->id]);
|
$variantItem->variants()->create(['inventory_id' => $secondInventory->id]);
|
||||||
$variantItem->variants()->create([
|
$unavailableVariant = $variantItem->variants()->create([
|
||||||
'inventory_id' => $unavailableInventory->id,
|
'inventory_id' => $unavailableInventory->id,
|
||||||
]);
|
]);
|
||||||
$cart->featuredItems()->create(['catalog_item_id' => $variantItem->id]);
|
$cart->featuredItems()->create(['catalog_item_id' => $variantItem->id]);
|
||||||
@@ -72,14 +72,18 @@ class CatalogControllerTest extends TestCase
|
|||||||
->assertJsonPath('0.items.0.nombre', 'Variants')
|
->assertJsonPath('0.items.0.nombre', 'Variants')
|
||||||
->assertJsonPath('0.items.0.descripcion', 'Variants description')
|
->assertJsonPath('0.items.0.descripcion', 'Variants description')
|
||||||
->assertJsonPath('0.items.0.precio', '100.00')
|
->assertJsonPath('0.items.0.precio', '100.00')
|
||||||
->assertJsonPath('0.items.0.availability.state', 'visible')
|
->assertJsonPath('0.items.0.maximum_addable_quantity', 7)
|
||||||
->assertJsonPath('0.items.0.availability.maximum_quantity', 7)
|
->assertJsonCount(3, '0.items.0.variants')
|
||||||
->assertJsonCount(2, '0.items.0.variants')
|
->assertJsonPath('0.items.0.variants.0.maximum_addable_quantity', 4)
|
||||||
->assertJsonPath('0.items.0.variants.0.availability.maximum_quantity', 4)
|
->assertJsonPath('0.items.0.variants.1.maximum_addable_quantity', 3)
|
||||||
->assertJsonPath('0.items.0.variants.0.availability.state', 'visible')
|
->assertJsonPath('0.items.0.variants.2.id', $unavailableVariant->id)
|
||||||
->assertJsonPath('0.items.0.variants.1.availability.maximum_quantity', 3)
|
->assertJsonPath('0.items.0.variants.2.maximum_addable_quantity', 0)
|
||||||
|
->assertJsonPath(
|
||||||
|
'0.items.0.variants.2.unavailable_message',
|
||||||
|
'Este producto no tiene stock disponible.',
|
||||||
|
)
|
||||||
->assertJsonPath('1.title', 'Row')
|
->assertJsonPath('1.title', 'Row')
|
||||||
->assertJsonPath('1.items.data.0.availability.maximum_quantity', 8)
|
->assertJsonPath('1.items.data.0.maximum_addable_quantity', 8)
|
||||||
->assertJsonMissingPath('1.items.data.0.stock_tecnico')
|
->assertJsonMissingPath('1.items.data.0.stock_tecnico')
|
||||||
->assertJsonCount(0, '1.items.data.0.variants');
|
->assertJsonCount(0, '1.items.data.0.variants');
|
||||||
}
|
}
|
||||||
@@ -94,7 +98,7 @@ class CatalogControllerTest extends TestCase
|
|||||||
groupLayout: GroupLayout::Simple,
|
groupLayout: GroupLayout::Simple,
|
||||||
);
|
);
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$item = $this->createItem($tenant, 'Limited variants', withoutInventory: true);
|
$item = $this->createItem($tenant, 'Limited variants');
|
||||||
$item->update(['max_units_per_user' => 3]);
|
$item->update(['max_units_per_user' => 3]);
|
||||||
$firstVariant = $item->variants()->create([
|
$firstVariant = $item->variants()->create([
|
||||||
'inventory_id' => Inventory::query()->create(['real_stock' => 10])->id,
|
'inventory_id' => Inventory::query()->create(['real_stock' => 10])->id,
|
||||||
@@ -115,21 +119,21 @@ class CatalogControllerTest extends TestCase
|
|||||||
$this->actingAs($user, 'sanctum')
|
$this->actingAs($user, 'sanctum')
|
||||||
->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('0.items.0.availability.maximum_quantity', 0)
|
->assertJsonPath('0.items.0.variants.0.maximum_addable_quantity', 0)
|
||||||
->assertJsonPath('0.items.0.availability.allowed_actions', [])
|
->assertJsonPath('0.items.0.variants.1.maximum_addable_quantity', 0)
|
||||||
->assertJsonPath(
|
->assertJsonPath(
|
||||||
'0.items.0.availability.reasons.0.message',
|
'0.items.0.variants.0.unavailable_message',
|
||||||
|
'Alcanzaste el cupo máximo permitido para este producto.',
|
||||||
|
)
|
||||||
|
->assertJsonPath(
|
||||||
|
'0.items.0.variants.1.unavailable_message',
|
||||||
'Alcanzaste el cupo máximo permitido para este producto.',
|
'Alcanzaste el cupo máximo permitido para este producto.',
|
||||||
)
|
)
|
||||||
->assertJsonPath('0.items.0.variants.0.availability.maximum_quantity', 8)
|
|
||||||
->assertJsonPath('0.items.0.variants.1.availability.maximum_quantity', 9)
|
|
||||||
->assertJsonCount(0, '0.items.0.variants.0.availability.reasons')
|
|
||||||
->assertJsonCount(0, '0.items.0.variants.1.availability.reasons')
|
|
||||||
->assertJsonMissingPath('0.items.0.variants.0.stock_tecnico')
|
->assertJsonMissingPath('0.items.0.variants.0.stock_tecnico')
|
||||||
->assertJsonMissingPath('0.items.0.variants.1.stock_tecnico');
|
->assertJsonMissingPath('0.items.0.variants.1.stock_tecnico');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_hides_out_of_stock_items_before_building_the_group_response(): void
|
public function test_it_includes_out_of_stock_items_with_an_unavailable_message(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('catalog-available-variants');
|
$tenant = $this->createTenant('catalog-available-variants');
|
||||||
$group = $this->createGroup(
|
$group = $this->createGroup(
|
||||||
@@ -139,7 +143,7 @@ class CatalogControllerTest extends TestCase
|
|||||||
groupLayout: GroupLayout::SimpleVertical,
|
groupLayout: GroupLayout::SimpleVertical,
|
||||||
);
|
);
|
||||||
|
|
||||||
$unavailableItem = $this->createItem($tenant, 'Unavailable', withoutInventory: true);
|
$unavailableItem = $this->createItem($tenant, 'Unavailable');
|
||||||
$unavailableInventory = Inventory::query()->create([
|
$unavailableInventory = Inventory::query()->create([
|
||||||
'real_stock' => 4,
|
'real_stock' => 4,
|
||||||
'reserved_stock' => 4,
|
'reserved_stock' => 4,
|
||||||
@@ -147,7 +151,7 @@ class CatalogControllerTest extends TestCase
|
|||||||
$unavailableItem->variants()->create(['inventory_id' => $unavailableInventory->id]);
|
$unavailableItem->variants()->create(['inventory_id' => $unavailableInventory->id]);
|
||||||
$group->featuredItems()->create(['catalog_item_id' => $unavailableItem->id]);
|
$group->featuredItems()->create(['catalog_item_id' => $unavailableItem->id]);
|
||||||
|
|
||||||
$availableItem = $this->createItem($tenant, 'Available', withoutInventory: true);
|
$availableItem = $this->createItem($tenant, 'Available');
|
||||||
$availableInventory = Inventory::query()->create([
|
$availableInventory = Inventory::query()->create([
|
||||||
'real_stock' => 4,
|
'real_stock' => 4,
|
||||||
'reserved_stock' => 3,
|
'reserved_stock' => 3,
|
||||||
@@ -157,9 +161,15 @@ class CatalogControllerTest extends TestCase
|
|||||||
|
|
||||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonCount(1, '0.items')
|
->assertJsonCount(2, '0.items')
|
||||||
->assertJsonPath('0.items.0.nombre', 'Available')
|
->assertJsonPath('0.items.0.nombre', 'Unavailable')
|
||||||
->assertJsonCount(0, '0.items.0.availability.reasons');
|
->assertJsonPath('0.items.0.maximum_addable_quantity', 0)
|
||||||
|
->assertJsonPath(
|
||||||
|
'0.items.0.unavailable_message',
|
||||||
|
'Este producto no tiene stock disponible.',
|
||||||
|
)
|
||||||
|
->assertJsonPath('0.items.1.nombre', 'Available')
|
||||||
|
->assertJsonPath('0.items.1.unavailable_message', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_column_with_image_uses_item_image_then_variant_image_then_null(): void
|
public function test_column_with_image_uses_item_image_then_variant_image_then_null(): void
|
||||||
@@ -176,8 +186,8 @@ class CatalogControllerTest extends TestCase
|
|||||||
'order' => 0,
|
'order' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$variantItem = $this->createItem($tenant, 'Variant image', withoutInventory: true);
|
$variantItem = $this->createItem($tenant, 'Variant image');
|
||||||
$variantInventory = Inventory::query()->create(['real_stock' => 1]);
|
$variantInventory = Inventory::query()->create();
|
||||||
$variant = $variantItem->variants()->create(['inventory_id' => $variantInventory->id]);
|
$variant = $variantItem->variants()->create(['inventory_id' => $variantInventory->id]);
|
||||||
$variantImage = $this->createAttachment('variant');
|
$variantImage = $this->createAttachment('variant');
|
||||||
$variant->attachments()->attach($variantImage, ['orden' => 0]);
|
$variant->attachments()->attach($variantImage, ['orden' => 0]);
|
||||||
@@ -344,8 +354,10 @@ class CatalogControllerTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$food = $this->createItem($tenant, 'Hamburger');
|
$food = $this->createItem($tenant, 'Hamburger');
|
||||||
|
$food->update(['group_order' => 2]);
|
||||||
$food->category()->associate($category)->save();
|
$food->category()->associate($category)->save();
|
||||||
$this->createItem($tenant, 'Parking');
|
$parking = $this->createItem($tenant, 'Parking');
|
||||||
|
$parking->update(['group_order' => 1]);
|
||||||
|
|
||||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||||
->assertOk()
|
->assertOk()
|
||||||
@@ -354,56 +366,12 @@ class CatalogControllerTest extends TestCase
|
|||||||
->assertJsonPath('0.items.0.nombre', 'Hamburger')
|
->assertJsonPath('0.items.0.nombre', 'Hamburger')
|
||||||
->assertJsonPath('1.title', 'All products')
|
->assertJsonPath('1.title', 'All products')
|
||||||
->assertJsonCount(2, '1.items.data')
|
->assertJsonCount(2, '1.items.data')
|
||||||
|
->assertJsonPath('1.items.data.0.nombre', 'Parking')
|
||||||
|
->assertJsonPath('1.items.data.1.nombre', 'Hamburger')
|
||||||
|
->assertJsonMissingPath('1.items.data.0.group_order')
|
||||||
->assertJsonPath('1.items.meta.total', 2);
|
->assertJsonPath('1.items.meta.total', 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_index_excludes_items_from_disabled_categories(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('catalog-disabled-category');
|
|
||||||
$group = $this->createGroup(
|
|
||||||
$tenant,
|
|
||||||
ProductLayout::Row,
|
|
||||||
'All products',
|
|
||||||
groupLayout: GroupLayout::Simple,
|
|
||||||
);
|
|
||||||
$enabledCategory = Category::query()->create([
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'nombre' => 'Enabled',
|
|
||||||
]);
|
|
||||||
$disabledCategory = Category::query()->create([
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'nombre' => 'Disabled',
|
|
||||||
'is_enabled' => false,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$enabledItem = $this->createItem($tenant, 'Enabled item');
|
|
||||||
$enabledItem->category()->associate($enabledCategory)->save();
|
|
||||||
$disabledItem = $this->createItem($tenant, 'Disabled item');
|
|
||||||
$disabledItem->category()->associate($disabledCategory)->save();
|
|
||||||
$uncategorizedItem = $this->createItem($tenant, 'Uncategorized item');
|
|
||||||
|
|
||||||
foreach ([$enabledItem, $disabledItem, $uncategorizedItem] as $order => $item) {
|
|
||||||
$group->featuredItems()->create([
|
|
||||||
'catalog_item_id' => $item->id,
|
|
||||||
'order' => $order,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(2, '0.items')
|
|
||||||
->assertJsonPath('0.items.0.nombre', 'Enabled item')
|
|
||||||
->assertJsonPath('0.items.1.nombre', 'Uncategorized item')
|
|
||||||
->assertJsonMissing(['nombre' => 'Disabled item']);
|
|
||||||
|
|
||||||
$this->getJson(
|
|
||||||
"/api/tenants/{$tenant->codigo}/catalog/featured-groups/{$group->id}/items"
|
|
||||||
)
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(2)
|
|
||||||
->assertJsonMissing(['nombre' => 'Disabled item']);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createGroup(
|
private function createGroup(
|
||||||
Tenant $tenant,
|
Tenant $tenant,
|
||||||
ProductLayout $layout,
|
ProductLayout $layout,
|
||||||
@@ -424,12 +392,7 @@ class CatalogControllerTest extends TestCase
|
|||||||
Tenant $tenant,
|
Tenant $tenant,
|
||||||
string $name,
|
string $name,
|
||||||
?Inventory $inventory = null,
|
?Inventory $inventory = null,
|
||||||
bool $withoutInventory = false,
|
|
||||||
): CatalogItem {
|
): CatalogItem {
|
||||||
$inventory ??= $withoutInventory
|
|
||||||
? null
|
|
||||||
: Inventory::query()->create(['real_stock' => 10]);
|
|
||||||
|
|
||||||
return CatalogItem::query()->create([
|
return CatalogItem::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'inventory_id' => $inventory?->id,
|
'inventory_id' => $inventory?->id,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class CatalogItemControllerTest extends TestCase
|
|||||||
$response = $this->postJson("/api/tenants/{$tenant->codigo}/catalog-items", [
|
$response = $this->postJson("/api/tenants/{$tenant->codigo}/catalog-items", [
|
||||||
'slug' => 'shirt',
|
'slug' => 'shirt',
|
||||||
'nombre' => 'Shirt',
|
'nombre' => 'Shirt',
|
||||||
|
'group_order' => 7,
|
||||||
'precio' => 100,
|
'precio' => 100,
|
||||||
'max_units_per_user' => 4,
|
'max_units_per_user' => 4,
|
||||||
'attribute_codes' => [$attribute->codigo],
|
'attribute_codes' => [$attribute->codigo],
|
||||||
@@ -47,6 +48,7 @@ class CatalogItemControllerTest extends TestCase
|
|||||||
$response
|
$response
|
||||||
->assertCreated()
|
->assertCreated()
|
||||||
->assertJsonPath('data.nombre', 'Shirt')
|
->assertJsonPath('data.nombre', 'Shirt')
|
||||||
|
->assertJsonMissingPath('data.group_order')
|
||||||
->assertJsonPath('data.max_units_per_user', 4)
|
->assertJsonPath('data.max_units_per_user', 4)
|
||||||
->assertJsonCount(2, 'data.images')
|
->assertJsonCount(2, 'data.images')
|
||||||
->assertJsonCount(1, 'data.variants')
|
->assertJsonCount(1, 'data.variants')
|
||||||
@@ -57,6 +59,7 @@ class CatalogItemControllerTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame([0, 1], $item->attachments()->get()->pluck('pivot.orden')->all());
|
$this->assertSame([0, 1], $item->attachments()->get()->pluck('pivot.orden')->all());
|
||||||
$this->assertSame(4, $item->max_units_per_user);
|
$this->assertSame(4, $item->max_units_per_user);
|
||||||
|
$this->assertSame(7, $item->group_order);
|
||||||
$this->assertSame([0], $variant->attachments()->get()->pluck('pivot.orden')->all());
|
$this->assertSame([0], $variant->attachments()->get()->pluck('pivot.orden')->all());
|
||||||
$this->assertDatabaseHas('catalog_items_attachments', [
|
$this->assertDatabaseHas('catalog_items_attachments', [
|
||||||
'catalog_item_id' => $item->id,
|
'catalog_item_id' => $item->id,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class CatalogItemDetailControllerTest extends TestCase
|
|||||||
|
|
||||||
$response
|
$response
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.availability.maximum_quantity', 7)
|
->assertJsonPath('data.maximum_addable_quantity', 7)
|
||||||
->assertJsonMissingPath('data.stock_tecnico')
|
->assertJsonMissingPath('data.stock_tecnico')
|
||||||
->assertJsonCount(0, 'data.variants')
|
->assertJsonCount(0, 'data.variants')
|
||||||
->assertJsonCount(1, 'data.images');
|
->assertJsonCount(1, 'data.images');
|
||||||
@@ -48,18 +48,7 @@ class CatalogItemDetailControllerTest extends TestCase
|
|||||||
$this->assertStringContainsString($itemImage->path, $response->json('data.images.0'));
|
$this->assertStringContainsString($itemImage->path, $response->json('data.images.0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_does_not_return_an_out_of_stock_product_detail(): void
|
public function test_it_lists_unavailable_variants_and_selects_the_first_available_one(): void
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('detail-hidden');
|
|
||||||
$inventory = Inventory::query()->create(['real_stock' => 0]);
|
|
||||||
$item = $this->createItem($tenant, 'Hidden item', $inventory);
|
|
||||||
|
|
||||||
$this->getJson(
|
|
||||||
"/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}",
|
|
||||||
)->assertNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_hides_unavailable_variants_and_selects_the_first_available_one(): void
|
|
||||||
{
|
{
|
||||||
Storage::fake('s3');
|
Storage::fake('s3');
|
||||||
$tenant = $this->createTenant('detail-default');
|
$tenant = $this->createTenant('detail-default');
|
||||||
@@ -80,11 +69,16 @@ class CatalogItemDetailControllerTest extends TestCase
|
|||||||
|
|
||||||
$response
|
$response
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonCount(1, 'data.variants')
|
->assertJsonCount(2, 'data.variants')
|
||||||
->assertJsonPath('data.variants.0.id', $secondVariant->id)
|
->assertJsonPath('data.variants.0.id', $firstVariant->id)
|
||||||
->assertJsonPath('data.variants.0.availability.state', 'visible')
|
->assertJsonPath('data.variants.0.maximum_addable_quantity', 0)
|
||||||
|
->assertJsonPath(
|
||||||
|
'data.variants.0.unavailable_message',
|
||||||
|
'Este producto no tiene stock disponible.',
|
||||||
|
)
|
||||||
|
->assertJsonPath('data.variants.1.id', $secondVariant->id)
|
||||||
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
||||||
->assertJsonPath('data.selected_variant.availability.maximum_quantity', 6)
|
->assertJsonPath('data.selected_variant.maximum_addable_quantity', 6)
|
||||||
->assertJsonMissingPath('data.selected_variant.stock_tecnico')
|
->assertJsonMissingPath('data.selected_variant.stock_tecnico')
|
||||||
->assertJsonCount(1, 'data.selected_variant.images');
|
->assertJsonCount(1, 'data.selected_variant.images');
|
||||||
$response
|
$response
|
||||||
@@ -139,11 +133,11 @@ class CatalogItemDetailControllerTest extends TestCase
|
|||||||
$response
|
$response
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.variants.0.id', $firstVariant->id)
|
->assertJsonPath('data.variants.0.id', $firstVariant->id)
|
||||||
->assertJsonPath('data.variants.0.availability.maximum_quantity', 4)
|
->assertJsonPath('data.variants.0.maximum_addable_quantity', 4)
|
||||||
->assertJsonPath('data.variants.0.values.size.value', 'S')
|
->assertJsonPath('data.variants.0.values.size.value', 'S')
|
||||||
->assertJsonPath('data.variants.0.values.size.label', 'Small')
|
->assertJsonPath('data.variants.0.values.size.label', 'Small')
|
||||||
->assertJsonPath('data.variants.1.id', $secondVariant->id)
|
->assertJsonPath('data.variants.1.id', $secondVariant->id)
|
||||||
->assertJsonPath('data.variants.1.availability.maximum_quantity', 7)
|
->assertJsonPath('data.variants.1.maximum_addable_quantity', 7)
|
||||||
->assertJsonPath('data.variants.1.values.size.value', 'M')
|
->assertJsonPath('data.variants.1.values.size.value', 'M')
|
||||||
->assertJsonPath('data.variants.1.values.size.label', 'Medium')
|
->assertJsonPath('data.variants.1.values.size.label', 'Medium')
|
||||||
->assertJsonPath('data.attributes.0.codigo', 'size')
|
->assertJsonPath('data.attributes.0.codigo', 'size')
|
||||||
@@ -151,7 +145,7 @@ class CatalogItemDetailControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.attributes.0.options.1.value', 'M')
|
->assertJsonPath('data.attributes.0.options.1.value', 'M')
|
||||||
->assertJsonCount(2, 'data.attributes.0.options')
|
->assertJsonCount(2, 'data.attributes.0.options')
|
||||||
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
||||||
->assertJsonPath('data.selected_variant.availability.maximum_quantity', 7)
|
->assertJsonPath('data.selected_variant.maximum_addable_quantity', 7)
|
||||||
->assertJsonPath('data.selected_variant.values.size.value', 'M')
|
->assertJsonPath('data.selected_variant.values.size.value', 'M')
|
||||||
->assertJsonPath('data.selected_variant.values.size.label', 'Medium')
|
->assertJsonPath('data.selected_variant.values.size.label', 'Medium')
|
||||||
->assertJsonCount(1, 'data.selected_variant.images');
|
->assertJsonCount(1, 'data.selected_variant.images');
|
||||||
@@ -191,9 +185,9 @@ class CatalogItemDetailControllerTest extends TestCase
|
|||||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}")
|
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}")
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.selected_variant.id', $variant->id)
|
->assertJsonPath('data.selected_variant.id', $variant->id)
|
||||||
->assertJsonPath('data.selected_variant.availability.maximum_quantity', null)
|
->assertJsonPath('data.selected_variant.maximum_addable_quantity', null)
|
||||||
->assertJsonMissingPath('data.stock_tecnico')
|
->assertJsonMissingPath('data.stock_tecnico')
|
||||||
->assertJsonPath('data.variants.0.availability.maximum_quantity', null)
|
->assertJsonPath('data.variants.0.maximum_addable_quantity', null)
|
||||||
->assertJsonMissingPath('data.selected_variant.stock_tecnico')
|
->assertJsonMissingPath('data.selected_variant.stock_tecnico')
|
||||||
->assertJsonMissingPath('data.variants.0.stock_tecnico');
|
->assertJsonMissingPath('data.variants.0.stock_tecnico');
|
||||||
}
|
}
|
||||||
@@ -360,9 +354,6 @@ class CatalogItemDetailControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.resolved_variant', null)
|
->assertJsonPath('data.resolved_variant', null)
|
||||||
->assertJsonCount(3, 'data.variants')
|
->assertJsonCount(3, 'data.variants')
|
||||||
->assertJsonPath('data.variants.0.id', $first->id)
|
->assertJsonPath('data.variants.0.id', $first->id)
|
||||||
->assertJsonPath('data.variants.0.availability.state', 'visible')
|
|
||||||
->assertJsonPath('data.variants.0.availability.maximum_quantity', 1)
|
|
||||||
->assertJsonPath('data.variants.0.availability.allowed_actions.2', 'add_to_cart')
|
|
||||||
->assertJsonPath('data.variants.0.values.sector.value', 'A')
|
->assertJsonPath('data.variants.0.values.sector.value', 'A')
|
||||||
->assertJsonPath('data.variants.0.values.seat.value', '1')
|
->assertJsonPath('data.variants.0.values.seat.value', '1')
|
||||||
->assertJsonCount(2, 'data.selectors')
|
->assertJsonCount(2, 'data.selectors')
|
||||||
@@ -430,9 +421,7 @@ class CatalogItemDetailControllerTest extends TestCase
|
|||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.selected_values.sector', 'VIP')
|
->assertJsonPath('data.selected_values.sector', 'VIP')
|
||||||
->assertJsonPath('data.selected_values.seat', 'A-12')
|
->assertJsonPath('data.selected_values.seat', 'A-12')
|
||||||
->assertJsonPath('data.resolved_variant.id', $variant->id)
|
->assertJsonPath('data.resolved_variant.id', $variant->id);
|
||||||
->assertJsonPath('data.resolved_variant.availability.state', 'hidden')
|
|
||||||
->assertJsonMissingPath('data.resolved_variant.availability.allowed_actions');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createItem(
|
private function createItem(
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ namespace Tests\Feature\Catalog;
|
|||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\Category;
|
|
||||||
use App\Domains\Catalog\Models\Inventory;
|
use App\Domains\Catalog\Models\Inventory;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -16,21 +15,6 @@ class CatalogSchemaTest extends TestCase
|
|||||||
{
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
public function test_categories_are_enabled_by_default(): void
|
|
||||||
{
|
|
||||||
$this->assertTrue(Schema::hasColumn('categorias', 'is_enabled'));
|
|
||||||
|
|
||||||
$category = Category::query()->create([
|
|
||||||
'nombre' => 'Enabled category',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertTrue($category->is_enabled);
|
|
||||||
$this->assertDatabaseHas('categorias', [
|
|
||||||
'id' => $category->id,
|
|
||||||
'is_enabled' => true,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_legacy_product_tables_are_replaced_by_catalog_tables(): void
|
public function test_legacy_product_tables_are_replaced_by_catalog_tables(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse(Schema::hasTable('productos'));
|
$this->assertFalse(Schema::hasTable('productos'));
|
||||||
|
|||||||
@@ -62,8 +62,6 @@ class CatalogSearchTest extends TestCase
|
|||||||
$this->createCatalogItem($tenant, "Running {$number}");
|
$this->createCatalogItem($tenant, "Running {$number}");
|
||||||
}
|
}
|
||||||
$exactMatch = $this->createCatalogItem($tenant, 'Running');
|
$exactMatch = $this->createCatalogItem($tenant, 'Running');
|
||||||
$outOfStockMatch = $this->createCatalogItem($tenant, 'Running unavailable');
|
|
||||||
$outOfStockMatch->inventory->update(['real_stock' => 0]);
|
|
||||||
$this->createCatalogItem($tenant, 'Unrelated');
|
$this->createCatalogItem($tenant, 'Unrelated');
|
||||||
$this->createCatalogItem($otherTenant, 'Running foreign');
|
$this->createCatalogItem($otherTenant, 'Running foreign');
|
||||||
|
|
||||||
@@ -78,7 +76,6 @@ class CatalogSearchTest extends TestCase
|
|||||||
->assertJsonPath('meta.total', 6)
|
->assertJsonPath('meta.total', 6)
|
||||||
->assertJsonCount(4, 'data')
|
->assertJsonCount(4, 'data')
|
||||||
->assertJsonPath('data.0.id', $exactMatch->id)
|
->assertJsonPath('data.0.id', $exactMatch->id)
|
||||||
->assertJsonMissing(['nombre' => 'Running unavailable'])
|
|
||||||
->assertJsonMissing(['nombre' => 'Running foreign'])
|
->assertJsonMissing(['nombre' => 'Running foreign'])
|
||||||
->assertJsonMissing(['nombre' => 'Unrelated']);
|
->assertJsonMissing(['nombre' => 'Unrelated']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,59 +38,6 @@ class EntryControllerTest extends TestCase
|
|||||||
->assertUnauthorized();
|
->assertUnauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_category_visibility_can_be_read_and_updated_for_every_fiesta_menu(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createFiestaTenant();
|
|
||||||
$categories = [
|
|
||||||
'entries' => ['Entradas', 'adminapp.fiesta-futbol-infantil.entradas'],
|
|
||||||
'foods' => ['Comidas', 'adminapp.fiesta-futbol-infantil.comida'],
|
|
||||||
'accommodations' => ['Alojamientos', 'adminapp.fiesta-futbol-infantil.alojamientos'],
|
|
||||||
'merchandise' => ['Merchandising', 'adminapp.fiesta-futbol-infantil.merchandising'],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($categories as [$label, $menuCode]) {
|
|
||||||
$menu = Menu::query()->firstOrCreate(
|
|
||||||
['code' => $menuCode],
|
|
||||||
['label' => $label, 'route' => '/admin'],
|
|
||||||
);
|
|
||||||
$tenant->menues()->syncWithoutDetaching([$menu->code]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
|
||||||
|
|
||||||
foreach ($categories as $endpoint => [$categoryName]) {
|
|
||||||
$this->getJson("/api/v1/adminapp/tenant/{$endpoint}/visibility")
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.is_enabled', true);
|
|
||||||
|
|
||||||
$this->patchJson("/api/v1/adminapp/tenant/{$endpoint}/visibility", [
|
|
||||||
'is_enabled' => false,
|
|
||||||
])
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.is_enabled', false)
|
|
||||||
->assertJsonPath(
|
|
||||||
'message',
|
|
||||||
'Mostrar en sitio web se desactivo correctamente',
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->patchJson("/api/v1/adminapp/tenant/{$endpoint}/visibility", [
|
|
||||||
'is_enabled' => true,
|
|
||||||
])
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.is_enabled', true)
|
|
||||||
->assertJsonPath(
|
|
||||||
'message',
|
|
||||||
'Mostrar en sitio web se activo correctamente',
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('categorias', [
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'nombre' => $categoryName,
|
|
||||||
'is_enabled' => true,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_creates_multiple_entries_with_dates_and_tracked_inventory(): void
|
public function test_it_creates_multiple_entries_with_dates_and_tracked_inventory(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createFiestaTenant();
|
$tenant = $this->createFiestaTenant();
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ class StorePurchaseTest extends TestCase
|
|||||||
->assertJsonPath('code', 'purchase.limit_exceeded')
|
->assertJsonPath('code', 'purchase.limit_exceeded')
|
||||||
->assertJsonPath('catalog_item_id', $variant->catalog_item_id)
|
->assertJsonPath('catalog_item_id', $variant->catalog_item_id)
|
||||||
->assertJsonPath('catalog_item_name', $variant->catalogItem->nombre)
|
->assertJsonPath('catalog_item_name', $variant->catalogItem->nombre)
|
||||||
->assertJsonPath('availability.maximum_quantity', 1);
|
->assertJsonPath('maximum_addable_quantity', 1);
|
||||||
|
|
||||||
$this->actingAs($otherUser, 'sanctum')
|
$this->actingAs($otherUser, 'sanctum')
|
||||||
->postJson('/api/tenants/sonder/compras/start-checkout', [
|
->postJson('/api/tenants/sonder/compras/start-checkout', [
|
||||||
@@ -1230,52 +1230,6 @@ class StorePurchaseTest extends TestCase
|
|||||||
->assertJsonPath('data.0.total', '100.00');
|
->assertJsonPath('data.0.total', '100.00');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_purchase_index_filters_multiple_comma_separated_statuses_and_orders_by_status_ascending_then_date(): void
|
|
||||||
{
|
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$olderPaid = Purchase::query()->create([
|
|
||||||
'tenant_codigo' => 'sonder',
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'status' => Purchase::STATUS_PAID,
|
|
||||||
'total' => '10.00',
|
|
||||||
]);
|
|
||||||
$newerInReview = Purchase::query()->create([
|
|
||||||
'tenant_codigo' => 'sonder',
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'status' => Purchase::STATUS_IN_REVIEW,
|
|
||||||
'total' => '20.00',
|
|
||||||
]);
|
|
||||||
$newerPaid = Purchase::query()->create([
|
|
||||||
'tenant_codigo' => 'sonder',
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'status' => Purchase::STATUS_PAID,
|
|
||||||
'total' => '30.00',
|
|
||||||
]);
|
|
||||||
Purchase::query()->create([
|
|
||||||
'tenant_codigo' => 'sonder',
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'status' => Purchase::STATUS_CANCELLED,
|
|
||||||
'total' => '40.00',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$olderPaid->forceFill(['created_at' => now()->subDays(3)])->saveQuietly();
|
|
||||||
$newerInReview->forceFill(['created_at' => now()])->saveQuietly();
|
|
||||||
$newerPaid->forceFill(['created_at' => now()->subDay()])->saveQuietly();
|
|
||||||
|
|
||||||
$this->actingAs($user, 'sanctum')
|
|
||||||
->getJson('/api/tenants/sonder/compras?status=paid,%20in_review,paid')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(3, 'data')
|
|
||||||
->assertJsonPath('data.0.id', $newerInReview->id)
|
|
||||||
->assertJsonPath('data.0.status', Purchase::STATUS_IN_REVIEW)
|
|
||||||
->assertJsonPath('data.1.id', $newerPaid->id)
|
|
||||||
->assertJsonPath('data.1.status', Purchase::STATUS_PAID)
|
|
||||||
->assertJsonPath('data.2.id', $olderPaid->id)
|
|
||||||
->assertJsonPath('data.2.status', Purchase::STATUS_PAID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_rejects_a_cart_from_another_user(): void
|
public function test_it_rejects_a_cart_from_another_user(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
|||||||
@@ -70,6 +70,14 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
|||||||
['abono', 'alojamiento', 'camiseta', 'comida'],
|
['abono', 'alojamiento', 'camiseta', 'comida'],
|
||||||
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('slug')->pluck('slug')->all(),
|
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('slug')->pluck('slug')->all(),
|
||||||
);
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
['camiseta', 'alojamiento', 'abono', 'comida'],
|
||||||
|
CatalogItem::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->orderBy('group_order')
|
||||||
|
->pluck('slug')
|
||||||
|
->all(),
|
||||||
|
);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
CatalogItem::query()
|
CatalogItem::query()
|
||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
|||||||
@@ -2,73 +2,42 @@
|
|||||||
|
|
||||||
namespace Tests\Unit\Catalog;
|
namespace Tests\Unit\Catalog;
|
||||||
|
|
||||||
use App\Domains\Catalog\Services\AvailabilityPolicyResolver;
|
|
||||||
use App\Domains\Catalog\Services\CatalogItemAllowanceService;
|
use App\Domains\Catalog\Services\CatalogItemAllowanceService;
|
||||||
use App\Domains\Purchase\Services\UserPurchaseLimitService;
|
use ReflectionClass;
|
||||||
use Mockery;
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class CatalogItemAllowanceServiceTest extends TestCase
|
class CatalogItemAllowanceServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test_a_hidden_decision_only_exposes_its_state_and_reasons(): void
|
private CatalogItemAllowanceService $service;
|
||||||
{
|
|
||||||
$availability = $this->service()->availability(0, 0)->toArray();
|
|
||||||
|
|
||||||
$this->assertSame('hidden', $availability['state']);
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->service = (new ReflectionClass(CatalogItemAllowanceService::class))
|
||||||
|
->newInstanceWithoutConstructor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_the_user_quota_message_with_priority_over_stock(): void
|
||||||
|
{
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
['user_quota_reached', 'out_of_stock'],
|
'Alcanzaste el cupo máximo permitido para este producto.',
|
||||||
array_column($availability['reasons'], 'code'),
|
$this->service->unavailableMessage(0, 0),
|
||||||
);
|
);
|
||||||
$this->assertArrayNotHasKey('maximum_quantity', $availability);
|
|
||||||
$this->assertArrayNotHasKey('allowed_actions', $availability);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_an_available_decision_keeps_all_actions(): void
|
public function test_it_returns_the_out_of_stock_message(): void
|
||||||
{
|
{
|
||||||
$availability = $this->service()->availability(5, 3)->toArray();
|
|
||||||
|
|
||||||
$this->assertSame('visible', $availability['state']);
|
|
||||||
$this->assertSame(3, $availability['maximum_quantity']);
|
|
||||||
$this->assertSame([], $availability['reasons']);
|
|
||||||
$this->assertSame([
|
|
||||||
'select_variant',
|
|
||||||
'change_quantity',
|
|
||||||
'add_to_cart',
|
|
||||||
'buy_now',
|
|
||||||
], $availability['allowed_actions']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_reaching_the_user_quota_keeps_the_product_visible_without_actions(): void
|
|
||||||
{
|
|
||||||
$availability = $this->service()->availability(5, 0)->toArray();
|
|
||||||
|
|
||||||
$this->assertSame('visible', $availability['state']);
|
|
||||||
$this->assertSame([], $availability['allowed_actions']);
|
|
||||||
$this->assertSame('user_quota_reached', $availability['reasons'][0]['code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_exceeding_the_remaining_quota_allows_the_quantity_to_be_corrected(): void
|
|
||||||
{
|
|
||||||
$availability = $this->service()
|
|
||||||
->purchaseLimitExceededAvailability(1, 'Solo podés agregar una unidad.')
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
$this->assertSame(1, $availability['maximum_quantity']);
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'requested_quantity_exceeds_user_quota',
|
'Este producto no tiene stock disponible.',
|
||||||
$availability['reasons'][0]['code'],
|
$this->service->unavailableMessage(0, null),
|
||||||
);
|
);
|
||||||
$this->assertSame([
|
|
||||||
'select_variant',
|
|
||||||
'change_quantity',
|
|
||||||
], $availability['allowed_actions']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function service(): CatalogItemAllowanceService
|
public function test_it_returns_no_message_when_the_item_is_available(): void
|
||||||
{
|
{
|
||||||
return new CatalogItemAllowanceService(
|
$this->assertNull($this->service->unavailableMessage(1, null));
|
||||||
Mockery::mock(UserPurchaseLimitService::class),
|
$this->assertNull($this->service->unavailableMessage(null, 1));
|
||||||
new AvailabilityPolicyResolver,
|
$this->assertNull($this->service->unavailableMessage(null, null));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,11 +83,13 @@ class CatalogModelsTest extends TestCase
|
|||||||
public function test_catalog_item_is_the_catalog_root(): void
|
public function test_catalog_item_is_the_catalog_root(): void
|
||||||
{
|
{
|
||||||
$item = new CatalogItem;
|
$item = new CatalogItem;
|
||||||
|
$this->assertSame(0, $item->group_order);
|
||||||
$item->setRawAttributes([
|
$item->setRawAttributes([
|
||||||
'category_id' => '10',
|
'category_id' => '10',
|
||||||
'brand_id' => '20',
|
'brand_id' => '20',
|
||||||
'inventory_id' => '30',
|
'inventory_id' => '30',
|
||||||
'type' => CatalogItemType::Standard->value,
|
'type' => CatalogItemType::Standard->value,
|
||||||
|
'group_order' => '4',
|
||||||
'precio' => '12.50',
|
'precio' => '12.50',
|
||||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||||
'inventory_subject' => InventorySubject::Seat->value,
|
'inventory_subject' => InventorySubject::Seat->value,
|
||||||
@@ -100,6 +102,7 @@ class CatalogModelsTest extends TestCase
|
|||||||
$this->assertSame(20, $item->brand_id);
|
$this->assertSame(20, $item->brand_id);
|
||||||
$this->assertSame(30, $item->inventory_id);
|
$this->assertSame(30, $item->inventory_id);
|
||||||
$this->assertSame(CatalogItemType::Standard, $item->type);
|
$this->assertSame(CatalogItemType::Standard, $item->type);
|
||||||
|
$this->assertSame(4, $item->group_order);
|
||||||
$this->assertSame('12.50', $item->precio);
|
$this->assertSame('12.50', $item->precio);
|
||||||
$this->assertSame(InventoryPolicy::Tracked, $item->inventory_policy);
|
$this->assertSame(InventoryPolicy::Tracked, $item->inventory_policy);
|
||||||
$this->assertSame(InventorySubject::Seat, $item->inventory_subject);
|
$this->assertSame(InventorySubject::Seat, $item->inventory_subject);
|
||||||
|
|||||||
Reference in New Issue
Block a user