Explorar o código

增加商品属性定义

abiao %!s(int64=5) %!d(string=hai) anos
pai
achega
97aca54b74
Modificáronse 1 ficheiros con 11 adicións e 9 borrados
  1. 11 9
      app/models/product.rb

+ 11 - 9
app/models/product.rb

@@ -5,22 +5,22 @@ class Product < ActiveRecord::Base
     belongs_to :merchant, :foreign_key => :merchant_id
     validates :name,:buy_price,:price,:category_id,:count,:robo_balance_price, presence: true
     attr_accessor :v_share_img,:get_size_enum,:gross_interest_rate
-    after_find :gross_interest_rate
+    after_find :get_size_enum
     TYPE_ENUM = [["直营","direct_sale"]]
     #["代销","user_sale"]
 
     SIZE_ENUM =  []
     def get_size_enum
-=begin
-        @Size = ProductAttrConfig.where("product_id=? and size_type='size'",self.id).first
-        if !@Size.blank?
-            @productAttrs = ProductAttr.where("attr_key_id=?",@Size.id).order("recommend desc")
-            @productAttrs.each do |attr|
-                a=[attr.name,attr.id]
-                SIZE_ENUM.push(a)
+        if SIZE_ENUM.length ==0
+            @Size = ProductAttrConfig.where("product_id=? and size_type='size'",self.id).first
+            if !@Size.blank?
+                @productAttrs = ProductAttr.where("attr_key_id=?",@Size.id).order("recommend desc")
+                @productAttrs.each do |attr|
+                    a=[attr.name,attr.id]
+                    SIZE_ENUM.push(a)
+                end
             end
         end
-=end
         return "--"
     end
     IMG_STORE_PATH = "product"
@@ -50,6 +50,7 @@ class Product < ActiveRecord::Base
     end
 
     def gross_interest_rate
+=begin
         @Size = ProductAttrConfig.where("product_id=? and size_type='size'",self.id).first
         if !@Size.blank?
             @productAttrs = ProductAttr.where("attr_key_id=?",@Size.id).order("recommend desc")
@@ -58,6 +59,7 @@ class Product < ActiveRecord::Base
                 SIZE_ENUM.push(a)
             end
         end
+=end
         rate = 0
         if self.buy_price != 0 && self.price != 0
             rate = (( self.price.to_f - self.buy_price.to_f )/self.buy_price.to_f)*100