Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't figure out a solution...

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
I have built a shopping cart, and my client wants to be able to discount shipping depending on what item in the cart.

IE:

Red hat, blue hat, orange hat

If you buy red had and orange hat together you get a x% discount on shipping.

How could I do this to allow 1 product to have unlimited options for this, and calculate it. I really am having trouble thinking of a soultion.


My MySQL database structure is as follows:

shopping table: items in user cart
Code:
((( pid = product id )))

CREATE TABLE shopping (
  sid int(50) unsigned NOT NULL auto_increment,
  pid int(30) unsigned default NULL,
  qty int(8) unsigned default NULL,
  uid int(30) unsigned default NULL,
  swhen datetime default NULL,
  PRIMARY KEY  (sid),
  UNIQUE KEY sid (sid)
) TYPE=MyISAM;


Thanks for your help in advance.

Jason
 
is it just one specify product that will have the discount options?

i'm not sure if this is what you mean but take a look

Code:
if product_id="054026" then 'example pid for red hat

select case otherprodvariable
case "orange hat"
discount=5
case "blue hat"
discount=10
case else
discount=0
end select

end if
 
Thanks for your post steven, I did give my client the option for hard coding it in, however they want to be able to modify it, so I need to do this database driven. That is why it seems so complicated to me.
 
what if you have column called discount for orange and blue then something like this

discount=rs("discount")
otherprod=rs("pid")


if product_id="054026" then 'example pid for red hat

if otherprod<>"" then
discountamount= discount
else
discountamount= 0
end if

end if
 
This would work for one discount per product, but how can it work for say...

Blue hat had ----> Discounts on (red, green, blue, silver...)

Site San Diego www.sitesd.com

 
question: is

blue --> red

the same disount as

silver --> red

or

green --> red

or

red -->blue
 
having another table with product_id (pid) and the discount qualifying item (q_item) should work,
pid q_item
red blue
red green
red orange
blue silver
blue green

and so on
or even

pid q_item
red blue,green,orange
blue silver,green,red

the second being better from a db size POV but will need extra processing to split up the CSV list.

If a matrix of products can trigger the discount, like blue or red with green or purple you could use
pid q_item
blue,red green,purple



Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
Nightclub counting systems

So long, and thanks for all the fish.
 
What happens if there is a 5% discount for getting the red hat, a 10% discount for getting the blue hat and a 12% discount for getting both the red and the blue?

All 3 are potential database matches but the customer will expect to get the largest discount.

Perhaps your database configuration needs to take this into account and select the MAX discount? ie: 12% And you'd want to make it clear that it was the MAX instead of cummulative ... ie: 5% + 10% = 15%

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top