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
|
- Reset modal state after closing - #644 by @dominik-zeglen
|
||||||
- Fix incorrect messages - #643 by @dominik-zeglen
|
- Fix incorrect messages - #643 by @dominik-zeglen
|
||||||
- Do not use devserver to run cypress tests - #650 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
|
## 2.10.1
|
||||||
|
|
||||||
|
|
|
@ -167,8 +167,17 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
const hasVariants = maybe(() => product.productType.hasVariants, false);
|
const hasVariants = maybe(() => product.productType.hasVariants, false);
|
||||||
|
|
||||||
const handleSubmit = (data: ProductUpdatePageFormData) => {
|
const handleSubmit = (data: ProductUpdatePageFormData) => {
|
||||||
|
if (product.productType.hasVariants) {
|
||||||
|
onSubmit({
|
||||||
|
...data,
|
||||||
|
addStocks: [],
|
||||||
|
attributes,
|
||||||
|
removeStocks: [],
|
||||||
|
updateStocks: []
|
||||||
|
});
|
||||||
|
} else {
|
||||||
const dataStocks = stocks.map(stock => stock.id);
|
const dataStocks = stocks.map(stock => stock.id);
|
||||||
const variantStocks = product.variants[0].stocks.map(
|
const variantStocks = product.variants[0]?.stocks.map(
|
||||||
stock => stock.warehouse.id
|
stock => stock.warehouse.id
|
||||||
);
|
);
|
||||||
const stockDiff = diff(variantStocks, dataStocks);
|
const stockDiff = diff(variantStocks, dataStocks);
|
||||||
|
@ -184,6 +193,7 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
stock => !stockDiff.added.some(addedStock => addedStock === stock.id)
|
stock => !stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue