Fix updating product that has no variants (#649)
* Fix updating product that has no variants * Update changelog
This commit is contained in:
parent
355c796bd8
commit
cc2fb0ae4e
2 changed files with 27 additions and 16 deletions
|
@ -22,6 +22,7 @@ All notable, unreleased changes to this project will be documented in this file.
|
|||
- Reset modal state after closing - #644 by @dominik-zeglen
|
||||
- Fix incorrect messages - #643 by @dominik-zeglen
|
||||
- Do not use devserver to run cypress tests - #650 by @dominik-zeglen
|
||||
- Fix updating product that has no variants - #649 by @dominik-zeglen
|
||||
|
||||
## 2.10.1
|
||||
|
||||
|
|
|
@ -167,23 +167,33 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
|||
const hasVariants = maybe(() => product.productType.hasVariants, false);
|
||||
|
||||
const handleSubmit = (data: ProductUpdatePageFormData) => {
|
||||
const dataStocks = stocks.map(stock => stock.id);
|
||||
const variantStocks = product.variants[0].stocks.map(
|
||||
stock => stock.warehouse.id
|
||||
);
|
||||
const stockDiff = diff(variantStocks, dataStocks);
|
||||
if (product.productType.hasVariants) {
|
||||
onSubmit({
|
||||
...data,
|
||||
addStocks: [],
|
||||
attributes,
|
||||
removeStocks: [],
|
||||
updateStocks: []
|
||||
});
|
||||
} else {
|
||||
const dataStocks = stocks.map(stock => stock.id);
|
||||
const variantStocks = product.variants[0]?.stocks.map(
|
||||
stock => stock.warehouse.id
|
||||
);
|
||||
const stockDiff = diff(variantStocks, dataStocks);
|
||||
|
||||
onSubmit({
|
||||
...data,
|
||||
addStocks: stocks.filter(stock =>
|
||||
stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||
),
|
||||
attributes,
|
||||
removeStocks: stockDiff.removed,
|
||||
updateStocks: stocks.filter(
|
||||
stock => !stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||
)
|
||||
});
|
||||
onSubmit({
|
||||
...data,
|
||||
addStocks: stocks.filter(stock =>
|
||||
stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||
),
|
||||
attributes,
|
||||
removeStocks: stockDiff.removed,
|
||||
updateStocks: stocks.filter(
|
||||
stock => !stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||
)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in a new issue