My inclination would be to make the discount a property until it got quite complicated by having time-based discounts (this week only!), or other parameters.
Otherwise, one of my getPrice() methods (getListPrice(), getDiscountedPrice(), getRetailPrice(), getSpecialPriceForFriends(), etc.) would return the list times the discount. This would allow the same thing in the cart: getValue() would automatically calculate with the decimal discount multiplier in the discount property. Once you get beyond that simplicity though, it would have to be a composition object inside the cart item itself. However, I wouldn't make the cart items a struct. I would make the cart items themselves objects, with getPrice() (includes a call to getCoupons().getDiscount()) getCount(), getProperty() for things like color or size or hardback/softback. Hope that confuses the issue for your even more! ;) Stick with it, it starts to make a lot more sense after a while. Laterz! J On Wed, 23 Mar 2005 23:37:01 -0500, Jim McMullen <[EMAIL PROTECTED]> wrote: > > Thanks, Angus. Regarding your product line discount system, if each product > is responsible for its own pricing calculation, how can a product calculate > a price based on a multiple-product discount. > > For example, say the coupon is "buy any two widgets, get the third at half > off". Wouldn't your products have to be aware of what other products are in > the order/shoppingCart to be able to calculate the discount? > > Or does your shoppingCartManager just pass in the discount amount to be used > in the calculation? > > Jim McMullen > Devlab, Inc. > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of Angus Johnson > Sent: Wednesday, March 23, 2005 6:58 PM > To: [email protected] > Subject: RE: [CFCDev] Help with OO Model for Shopping Cart > > > > > Jim, > > > > Maybe if I run through how we set it up you might get some ideas. Before I > start this is how our ERP is designed and would certainly be overkill for a > simple shopping cart. It will hopefully give you some ideas on how to build > a robust discounting system though. > > > > First off we broke discounts into two types. > > > > 1.Whole of order – applies to order total > > 2.Product line – applies to each product only > > > > For whole of order discounts our process runs like this. > > > > Our system uses events to handle orders as they have a distinct lifecycle > ie, open, amend, processDiscount, processInvoice, etc. We have a manager > object which handles order objects but also retrieves discount and tax > types. After a user has completed an order we have an order object sitting > in the manager. To apply a discount we trigger a discount event on the order > as follows: > > > > - shoppingCartManager.getDiscountType() – Returns a discount object based > on myOrder.discountContext (property of order). This is where you could > supply a coupon number. > > - shoppingCartManager.myOrder.processDiscountEvent(discountObject) – creates > a discount event in the order object with discount object > > - myOrder.discountEvent.discount.calculateDiscountedPrice(totalPrice) – this > is a call to the discount object to calculate and return the discount on the > order total. > > > > The beauty of this is that we can apply multiple discounts to an order total > by stacking them in discountEvent. > > > > > > Now for product lines we don't calculate discounts on an order line. Instead > we use product/package pricing. Meaning we don't associate discounts with an > orderline but with a product itself. So here are the steps with this. > > > > - Get precondition which could be customer, order quantity, coupon number. > > - orderline[n].product.getPrice(preconditions) – on each order line we have > a product object which is responsible for it's own pricing. We use rule sets > and catalogues to filter prices on preconditions passed in. It would take me > a day to fully explain what goes on here but you could build some pretty > simple rules here like 'buy 6 get 1 free'. Even with a simple application > you can quickly build up a set of rules. The point here is that your rule is > tied to the product rather than the order. > > > > Bottom line is to correctly define your discount type before you start. Does > it apply to the whole order or a product? What are the conditions that must > be met before the discount can be given? If there is more than one discount > in what order are they applied? > > > > This is pretty full on for a simple shopping cart hey? Anyway, food for > thought J > > > > Angus > > > > > > > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of Jim McMullen > Sent: Thursday, 24 March 2005 12:58 AM > To: [email protected] > Subject: [CFCDev] Help with OO Model for Shopping Cart > > > > > I have a typical CFC-based shopping cart (ShoppingCart object holds a struct > of CartItem objects). This works well and I have no real problem with it. > > > > > > However, I now need to implement a pretty robust coupon/discount > functionality into the app, and I can't seem to figure out how to do it. I > need to allow for four types of coupons: > > > > > > (1) Whole order coupon (NN% off entire order) > > > (2) Single item coupon (NN% off this item) > > > (3) Multiple item coupon (buy one (or two), get the 2nd (or third) NN% off) > > > (4) Free item coupon (buy this item, get a free toaster) > > > > > > I think I can figure out how to model a single coupon type, but as I'm an > OOP newb, figuring out how to model and implement the whole range has got my > head spinning. > > > > > > Can anyone point me in the right direction? > > > > > > Jim McMullen > > > Devlab, Inc.---------------------------------------------------------- You > are subscribed to cfcdev. To unsubscribe, send an email to > [email protected] with the words 'unsubscribe cfcdev' as the subject of the > email. CFCDev is run by CFCZone (www.cfczone.org) and supported by > CFXHosting (www.cfxhosting.com). An archive of the CFCDev list is available > at www.mail-archive.com/[email protected] > ---------------------------------------------------------- You are > subscribed to cfcdev. To unsubscribe, send an email to [email protected] > with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is > run by CFCZone (www.cfczone.org) and supported by CFXHosting > (www.cfxhosting.com). An archive of the CFCDev list is available at > www.mail-archive.com/[email protected] > ---------------------------------------------------------- You are > subscribed to cfcdev. To unsubscribe, send an email to [email protected] > with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is > run by CFCZone (www.cfczone.org) and supported by CFXHosting > (www.cfxhosting.com). An archive of the CFCDev list is available at > www.mail-archive.com/[email protected] -- Continuum Media Group LLC Burnsville, MN 55337 http://www.web-relevant.com http://www.web-relevant.com/blogs/cfobjective ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
