Today Only Buy One, Get One Free

I l @ ve RuBoard

Today Only! Buy One, Get One Free!

BFG promotions work as follows : If a customer buys over a threshold amount of a given book or books from a given category, that customer receives a free gift. As with most sites, the gifts themselves aren't "normal" merchandise; you won't find the gift items by searching the categories.

In this example, two promotions will be available at launch. Buy Javabeans Unleashed and get a can of coffee, and buy any two J2ME books and get a PDA cover.

First you have to enter the two promotional items and the two promotions (see Listing 12.1).

Listing 12.1 Sample Data for the PROMOTION Table
 insert into PRODUCT (TITLE, PUB_DATE, ISBN, DESCRIPTION, PRICE) values        ('Genuine Nagahyde PDA Carrying Case',         '1998-12-22','PALMCASE','A genuine Nagahyde Palm-compatible PDA case, \ just the thing to keep your precious PDA safe from the elements.  Made from the \ skin of the rare endangered Naga, this case is sure to make you a hit at your \ next trade show.', 25.00); insert into PRODUCT (TITLE, PUB_DATE, ISBN, DESCRIPTION, PRICE) values        ('Jamaican Coffee',         '1998-12-22','COFFEECAN','When a late night of engineering has your eyes \ defocused and you just can\'t grind out that last method, grind some of these \ imported Jamaican Blue Mountain coffee beans instead.  The caffeine will be just \ the thing to keep you going.', 12.00); . . . insert into PROMOTION (PROMO_ID, PROMO_NAME, PROD_OR_CAT,                        CATEGORY_ID, PRODUCT_ISBN, PROMO_TYPE,                        DISCOUNT_QUANT, GIFT_ID)        values (1, 'Get a Palm Case with any 2 J2ME Books', 'C', 2,                null, 'B', 2, 'PALMCASE'); insert into PROMOTION (PROMO_ID, PROMO_NAME, PROD_OR_CAT,                        CATEGORY_ID, PRODUCT_ISBN, PROMO_TYPE,                        DISCOUNT_QUANT, GIFT_ID)        values (2, 'Buy Javabeans Unleashed, get a can of Jamaican Coffee',               'P', null, '067231424X', 'B', 1, 'COFFEECAN'); 

The promotion code should review the contents of the cart, find any promotions whose qualifications have been met, and add the appropriate gift to the cart.

This is where the isPromotionItem property of the CartItem comes in. The shopping cart code needs to recalculate promotions every time the cart contents change. If the results of the last promotion calculation are not cleared first, more gifts will be added to the cart each time. Any promotional items need to be cleared out first, and the isPromotionItem flag lets you tell them apart.

I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net