refactor(inventory): update stock validation rules and enforce stock_difference requirement
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user