Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> p = Product.find_by_model "DVD123321"
- => #<Product id: 2437, model: "DVD123321", internal_reference: "DVD123", permalink: "sony-dvd-r-dvd123321", weight: #<BigDecimal:6b5925c,'0.123E3',4(12)>, brand_id: 48, state: "inactive", invoice_description: "DVD123", text_description: "DVD123", created_at: "2009-06-03 19:24:42", updated_at: "2009-06-03 19:50:48", classification_id: 134, part_number: "DVD123", markup_description: "<p>DVD123</p>", has_old_images: nil, old_url: nil, housing_type: nil, housing_size: nil, packaging: nil, capacity_units: nil, capacity: nil, case_type: nil, priced_per: nil, pieces_per_unit: nil, on_sale: false, on_clearance: false, eligible_for_srr_points: true, srr_model: "DVD123", dealer_cost: #<BigDecimal:6b58a50,'0.0',4(12)>, dfi: #<BigDecimal:6b589c4,'0.0',4(12)>, volume_rebate: #<BigDecimal:6b58960,'0.0',4(12)>, credit_disc: #<BigDecimal:6b58910,'0.0',4(12)>, credit_term: 30, promo_rebate: #<BigDecimal:6b588ac,'0.0',4(12)>, cost_of_goods_sold_category_id: 17>
- >> p.activate
- => true
- >> p.has_pricing?
- => false
- >>
- ## the state machine
- state_machine :state, :initial => :pending do
- state :pending
- state :active
- state :inactive
- before_transition :to => :active do |product, transition|
- unless product.has_pricing? && product.has_categories?
- transition.rollback
- product.errors.add_to_base("A product cannot be activated without at least 1 standard price tier.") unless product.has_pricing?
- product.errors.add_to_base("A product cannot be activated without being categorized first.") unless product.has_categories?
- end
- end
- event :activate do
- transition :to => :active, :from => [:pending, :inactive]
- end
- event :deactivate do
- transition :to => :inactive, :from => [:pending, :active]
- end
- end
Add Comment
Please, Sign In to add comment