refactor(inventory): update stock validation rules and enforce stock_difference requirement
This commit is contained in:
@@ -169,7 +169,7 @@ class AccommodationService
|
||||
'title' => trim($variant['title']),
|
||||
'value' => $this->valueCode($variant['title']),
|
||||
'description' => $variant['description'] ?? null,
|
||||
'stock' => (int) $variant['stock'],
|
||||
...(array_key_exists('stock', $variant) ? ['stock' => (int) $variant['stock']] : []),
|
||||
])->all();
|
||||
}
|
||||
|
||||
@@ -257,8 +257,10 @@ class AccommodationService
|
||||
'descripcion' => $data['description'],
|
||||
'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,
|
||||
);
|
||||
$variant->definitions()->updateOrCreate(
|
||||
['item_attribute_id' => $itemAttribute->id],
|
||||
['value' => $data['value']],
|
||||
|
||||
Reference in New Issue
Block a user