feat: enhance item attributes management by adding sort order; update related models, resources, and tests for visibility and ordering of variants
This commit is contained in:
@@ -223,6 +223,43 @@ class CatalogModelsTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_variant_orders_selection_options_by_item_order_and_attribute_label(): void
|
||||
{
|
||||
$definitions = collect([
|
||||
['id' => 1, 'code' => 'zeta', 'label' => 'Zeta', 'sort_order' => 2],
|
||||
['id' => 2, 'code' => 'priority', 'label' => 'Priority', 'sort_order' => 1],
|
||||
['id' => 3, 'code' => 'alpha', 'label' => 'Alpha', 'sort_order' => 2],
|
||||
])->map(function (array $data): VariantDefinition {
|
||||
$attribute = new Attribute([
|
||||
'codigo' => $data['code'],
|
||||
'nombre' => $data['label'],
|
||||
]);
|
||||
$attribute->setRelation('options', new EloquentCollection);
|
||||
|
||||
$itemAttribute = new ItemAttribute([
|
||||
'sort_order' => $data['sort_order'],
|
||||
'allow_multi_select' => false,
|
||||
]);
|
||||
$itemAttribute->id = $data['id'];
|
||||
$itemAttribute->setRelation('attribute', $attribute);
|
||||
|
||||
$definition = new VariantDefinition(['value' => $data['code']]);
|
||||
$definition->item_attribute_id = $itemAttribute->id;
|
||||
$definition->setRelation('itemAttribute', $itemAttribute);
|
||||
|
||||
return $definition;
|
||||
});
|
||||
|
||||
$variant = new Variant;
|
||||
$variant->setRelation('definitions', new EloquentCollection($definitions));
|
||||
$variant->setRelation('eventDates', new EloquentCollection);
|
||||
|
||||
$this->assertSame(
|
||||
['priority', 'alpha', 'zeta'],
|
||||
$variant->selectionOptions()->keys()->all(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_inventory_maps_stock_without_a_polymorphic_owner(): void
|
||||
{
|
||||
$inventory = $this->trackedInventory(realStock: 10, reservedStock: 3);
|
||||
@@ -249,6 +286,21 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertTrue($item->isAvailable());
|
||||
}
|
||||
|
||||
public function test_catalog_item_only_exposes_available_tracked_variants(): void
|
||||
{
|
||||
$unavailable = (new Variant)->setRelation('inventory', $this->trackedInventory(3, 3));
|
||||
$available = (new Variant)->setRelation('inventory', $this->trackedInventory(5, 2));
|
||||
$item = new CatalogItem;
|
||||
$item->inventory_policy = InventoryPolicy::Tracked;
|
||||
$item->setRelation('variants', new EloquentCollection([$unavailable, $available]));
|
||||
|
||||
$this->assertSame([$available], $item->visibleVariants()->all());
|
||||
|
||||
$item->inventory_policy = InventoryPolicy::Unlimited;
|
||||
|
||||
$this->assertSame([$unavailable, $available], $item->visibleVariants()->all());
|
||||
}
|
||||
|
||||
public function test_catalog_item_prioritizes_its_inventory_over_variants(): void
|
||||
{
|
||||
$item = new CatalogItem;
|
||||
|
||||
Reference in New Issue
Block a user