Просмотр исходного кода

管理后台调试变体图片上传接口 --- 保存变体接口修改

fogwind 3 дней назад
Родитель
Сommit
0bbc03452c

+ 22 - 24
packages/Longyi/Core/src/Resources/views/admin/catalog/products/edit/types/flexible_variant.blade.php

@@ -1038,19 +1038,6 @@
                             */
                             let resOptions = [];
                             let resVariants = [];
-                            const matchOptionValue = (optionCode,val,options) => {
-                                let op = options.find((item) => {
-                                    return item.code === optionCode;
-                                });
-                                for(let i = 0; i < op.values.length; i++) {
-                                    if(val.label === op.values[i].label && val.code === op.values[i].code) {
-                                        val.id = op.values[i].id;
-                                        break;
-                                    }
-                                }
-
-                                return val;
-                            };
                             
                             saveRes.data.data.selected_options.forEach((option) => {
 
@@ -1073,27 +1060,38 @@
                             });
 
                             saveRes.data.data.variants.forEach((variant) => {
-                                let values = [];
-                                let option_value_ids = [];
-                                Object.keys(variant.values).forEach((key) => {
-                                    let val = matchOptionValue(key,variant.values[key],resOptions);
+                                let option_value_ids = [], images = [];
+                                variant.values.forEach((val) => {
                                     option_value_ids.push(val.id);
-                                    values.push({
-                                        ...val,
-                                        isNewCreate: false
-                                    });
                                 });
-                  
+                                if(variant.variant_images) {
+                                    variant.variant_images.forEach((img) => {
+                                        images.push({...img});
+                                    });
+                                }
+                                
                                 resVariants.push({
                                     isNew: false,
-                                    id: variant.variant_id,
+                                    id: variant.id,
                                     price: variant.price,
                                     quantity: variant.quantity,
                                     sku: variant.sku,
+                                    variant_images: images,
                                     option_value_ids: option_value_ids,
                                     // status: item.status,
-                                    values: values
+                                    values: variant.values.map((val) => {
+                                        return {
+                                            id: val.id,
+                                            code: val.code,
+                                            label: val.label,
+                                            position: val.position,
+                                            isNewCreate: false,
+                                            parent_code: val.option.code
+                                        };
+                                    })
                                 });
+
+
                             });
 
                             this.optionsFormData.list = resOptions;