瀏覽代碼

product cache clear

abiao 4 年之前
父節點
當前提交
ea06604cc5
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12 1
      app/models/product.rb

+ 12 - 1
app/models/product.rb

@@ -7,7 +7,18 @@ class Product < ActiveRecord::Base
     scope :inactive, -> { where(ptype: "direct_sale") }
     belongs_to :product_cat, :foreign_key => :category_id
     belongs_to :merchant, :foreign_key => :merchant_id
-    validates :name,:buy_price,:price,:category_id,:count,:robo_balance_price, presence: true
+    validates :name,:buy_price,:price,:category_id,:count,:robo_balance_price,:relate_product_id, presence: true
+    validate :product_validation
+
+    def product_validation
+        if self.relate_product_id <= 0
+            #主商品默认关联商品
+            if self.show_flag
+                self.relate_product_id = self.id
+                self.save
+            end
+        end
+    end
     attr_accessor :v_share_img,:get_size_enum,:get_color_enum,:gross_interest_rate
     # after_find :get_size_enum
     after_create :after_create