Fix saving initial variant attributes (#1624)
This commit is contained in:
parent
057940c99a
commit
45c2726910
2 changed files with 13 additions and 1 deletions
|
@ -7,6 +7,7 @@ import { AttributeErrorFragment } from "@saleor/fragments/types/AttributeErrorFr
|
|||
import { AttributeValueFragment } from "@saleor/fragments/types/AttributeValueFragment";
|
||||
import { SelectedVariantAttributeFragment } from "@saleor/fragments/types/SelectedVariantAttributeFragment";
|
||||
import { UploadErrorFragment } from "@saleor/fragments/types/UploadErrorFragment";
|
||||
import { VariantAttributeFragment } from "@saleor/fragments/types/VariantAttributeFragment";
|
||||
import { FormsetData } from "@saleor/hooks/useFormset";
|
||||
import { PageDetails_page_attributes } from "@saleor/pages/types/PageDetails";
|
||||
import { ProductDetails_product_attributes } from "@saleor/products/types/ProductDetails";
|
||||
|
@ -132,6 +133,16 @@ export function getAttributeData(
|
|||
}
|
||||
}
|
||||
|
||||
export function getDefaultAttributeValues(attribute: VariantAttributeFragment) {
|
||||
switch (attribute.inputType) {
|
||||
case AttributeInputTypeEnum.BOOLEAN:
|
||||
return ["false"];
|
||||
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function getSelectedAttributeValues(
|
||||
attribute:
|
||||
| PageDetails_page_attributes
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
getDefaultAttributeValues,
|
||||
getSelectedAttributeValues,
|
||||
mergeChoicesWithValues
|
||||
} from "@saleor/attributes/utils/data";
|
||||
|
@ -97,7 +98,7 @@ export function getAttributeInputFromAttributes(
|
|||
},
|
||||
id: attribute.id,
|
||||
label: attribute.name,
|
||||
value: []
|
||||
value: getDefaultAttributeValues(attribute)
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue