Add attribute values to matrix
This commit is contained in:
parent
12aed6457e
commit
b75ceed7cc
2 changed files with 34 additions and 13 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
//#region
|
||||||
import {
|
import {
|
||||||
add,
|
add,
|
||||||
remove,
|
remove,
|
||||||
|
@ -35,16 +36,16 @@ export interface ProductVariantCreateReducerAction {
|
||||||
valueId?: string;
|
valueId?: string;
|
||||||
variantIndex?: number;
|
variantIndex?: number;
|
||||||
}
|
}
|
||||||
|
//#endregion
|
||||||
function selectValue(
|
function selectValue(
|
||||||
prevState: ProductVariantCreateFormData,
|
prevState: ProductVariantCreateFormData,
|
||||||
attributeId: string,
|
attributeId: string,
|
||||||
valueId: string
|
valueSlug: string
|
||||||
): ProductVariantCreateFormData {
|
): ProductVariantCreateFormData {
|
||||||
const attribute = prevState.attributes.find(
|
const attribute = prevState.attributes.find(
|
||||||
attribute => attribute.id === attributeId
|
attribute => attribute.id === attributeId
|
||||||
);
|
);
|
||||||
const values = toggle(valueId, attribute.values, (a, b) => a === b);
|
const values = toggle(valueSlug, attribute.values, (a, b) => a === b);
|
||||||
const updatedAttributes = add(
|
const updatedAttributes = add(
|
||||||
{
|
{
|
||||||
id: attributeId,
|
id: attributeId,
|
||||||
|
@ -53,20 +54,40 @@ function selectValue(
|
||||||
remove(attribute, prevState.attributes, (a, b) => a.id === b.id)
|
remove(attribute, prevState.attributes, (a, b) => a.id === b.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const priceValues =
|
||||||
|
prevState.price.attribute === attributeId
|
||||||
|
? toggle(
|
||||||
|
{
|
||||||
|
slug: valueSlug,
|
||||||
|
value: ""
|
||||||
|
},
|
||||||
|
prevState.price.values,
|
||||||
|
(a, b) => a.slug === b.slug
|
||||||
|
)
|
||||||
|
: prevState.price.values;
|
||||||
|
|
||||||
|
const stockValues =
|
||||||
|
prevState.stock.attribute === attributeId
|
||||||
|
? toggle(
|
||||||
|
{
|
||||||
|
slug: valueSlug,
|
||||||
|
value: ""
|
||||||
|
},
|
||||||
|
prevState.stock.values,
|
||||||
|
(a, b) => a.slug === b.slug
|
||||||
|
)
|
||||||
|
: prevState.stock.values;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...prevState,
|
...prevState,
|
||||||
attributes: updatedAttributes,
|
attributes: updatedAttributes,
|
||||||
price: {
|
price: {
|
||||||
...prevState.price,
|
...prevState.price,
|
||||||
all: true,
|
values: priceValues
|
||||||
attribute: undefined,
|
|
||||||
values: []
|
|
||||||
},
|
},
|
||||||
stock: {
|
stock: {
|
||||||
...prevState.stock,
|
...prevState.stock,
|
||||||
all: true,
|
values: stockValues
|
||||||
attribute: undefined,
|
|
||||||
values: []
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -82056,7 +82056,7 @@ exports[`Storyshots Views / Products / Create multiple variants / summary defaul
|
||||||
style="padding:24px"
|
style="padding:24px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="MuiPaper-root-id MuiPaper-elevation1-id MuiPaper-rounded-id MuiCard-root-id"
|
class="MuiPaper-root-id MuiPaper-elevation0-id MuiPaper-rounded-id MuiCard-root-id"
|
||||||
style="margin:auto;overflow:visible;width:800px"
|
style="margin:auto;overflow:visible;width:800px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
@ -82759,7 +82759,7 @@ exports[`Storyshots Views / Products / Create multiple variants / summary errors
|
||||||
style="padding:24px"
|
style="padding:24px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="MuiPaper-root-id MuiPaper-elevation1-id MuiPaper-rounded-id MuiCard-root-id"
|
class="MuiPaper-root-id MuiPaper-elevation0-id MuiPaper-rounded-id MuiCard-root-id"
|
||||||
style="margin:auto;overflow:visible;width:800px"
|
style="margin:auto;overflow:visible;width:800px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
@ -83467,7 +83467,7 @@ exports[`Storyshots Views / Products / Create multiple variants choose values 1`
|
||||||
style="padding:24px"
|
style="padding:24px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="MuiPaper-root-id MuiPaper-elevation1-id MuiPaper-rounded-id MuiCard-root-id"
|
class="MuiPaper-root-id MuiPaper-elevation0-id MuiPaper-rounded-id MuiCard-root-id"
|
||||||
style="margin:auto;overflow:visible;width:800px"
|
style="margin:auto;overflow:visible;width:800px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
@ -83751,7 +83751,7 @@ exports[`Storyshots Views / Products / Create multiple variants prices and SKU 1
|
||||||
style="padding:24px"
|
style="padding:24px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="MuiPaper-root-id MuiPaper-elevation1-id MuiPaper-rounded-id MuiCard-root-id"
|
class="MuiPaper-root-id MuiPaper-elevation0-id MuiPaper-rounded-id MuiCard-root-id"
|
||||||
style="margin:auto;overflow:visible;width:800px"
|
style="margin:auto;overflow:visible;width:800px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|
Loading…
Reference in a new issue