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 {
|
||||
add,
|
||||
remove,
|
||||
|
@ -35,16 +36,16 @@ export interface ProductVariantCreateReducerAction {
|
|||
valueId?: string;
|
||||
variantIndex?: number;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
function selectValue(
|
||||
prevState: ProductVariantCreateFormData,
|
||||
attributeId: string,
|
||||
valueId: string
|
||||
valueSlug: string
|
||||
): ProductVariantCreateFormData {
|
||||
const attribute = prevState.attributes.find(
|
||||
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(
|
||||
{
|
||||
id: attributeId,
|
||||
|
@ -53,20 +54,40 @@ function selectValue(
|
|||
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 {
|
||||
...prevState,
|
||||
attributes: updatedAttributes,
|
||||
price: {
|
||||
...prevState.price,
|
||||
all: true,
|
||||
attribute: undefined,
|
||||
values: []
|
||||
values: priceValues
|
||||
},
|
||||
stock: {
|
||||
...prevState.stock,
|
||||
all: true,
|
||||
attribute: undefined,
|
||||
values: []
|
||||
values: stockValues
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -82056,7 +82056,7 @@ exports[`Storyshots Views / Products / Create multiple variants / summary defaul
|
|||
style="padding:24px"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
<div
|
||||
|
@ -82759,7 +82759,7 @@ exports[`Storyshots Views / Products / Create multiple variants / summary errors
|
|||
style="padding:24px"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
<div
|
||||
|
@ -83467,7 +83467,7 @@ exports[`Storyshots Views / Products / Create multiple variants choose values 1`
|
|||
style="padding:24px"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
<div
|
||||
|
@ -83751,7 +83751,7 @@ exports[`Storyshots Views / Products / Create multiple variants prices and SKU 1
|
|||
style="padding:24px"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
<div
|
||||
|
|
Loading…
Reference in a new issue