refactor(inventory): update stock validation rules and enforce stock_difference requirement

This commit is contained in:
2026-09-25 15:28:49 -03:00
parent 717f02ce16
commit a05d15d17f
13 changed files with 141 additions and 31 deletions

View File

@@ -245,7 +245,7 @@ class MerchandiseService
...$variant,
'color' => $color->value,
'size' => $size->value,
'stock' => (int) $variant['stock'],
...(array_key_exists('stock', $variant) ? ['stock' => (int) $variant['stock']] : []),
];
})->all();
}
@@ -369,8 +369,10 @@ class MerchandiseService
->firstOrFail();
$variant->update(['precio' => $data['price']]);
$stockDifference = (int) ($data['stock_difference'] ?? ($data['stock'] - $inventory->availableStock()));
$inventory->adjustAvailableStock($stockDifference, idempotencyKey: $stockAdjustmentId);
$inventory->adjustAvailableStock(
(int) $data['stock_difference'],
idempotencyKey: $stockAdjustmentId,
);
$this->syncDefinitions($variant, $itemAttributes, $data);
}