Guest User

Untitled

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. >> p = Product.find_by_model "DVD123321"
  2. => #<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>
  3. >> p.activate
  4. => true
  5. >> p.has_pricing?
  6. => false
  7. >>
  8.  
  9.  
  10. ## the state machine
  11. state_machine :state, :initial => :pending do
  12. state :pending
  13. state :active
  14. state :inactive
  15.  
  16. before_transition :to => :active do |product, transition|
  17. unless product.has_pricing? && product.has_categories?
  18. transition.rollback
  19. product.errors.add_to_base("A product cannot be activated without at least 1 standard price tier.") unless product.has_pricing?
  20. product.errors.add_to_base("A product cannot be activated without being categorized first.") unless product.has_categories?
  21. end
  22. end
  23.  
  24. event :activate do
  25. transition :to => :active, :from => [:pending, :inactive]
  26. end
  27.  
  28. event :deactivate do
  29. transition :to => :inactive, :from => [:pending, :active]
  30. end
  31.  
  32. end
Add Comment
Please, Sign In to add comment