Guest User

Untitled

a guest
Jan 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. # the code
  2.  
  3. has_many :line_items do
  4. def total
  5. require 'pp'
  6. pp to_a
  7. if self[0] == self[1]
  8. self[1..-1].map(&:total).sum
  9. else
  10. map(&:total).sum
  11. end
  12. # self[1..-1].map(&:total).sum
  13. end
  14. end
  15.  
  16.  
  17.  
  18. # result from pp =>
  19. [#<LineItem _id: 4e4d34f7bb71f923eb000001, _type: nil, name: "Hazelfern", image: nil, item_id: "A2750", invent_size_id: "", invent_color_id: "", config_id: "", configure: {}, quantity: 1, price: 295.0, delivery_status: nil, order_id: BSON::ObjectId('4e4d3352bb71f923ae000001')>,
  20. #<LineItem _id: 4e4d34f7bb71f923eb000001, _type: nil, name: "Hazelfern", image: nil, item_id: "A2750", invent_size_id: "", invent_color_id: "", config_id: "", configure: {}, quantity: 1, price: 295.0, delivery_status: nil, order_id: BSON::ObjectId('4e4d3352bb71f923ae000001')>]
Add Comment
Please, Sign In to add comment