spree/spree — pull request #2569 by huoxito (2013-02-15 00:54:09+00:00)
Title: Fixes first order promotion rule

I was going to submit a patch to fix a scenario which involved the ``FirstOrder`` but then realized that the rule was not working at all.

The scenario was:

Store has a promo with a the first order rule.
Customer places an order and the discount applies to this order, as it should
Admin updates the order some how. e.g. updates a shipment
The first order discount is removed from the order when it shouldn't.

That is in a Spree store tracked somewhere between Spree 1.2 and Spree 1.3. Spree should not remove the discount from the first order when it's completed.

This patch fixes that and also the logic involving the promotion rule. I believe this was the commit that introduced the bug c014893b7dc2560a581f62096e448d546440c9f7. Currently promotions with this rule will probably never be eligible (for signed in users) due to this logic:

```ruby
...
if user
return orders_by_email(user.email) == 0
elsif order.email
return orders_by_email(order.email) == 0
end
...

def orders_by_email(email)
Spree::Order.where(:email => email).count
end
```

Please let me know if I missed anything. Is 1-2-stable still receiving pull requests? We could apply this there and resolve #2306