This commit is contained in:
parent
edbd05fa6c
commit
d3f689bd3c
|
|
@ -25,30 +25,30 @@ export function AddNewVariation(Varibletaps: any[], data: any, AddVariation: any
|
||||||
// [StringimagesArray]
|
// [StringimagesArray]
|
||||||
// ];
|
// ];
|
||||||
|
|
||||||
|
const filteredAttributes = varible.attribute?.filter(Boolean); // Filter out undefined values
|
||||||
|
|
||||||
|
const mappedAttributes = filteredAttributes?.map((item: any) => {
|
||||||
const mappedAttributes = varible.attribute?.map((item: any) => {
|
return {
|
||||||
return item?.map((subitem: any) => ({
|
attribute_value_id: item?.value,
|
||||||
attribute_value_id: subitem?.value,
|
attribute_id: item?.id
|
||||||
attribute_id: subitem?.id
|
}
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(mappedAttributes, "mappedAttributes");
|
console.log(mappedAttributes, "mappedAttributes");
|
||||||
|
|
||||||
// Flatten the array of arrays
|
// Flatten the array of arrays
|
||||||
const flattenedAttributes = mappedAttributes?.filter(Boolean)?.flat();
|
// const flattenedAttributes = mappedAttributes?.filter(Boolean)?.flat();
|
||||||
|
|
||||||
const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
|
// const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
|
||||||
console.log(subArray, "subArray");
|
// console.log(subArray, "subArray");
|
||||||
console.log(index, "index");
|
// console.log(index, "index");
|
||||||
|
|
||||||
return {
|
// return {
|
||||||
...subArray,
|
// ...subArray,
|
||||||
};
|
// };
|
||||||
});
|
// });
|
||||||
|
|
||||||
console.log(arrayOfObjects, "arrayOfObjects");
|
// console.log(arrayOfObjects, "arrayOfObjects");
|
||||||
|
|
||||||
|
|
||||||
const Newproduct = {
|
const Newproduct = {
|
||||||
|
|
@ -63,10 +63,6 @@ export function AddNewVariation(Varibletaps: any[], data: any, AddVariation: any
|
||||||
de: varible?.description_de
|
de: varible?.description_de
|
||||||
},
|
},
|
||||||
// quantity: varible?.quantity,
|
// quantity: varible?.quantity,
|
||||||
...images,
|
|
||||||
...main_photo,
|
|
||||||
// ...copied_assets,
|
|
||||||
|
|
||||||
info: jsonString,
|
info: jsonString,
|
||||||
price: varible?.price,
|
price: varible?.price,
|
||||||
// product_attributes: varible?.attribute?.map((item: any, index: any) => {
|
// product_attributes: varible?.attribute?.map((item: any, index: any) => {
|
||||||
|
|
@ -74,8 +70,13 @@ export function AddNewVariation(Varibletaps: any[], data: any, AddVariation: any
|
||||||
// return { attribute_value_id: subitem?.value, attribute_id: subitem?.id }
|
// return { attribute_value_id: subitem?.value, attribute_id: subitem?.id }
|
||||||
// })
|
// })
|
||||||
// }),
|
// }),
|
||||||
product_attributes:arrayOfObjects,
|
product_attributes:mappedAttributes,
|
||||||
base_product_id: baseProductId
|
base_product_id: baseProductId,
|
||||||
|
...images,
|
||||||
|
...main_photo,
|
||||||
|
// ...copied_assets,
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
console.log(Newproduct);
|
console.log(Newproduct);
|
||||||
AddVariation(Newproduct);
|
AddVariation(Newproduct);
|
||||||
|
|
|
||||||
|
|
@ -252,26 +252,30 @@ const ViewProduct = () => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const mappedAttributes = varible.attribute?.map((item: any) => {
|
|
||||||
return item?.map((subitem: any) => ({
|
const filteredAttributes = varible.attribute?.filter(Boolean); // Filter out undefined values
|
||||||
attribute_value_id: subitem?.value,
|
console.log(filteredAttributes,"filteredAttributes");
|
||||||
attribute_id: subitem?.id
|
|
||||||
}));
|
const mappedAttributes = filteredAttributes?.map((item: any) => {
|
||||||
});
|
return {
|
||||||
|
attribute_value_id: item?.value,
|
||||||
|
attribute_id: item?.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
console.log(mappedAttributes, "mappedAttributes");
|
console.log(mappedAttributes, "mappedAttributes");
|
||||||
|
|
||||||
// Flatten the array of arrays
|
// // Flatten the array of arrays
|
||||||
const flattenedAttributes = mappedAttributes?.filter(Boolean)?.flat();
|
// const flattenedAttributes = mappedAttributes?.filter(Boolean)?.flat();
|
||||||
|
|
||||||
const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
|
// const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
|
||||||
console.log(subArray, "subArray");
|
// console.log(subArray, "subArray");
|
||||||
console.log(index, "index");
|
// console.log(index, "index");
|
||||||
|
|
||||||
return {
|
// return {
|
||||||
...subArray,
|
// ...subArray,
|
||||||
};
|
// };
|
||||||
});
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -291,6 +295,7 @@ const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
|
||||||
info: jsonString,
|
info: jsonString,
|
||||||
price: varible?.price,
|
price: varible?.price,
|
||||||
base_product_id: id,
|
base_product_id: id,
|
||||||
|
product_attributes: mappedAttributes,
|
||||||
|
|
||||||
...images,
|
...images,
|
||||||
...main_photo,
|
...main_photo,
|
||||||
|
|
@ -299,7 +304,6 @@ const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
product_attributes: arrayOfObjects,
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,13 @@ const Attribute = ({ tabKey }: any) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const handleAttributeChange = (value: any, option: any) => {
|
const handleAttributeChange = ( value: any, option: any) => {
|
||||||
// console.log(option[0],"option");
|
if (option) {
|
||||||
|
console.log(option, "option");
|
||||||
setFieldValue(`variable[${tabKey}].attribute[${option[0].id}]`, option);
|
setFieldValue(`variable[${tabKey}].attribute[${option.id}]`, option);
|
||||||
|
} else {
|
||||||
|
console.error("Option is undefined");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -33,7 +35,7 @@ const Attribute = ({ tabKey }: any) => {
|
||||||
label,
|
label,
|
||||||
value: value.attribute_id, // Change value to attribute_id
|
value: value.attribute_id, // Change value to attribute_id
|
||||||
id: value.id, // Include id in the option
|
id: value.id, // Include id in the option
|
||||||
}));
|
})) as any;
|
||||||
|
|
||||||
if (options.length === 0) {
|
if (options.length === 0) {
|
||||||
return <></>; // Don't render anything if options are empty
|
return <></>; // Don't render anything if options are empty
|
||||||
|
|
@ -54,9 +56,9 @@ const Attribute = ({ tabKey }: any) => {
|
||||||
className={`w-100`}
|
className={`w-100`}
|
||||||
|
|
||||||
|
|
||||||
defaultValue={values?.variable?.[tabKey]?.attribute?.[options?.[0]?.id]}
|
defaultValue={values?.variable?.[tabKey]?.attribute?.[options[0]?.id] ?? ""}
|
||||||
allowClear
|
allowClear
|
||||||
mode={"multiple" }
|
// mode={"multiple" }
|
||||||
onChange={handleAttributeChange}
|
onChange={handleAttributeChange}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -502,6 +502,8 @@ padding: 10px 40px;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@media screen and (max-width: 600px) {
|
@media screen and (max-width: 600px) {
|
||||||
.SearchField,.SelectWSearchField{
|
.SearchField,.SelectWSearchField{
|
||||||
display: none;
|
display: none;
|
||||||
|
|
@ -514,7 +516,14 @@ padding: 10px 40px;
|
||||||
margin-left: 60px;
|
margin-left: 60px;
|
||||||
transform: translateY(-30px);
|
transform: translateY(-30px);
|
||||||
}
|
}
|
||||||
|
@media screen and (max-width: 1000px) {
|
||||||
|
|
||||||
|
.AddNewTabText{
|
||||||
|
transform: translateY(-50px);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Dynamic form complex */
|
/* Dynamic form complex */
|
||||||
#dynamic_form_complex{
|
#dynamic_form_complex{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user