浏览代码

后台custom option恢复

chengwl 5 年之前
父节点
当前提交
8f22caff2d

+ 123 - 26
vendor/fancyecommerce/fecshop/app/appadmin/theme/base/default/catalog/productinfo/manageredit.php

@@ -139,30 +139,30 @@ function thissubmit(thiss){
     
 	$(".tabsContent .image_gallery").val(image_gallery);
 	//custom_option
-	//i = 0;
-	//custom_option = new Object();
-	//jQuery(".custom_option_list tbody tr").each(function(){
-	//	option_header = new Object();
-	//	$(this).find("td").each(function(){
-	//		rel = $(this).attr("rel");
-	//		
-	//		if(rel != 'image'){
-	//			if(rel){
-	//				option_header[rel] = $(this).attr('val');
-	//			}
-	//		}else{
-	//			rel = $(this).find("img").attr("rel");
-	//			option_header['image'] = rel;
-	//		}
-	//		
-	//	});
-	//	custom_option[i] = option_header;
-	//	i++;
-	//});
-	//	
-	//custom_option = JSON.stringify(custom_option);
-	//alert(custom_option);
-	//jQuery(".custom_option_value").val(custom_option);
+	i = 0;
+	custom_option = new Object();
+	jQuery(".custom_option_list tbody tr").each(function(){
+		option_header = new Object();
+		$(this).find("td").each(function(){
+			rel = $(this).attr("rel");
+			
+			if(rel != 'image'){
+				if(rel){
+					option_header[rel] = $(this).attr('val');
+				}
+			}else{
+				rel = $(this).find("img").attr("rel");
+				option_header['image'] = rel;
+			}
+			
+		});
+		custom_option[i] = option_header;
+		i++;
+	});
+		
+	custom_option = JSON.stringify(custom_option);
+	alert(custom_option);
+	jQuery(".custom_option_value").val(custom_option);
 	
 	cate_str = "";
 	jQuery(".category_tree div.ckbox.checked").each(function(){
@@ -210,8 +210,8 @@ function thissubmit(thiss){
 						<li><a href="javascript:;"><span><?=  Yii::$service->page->translate->__('Image Info') ?></span></a></li>
 						<li><a href="javascript:;"><span><?=  Yii::$service->page->translate->__('Category Info') ?></span></a></li>
 						<li><a href="javascript:;"><span><?=  Yii::$service->page->translate->__('Attr Group') ?></span></a></li>
-						<!--<li><a href="javascript:;"><span><?=  Yii::$service->page->translate->__('Custom Option') ?></span></a></li>
-						-->
+						<li><a href="javascript:;"><span><?=  Yii::$service->page->translate->__('Custom Option') ?></span></a></li>
+						
                         <li><a href="javascript:;"><span><?=  Yii::$service->page->translate->__('Relate Product') ?></span></a></li>
 					</ul>
 				</div>
@@ -390,6 +390,103 @@ function thissubmit(thiss){
 				<div >
 					<?= $groupAttr ?>
 				</div>
+				<div class="custom_option">	
+					<div>	
+						<?= $custom_option_add ?>	
+					</div>	
+					<div style="clear:both"></div>	
+					<div class="custom_option_img_list" style="display:none;border: 1px dashed #888;margin: 15px 0;padding: 8px 0;">	
+						<?=  $custom_option_img  ?>	
+					</div>	
+					<div style="clear:both"></div>	
+
+					<div class="custom_option_list" style="margin:20px 2px;">	
+						<?= $custom_option_list ?>	
+
+					</div>	
+					<input type="hidden" class="custom_option_value" name="custom_option"  value=""  />	
+					<script>	
+					$(document).ready(function(){	
+						jQuery(document).off("click",".chose_custom_op_img");	
+						jQuery(document).on("click",".chose_custom_op_img",function(){	
+							$(".custom_option_img_list").slideDown("slow");	
+								
+						});	
+						jQuery(document).off("click",".custom_option_img_list img");	
+						jQuery(document).on("click",".custom_option_img_list img",function(){	
+							rel = $(this).attr('rel');	
+							src = $(this).attr('src');	
+							$(".chosened_img").html('<img style="width:80px;" rel="'+rel+'" src="'+src+'">');	
+							$(".custom_option_img_list").slideUp("slow");	
+						});	
+							
+							
+						jQuery(document).off("click",".deleteCustomList");	
+						jQuery(document).on("click",".deleteCustomList",function(){	
+							$(this).parent().parent().remove();	
+								
+						});	
+						jQuery(document).off("click",".add_custom_option");	
+						jQuery(document).on("click",".add_custom_option",function(){	
+							i = 0;	
+							$str = '<tr>';	
+							general_sku = '';	
+							$(".custom_option_attr").each(function(){	
+								attr = $(this).attr("atr");	
+								val = $(this).val();	
+                                label_v = $(this).find("option:selected").text();	
+								if(!val){	
+									i = 1;	
+									alert("<?=  Yii::$service->page->translate->__('can not select empty') ?>");	
+								}	
+								$str += '<td rel="'+attr+'" val="'+val+'" >'+label_v+'</td>';	
+								val = val.replace(/ /g, "*")	
+								if(!general_sku){	
+									general_sku = val;	
+								}else{	
+									general_sku += "-"+val;	
+								}	
+							});	
+							custom_option_sku = general_sku;	
+							custom_option_sku = custom_option_sku.toLowerCase();   	
+							$(".custom_option_sku").val(custom_option_sku);	
+							$str += '<td class="custom_option_sku" rel="sku" val="'+custom_option_sku+'">'+custom_option_sku+'</td>';	
+							custom_option_qty = $(".custom_option_qty").val();	
+							if(!custom_option_qty){	
+								custom_option_qty = 99999;	
+							}	
+							$str += '<td rel="qty" val="'+custom_option_qty+'" >'+custom_option_qty+'</td>';	
+							custom_option_price = $(".custom_option_price").val();	
+							if(!custom_option_price){	
+								custom_option_price = 0;	
+							}	
+							$(".custom_option_price").val(custom_option_price);	
+							$str += '<td rel="price" val="'+custom_option_price+'" >'+custom_option_price+'</td>';	
+							chosened_img_src = $(".chosened_img img").attr('src');	
+							chosened_img_rel = $(".chosened_img img").attr('rel');	
+							if(!chosened_img_src || !chosened_img_rel){	
+								i = 1;	
+								alert("<?= Yii::$service->page->translate->__('you must chose a image');  ?>");	
+							}	
+							$str += '<td rel="image"><img style="width:30px;" rel="'+chosened_img_rel+'" src="'+chosened_img_src+'"/></td>';	
+							$str += '<td><a title="<?=  Yii::$service->page->translate->__('Delete') ?>"  href="javascript:void(0)" class="btnDel deleteCustomList"><i class="fa fa-trash-o"></i></a></td>'	
+							// 检查这个sku是否已经存在 	
+							$(".custom_option_sku").each(function(){	
+								sku = $(this).html();	
+								if(sku == custom_option_sku){	
+									i = 1;	
+									alert("<?= Yii::$service->page->translate->__('this custom_option sku is exist');  ?>");	
+								}	
+							});	
+							if(!i){	
+								//alert(11);	
+								$(".custom_option_list table tbody").append($str);	
+							}	
+						});	
+							
+					});	
+					</script>	
+				</div>
 				<div class="relation_list" style="margin:20px 2px;">
 						<?= $relation ?>	
 				</div>

+ 1 - 61
vendor/fancyecommerce/fecshop/services/product/ProductApi.php

@@ -266,67 +266,7 @@ class ProductApi extends Service
          *  6. 数组的key,需要和sku相等,譬如 red-l-s2-s3 要等于下面的  "sku": "red-l-s2-s3"
          *
          */
-        /*
-        $custom_option = $post['custom_option'];
-        if (!empty($custom_option) && is_array($custom_option) && isset($customAttrGroup[$attr_group]['custom_options']) && $customAttrGroup[$attr_group]['custom_options']) {
-            $custom_option_arr = [];
-            // 1.
-            // 该属性组对应的 custom option 的数据配置结构
-            $attr_group_config = $customAttrGroup[$attr_group]['custom_options'];
-            foreach ($custom_option as $key => $info) {
-                // 1. 图片地址是否存在,不存在则报错
-                if (!isset($info['image']) || !$info['image']) {
-                    $this->_error[] = 'custom option: image can not empty';
-                }
-                // 2.sku 存在
-                if (!isset($info['sku']) || !$info['sku']) {
-                    $this->_error[] = 'custom option: sku can not empty';
-                }
-                // 4. qty 是否存在,不存在,则初始化为0
-                $info['qty'] = (int)$info['qty'];
-                if (!$info['qty']) {
-                    $info['qty'] = 0;
-                }
-                // 5. price是否存在,不存在则初始化为0,
-                $info['price'] = (float)$info['price'];
-                if (!$info['price']) {
-                    $info['price'] = 0;
-                }
-                // 3. 通过属性组 attr_group 找到相应的custom option,查看里面的值,在这里是否都存在
-                if (is_array($attr_group_config)) {
-                    // 遍历 custom option 的数据配置结构
-                    foreach ($attr_group_config as $attrKey => $custom_option_info) {
-                        // 当前行数据中,是否符合 数据配置结构
-                        $val = '';
-                        if (isset($info[$attrKey]) && $info[$attrKey]) {
-                            $val = $info[$attrKey];
-                        } else {
-                            $this->_error[] = '[custom option error]: (attr_group:'.$attr_group.') attr['.$attrKey.'] is exist in config file ,but current data is empty';
-                            // error: 缺失 $attrKey 存在数据配置结构中,但是当前的插入数据中不存在这个属性。
-                        }
-                        if (isset($custom_option_info['display']['data']) && is_array($custom_option_info['display']['data'])) {
-                            $attr_group_config_val_arr = $custom_option_info['display']['data'];
-                            if (in_array($val, $attr_group_config_val_arr)) {
-                                
-                                // success
-                            } else {
-                                $this->_error[] = '[custom option error]: (attr_group:'.$attr_group.') attr['.$attrKey.':'.$val.'] must exist in array ['.implode(',', $attr_group_config_val_arr).'] ';
-                                // error:$attrKey 这个属性在当前的插入数据中存在,但是值不合法,值必须存在于 "数据配置结构" 中对应的数据列表中
-                            }
-                        } else {
-                            $this->_error[] = '[custom option config error]: (attr_group:'.$attr_group.') attr['.$attrKey.'] config is not correct , it must exist: [\'display\'][\'data\']';
-                        }
-                    }
-                } else {
-                    $this->_error[] = '[custom option config error]: (attr_group:'.$attr_group.') , it must be array';
-                }
-                $custom_option_arr[$info['sku']] = $info;
-            }
-            if (!empty($custom_option_arr)) {
-                $this->_param['custom_option'] = $custom_option_arr;
-            }
-        }
-        */
+       
         
         // 选填
         $remark = $post['remark'];

+ 14 - 14
vendor/fancyecommerce/fecshop/services/product/ProductMongodb.php

@@ -415,13 +415,13 @@ class ProductMongodb extends Service implements ProductInterface
         /**
          * 如果 $one['custom_option'] 不为空,则计算出来库存总数,填写到qty
          */
-        //if (is_array($one['custom_option']) && !empty($one['custom_option'])) {
-        //    $custom_option_qty = 0;
-        //    foreach ($one['custom_option'] as $co_one) {
-        //        $custom_option_qty += $co_one['qty'];
-        //    }
-        //    $one['qty'] = $custom_option_qty;
-        //}
+        if (is_array($one['custom_option']) && !empty($one['custom_option'])) {
+           $custom_option_qty = 0;
+           foreach ($one['custom_option'] as $co_one) {
+               $custom_option_qty += $co_one['qty'];
+           }
+           $one['qty'] = $custom_option_qty;
+        }
         /**
          * 保存产品
          */
@@ -490,13 +490,13 @@ class ProductMongodb extends Service implements ProductInterface
         /**
          * 如果 $one['custom_option'] 不为空,则计算出来库存总数,填写到qty
          */
-        //if (is_array($one['custom_option']) && !empty($one['custom_option'])) {
-        //    $custom_option_qty = 0;
-        //    foreach ($one['custom_option'] as $co_one) {
-        //        $custom_option_qty += $co_one['qty'];
-        //    }
-        //    $one['qty'] = $custom_option_qty;
-        //}
+        if (is_array($one['custom_option']) && !empty($one['custom_option'])) {
+           $custom_option_qty = 0;
+           foreach ($one['custom_option'] as $co_one) {
+               $custom_option_qty += $co_one['qty'];
+           }
+           $one['qty'] = $custom_option_qty;
+        }
         
         /**
          * 保存产品