Przeglądaj źródła

商品规格更改返回

abiao 5 lat temu
rodzic
commit
67ca30450f

+ 12 - 10
go/gopath/src/fohow.com/apps/controllers/product_controller/product_controller.go

@@ -308,22 +308,24 @@ func (self *ProductController) GetProductSizesByPid() {
 			if productKeyConfig != nil {
 				if item.SizeType == product_model.SIZE_TYPE_1 {
 					attrList := product_model.GetProductAttrsByKId(productKeyConfig.Id)
-					/*for _, attr := range attrList {
-						if attr.Id == product.SizeId {
-							attr.IsSelect = true
+					for _, attr := range attrList {
+						prod := product_model.GetProductByIdAndSizeId(product.RelateProductId, attr.Id, true)
+						if prod == nil {
+							continue
 						}
-					}*/
-					productKeyConfig.ProductAttr = attrList
+						productKeyConfig.ProductAttr = append(productKeyConfig.ProductAttr, attr)
+					}
 					ret.Size = productKeyConfig
 				}
 				if item.SizeType == product_model.SIZE_TYPE_2 {
 					attrList := product_model.GetProductAttrsByKId(productKeyConfig.Id)
-					/*	for _, attr := range attrList {
-						if attr.Id == product.ColorId {
-							attr.IsSelect = true
+					for _, attr := range attrList {
+						prod := product_model.GetProductByIdAndColorId(product.RelateProductId, attr.Id, true)
+						if prod == nil {
+							continue
 						}
-					}*/
-					productKeyConfig.ProductAttr = attrList
+						productKeyConfig.ProductAttr = append(productKeyConfig.ProductAttr, attr)
+					}
 					ret.Color = productKeyConfig
 				}
 			}

+ 36 - 0
go/gopath/src/fohow.com/apps/models/product_model/product.go

@@ -326,3 +326,39 @@ func GetProductByIdAndSizeAndColor(id, sizeId, colorId int64, useCache bool) *Pr
 	cache.Cache.Put(k, item, 5*time.Minute)
 	return item
 }
+
+//根据商品 relate_Id 跟 sizeId,获取商品信息
+func GetProductByIdAndSizeId(relateId, sizeId int64, useCache bool) *Product {
+	k := fmt.Sprintf("product_model.GetProductByIdAndSizeId[%d]", relateId)
+	if useCache {
+		if v, ok := cache.Cache.Get(k).(*Product); ok {
+			return v
+		}
+	}
+	item := new(Product)
+	o := orm.NewOrm()
+	if err := o.QueryTable(item).Filter("relate_product_id", relateId).Filter("size_id", sizeId).One(item); err != nil {
+		return nil
+	}
+	item.Cover = GetCoverByPId(relateId, useCache)
+	cache.Cache.Put(k, item, 5*time.Minute)
+	return item
+}
+
+//根据商品 relate_Id 跟 colorId,获取商品信息
+func GetProductByIdAndColorId(relateId, sizeId int64, useCache bool) *Product {
+	k := fmt.Sprintf("product_model.GetProductByIdAndColorId[%d]", relateId)
+	if useCache {
+		if v, ok := cache.Cache.Get(k).(*Product); ok {
+			return v
+		}
+	}
+	item := new(Product)
+	o := orm.NewOrm()
+	if err := o.QueryTable(item).Filter("relate_product_id", relateId).Filter("color_id", sizeId).One(item); err != nil {
+		return nil
+	}
+	item.Cover = GetCoverByPId(relateId, useCache)
+	cache.Cache.Put(k, item, 5*time.Minute)
+	return item
+}