radar/spree — pull request #5 by huoxito (2013-08-15 21:16:53+00:00)
Title: Introduce LineItemAdjust class

There will be scenarios where we want to save the line item but we don't
want to trigger all adjustments and order update calls. e.g. when saving
multiple line items at once in /cart or when saving a line item once
order is completed

Attempt to detach line item save from always triggering adjustments logic. Next I intend to write some specs of what we'd expect for order totals and line item totals as we add / remove items to cart and activate promos. They should all fail probably but at least I think they can lead us to a better api so we can get the whole thing working together.

I'm trying to look already into way to activate promos on line items. Please let me know what you think so far as right now I kind of depend on #4 and #3 to move on.

My idea right now for that is to activate line items promos in OrderContents as well (or in some other object that wraps OrderContents). The api I have in mind is something like this:

```ruby
def add(variant, quantity, currency=nil, shipment=nil)
line_item = add_to_line_item(variant, quantity, currency, shipment)
PromotionHandler.new(line_item: line_item).apply_on_item
adjust_line_item line_item
end

class PromotionHandler
# ... initialize

def apply_on_item
Promotion.discount_on(line_item).each do |promo|
promo.activate(line_item)
end
end
end
```

Just a rough idea. I guess we probably will need to move pieces around a lot to avoid too much repeated calls once we can start checking everything working together.