This commit is contained in:
KarimAldeen 2024-03-30 12:56:10 +03:00
parent edbd05fa6c
commit d3f689bd3c
4 changed files with 62 additions and 46 deletions

View File

@ -25,30 +25,30 @@ export function AddNewVariation(Varibletaps: any[], data: any, AddVariation: any
// [StringimagesArray]
// ];
const filteredAttributes = varible.attribute?.filter(Boolean); // Filter out undefined values
const mappedAttributes = varible.attribute?.map((item: any) => {
return item?.map((subitem: any) => ({
attribute_value_id: subitem?.value,
attribute_id: subitem?.id
}));
const mappedAttributes = filteredAttributes?.map((item: any) => {
return {
attribute_value_id: item?.value,
attribute_id: item?.id
}
});
console.log(mappedAttributes, "mappedAttributes");
// 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) => {
console.log(subArray, "subArray");
console.log(index, "index");
// const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
// console.log(subArray, "subArray");
// console.log(index, "index");
return {
...subArray,
};
});
// return {
// ...subArray,
// };
// });
console.log(arrayOfObjects, "arrayOfObjects");
// console.log(arrayOfObjects, "arrayOfObjects");
const Newproduct = {
@ -63,10 +63,6 @@ export function AddNewVariation(Varibletaps: any[], data: any, AddVariation: any
de: varible?.description_de
},
// quantity: varible?.quantity,
...images,
...main_photo,
// ...copied_assets,
info: jsonString,
price: varible?.price,
// 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 }
// })
// }),
product_attributes:arrayOfObjects,
base_product_id: baseProductId
product_attributes:mappedAttributes,
base_product_id: baseProductId,
...images,
...main_photo,
// ...copied_assets,
};
console.log(Newproduct);
AddVariation(Newproduct);

View File

@ -252,26 +252,30 @@ const ViewProduct = () => {
const mappedAttributes = varible.attribute?.map((item: any) => {
return item?.map((subitem: any) => ({
attribute_value_id: subitem?.value,
attribute_id: subitem?.id
}));
const filteredAttributes = varible.attribute?.filter(Boolean); // Filter out undefined values
console.log(filteredAttributes,"filteredAttributes");
const mappedAttributes = filteredAttributes?.map((item: any) => {
return {
attribute_value_id: item?.value,
attribute_id: item?.id
}
});
console.log(mappedAttributes, "mappedAttributes");
// Flatten the array of arrays
const flattenedAttributes = mappedAttributes?.filter(Boolean)?.flat();
// // Flatten the array of arrays
// const flattenedAttributes = mappedAttributes?.filter(Boolean)?.flat();
const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
console.log(subArray, "subArray");
console.log(index, "index");
// const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
// console.log(subArray, "subArray");
// console.log(index, "index");
return {
...subArray,
};
});
// return {
// ...subArray,
// };
// });
@ -291,6 +295,7 @@ const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
info: jsonString,
price: varible?.price,
base_product_id: id,
product_attributes: mappedAttributes,
...images,
...main_photo,
@ -299,7 +304,6 @@ const arrayOfObjects = flattenedAttributes?.map((subArray: any, index: any) => {
product_attributes: arrayOfObjects,
}

View File

@ -13,10 +13,12 @@ const Attribute = ({ tabKey }: any) => {
const handleAttributeChange = ( value: any, option: any) => {
// console.log(option[0],"option");
setFieldValue(`variable[${tabKey}].attribute[${option[0].id}]`, option);
if (option) {
console.log(option, "option");
setFieldValue(`variable[${tabKey}].attribute[${option.id}]`, option);
} else {
console.error("Option is undefined");
}
};
@ -33,7 +35,7 @@ const Attribute = ({ tabKey }: any) => {
label,
value: value.attribute_id, // Change value to attribute_id
id: value.id, // Include id in the option
}));
})) as any;
if (options.length === 0) {
return <></>; // Don't render anything if options are empty
@ -54,9 +56,9 @@ const Attribute = ({ tabKey }: any) => {
className={`w-100`}
defaultValue={values?.variable?.[tabKey]?.attribute?.[options?.[0]?.id]}
defaultValue={values?.variable?.[tabKey]?.attribute?.[options[0]?.id] ?? ""}
allowClear
mode={"multiple" }
// mode={"multiple" }
onChange={handleAttributeChange}

View File

@ -502,6 +502,8 @@ padding: 10px 40px;
@media screen and (max-width: 600px) {
.SearchField,.SelectWSearchField{
display: none;
@ -514,7 +516,14 @@ padding: 10px 40px;
margin-left: 60px;
transform: translateY(-30px);
}
@media screen and (max-width: 1000px) {
.AddNewTabText{
transform: translateY(-50px);
}
}
/* Dynamic form complex */
#dynamic_form_complex{