|
|
@@ -6,6 +6,22 @@ class Product < ActiveRecord::Base
|
|
|
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 :get_size_enum
|
|
|
+ after_create :after_create
|
|
|
+ after_update :after_update
|
|
|
+ def after_create
|
|
|
+ #主商品默认关联商品
|
|
|
+ if self.show_flag==1
|
|
|
+ self.relate_product_id = self.id
|
|
|
+ self.save
|
|
|
+ end
|
|
|
+ end
|
|
|
+ def after_update
|
|
|
+ #若取消,则用户卡次数加1
|
|
|
+ if self.show_flag==1
|
|
|
+ self.relate_product_id = self.id
|
|
|
+ self.save
|
|
|
+ end
|
|
|
+ end
|
|
|
TYPE_ENUM = [["直营","direct_sale"]]
|
|
|
#["代销","user_sale"]
|
|
|
SIZE_ENUM = []
|
|
|
@@ -13,7 +29,7 @@ class Product < ActiveRecord::Base
|
|
|
def get_size_enum
|
|
|
SIZE_ENUM.clear
|
|
|
if SIZE_ENUM.length ==0
|
|
|
- linkSize = ProductAttrConfig.where("product_id=? and size_type='size'",self.id).first
|
|
|
+ linkSize = ProductAttrConfig.where("product_id=? and size_type='size'",self.relate_product_id).first
|
|
|
if !linkSize.blank?
|
|
|
productAttrs = ProductAttr.where("attr_key_id=?",linkSize.attr_key_id).order("recommend desc")
|
|
|
productAttrs.each do |attr|
|
|
|
@@ -25,7 +41,7 @@ class Product < ActiveRecord::Base
|
|
|
|
|
|
COLOR_ENUM.clear
|
|
|
if COLOR_ENUM.length==0
|
|
|
- linkColor = ProductAttrConfig.where("product_id=? and size_type='color'",self.id).first
|
|
|
+ linkColor = ProductAttrConfig.where("product_id=? and size_type='color'",self.relate_product_id).first
|
|
|
if !linkColor.blank?
|
|
|
productColorAttrs = ProductAttr.where("attr_key_id=?",linkColor.attr_key_id).order("recommend desc")
|
|
|
productColorAttrs.each do |color_attr|
|