|
|
@@ -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
|