Re: Business rules and filtering
Re: Business rules and filtering
- Subject: Re: Business rules and filtering
- From: Maik Musall <email@hidden>
- Date: Thu, 14 Feb 2013 14:35:24 +0100
Am 14.02.2013 um 14:00 schrieb Pascal Robert <email@hidden>:
>>> In a shopping cart, how would you apply discount based on business rules? For example, if someone buy a quantity of 3 of the same item, you apply discount X, or if an item is ordered before a certain date, you apply discount Y. Yes, I can do that all in code, but that's not very flexible.
>>>
>>> Any ideas?
>>
>> Add an abstraction layer for shopping cart items and add virtual items to the cart that contain the calculated rebate?
>
> If I understand well, let's say I have "item.quantity()" with a value of 2. I then would have another EO related to this item for each quantity that a discount should be applied to.
>
> For example, item's name is "WOWODC 2013 ticket" and someone wants to buy two tickets. In "VirtualItem", I would have multiple rows for "WOWODC 2013 ticket", with a different quantity and discount for each row, so I would do a fetch « VirtualItem.NAME.eq("WOWODC 2013 ticket").and(VirtualItem.QUANTITY(2) » and apply the discount from the fetched row.
The point of virtual items would be to not be persistent, and not introduce new relationships and persistence complexity.
Obviously there are several ways to do that, and it depends on how you want to apply the rebate. Rebates generally could go per item, per item collection, or per purchase. If you tie the rebate logic to items only, you'll have difficulties applying a total rebate over the whole purchase containing all sorts of item types.
My original thought would depend on the rebate stuff happening in cart summing. Iterate over items, and ask each item about it's effective price, so that individual items can return a rebated price based on their quantity() or other properties. Also, the cart could decide to apply a general overall rebate if certain conditions are met, like a membership.
You would sum up both real price and effective price, and if they are different in cart sum, generate a virtual (non-EO) item that contains the rebate sum. Make an interface that the WOD's item display operates on, and let both real items and virtual items implement that interface. Then store the sums in the cart EO. Virtual items would just be re-generated whenever the cart is redisplayed.
And that's just ONE way...
Maik
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden