Fix saving initial variant attributes (#1624)

This commit is contained in:
Dawid Tarasiuk 2021-11-29 13:32:51 +01:00 committed by GitHub
parent 057940c99a
commit 45c2726910
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import { AttributeErrorFragment } from "@saleor/fragments/types/AttributeErrorFr
import { AttributeValueFragment } from "@saleor/fragments/types/AttributeValueFragment"; import { AttributeValueFragment } from "@saleor/fragments/types/AttributeValueFragment";
import { SelectedVariantAttributeFragment } from "@saleor/fragments/types/SelectedVariantAttributeFragment"; import { SelectedVariantAttributeFragment } from "@saleor/fragments/types/SelectedVariantAttributeFragment";
import { UploadErrorFragment } from "@saleor/fragments/types/UploadErrorFragment"; import { UploadErrorFragment } from "@saleor/fragments/types/UploadErrorFragment";
import { VariantAttributeFragment } from "@saleor/fragments/types/VariantAttributeFragment";
import { FormsetData } from "@saleor/hooks/useFormset"; import { FormsetData } from "@saleor/hooks/useFormset";
import { PageDetails_page_attributes } from "@saleor/pages/types/PageDetails"; import { PageDetails_page_attributes } from "@saleor/pages/types/PageDetails";
import { ProductDetails_product_attributes } from "@saleor/products/types/ProductDetails"; 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( export function getSelectedAttributeValues(
attribute: attribute:
| PageDetails_page_attributes | PageDetails_page_attributes

View file

@ -1,4 +1,5 @@
import { import {
getDefaultAttributeValues,
getSelectedAttributeValues, getSelectedAttributeValues,
mergeChoicesWithValues mergeChoicesWithValues
} from "@saleor/attributes/utils/data"; } from "@saleor/attributes/utils/data";
@ -97,7 +98,7 @@ export function getAttributeInputFromAttributes(
}, },
id: attribute.id, id: attribute.id,
label: attribute.name, label: attribute.name,
value: [] value: getDefaultAttributeValues(attribute)
})); }));
} }