Click to See Complete Forum and Search --> : a tiny bit of help, please...


Teenager
04-20-2009, 07:32 AM
Hello people,

I've just signed up to this site as I'm in need of some help.
I'm working on a script for a client who sells wine and in when it comes to calculating the shipping, I'm a bit stuck.

basically he sells wine by the bottle AND in gift sets, so if a customer was to buy a number of bottle AND a gift set, the cost of the gift box goes down €6.

here's what i have so far...


// calculate shipping

GiftShipping = (Number(Q6.value) * 15) + (Number(Q7.value) * 21) + (Number(Q8.value) * 21);
BotQuantity = Number(Q1.value) + Number(Q2.value) + Number(Q3.value) + Number(Q4.value) + Number(Q5.value);
fShipping = (BotQuantity * 2.30);
if (BotQuantity > 18) {
fShipping = (BotQuantity * 1.40);
if (BotQuantity > 48) {
fShipping = (BotQuantity * 1.00);
if (BotQuantity >= 96) {
fShipping = (BotQuantity * 0.70);
}
}
}
fShipping = fShipping + GiftShipping;


any help would be FAB, as i know hardly anything about PHP.

:D

jeffrydell
04-20-2009, 09:20 AM
Well the first thing I see, which is off topic to your question, is that you are hard-coding prices in to the script. This will be a cause for regret later. Trust me.

You should put the prices in a table so it will be easy to update later.

Now, what exactly is giving you trouble with regards to the discount?

Teenager
04-20-2009, 09:31 AM
well, it wasn't my code to begin with. i inherited this task from an employee that is no longer here. anyway...


on the site you can purchase cases of wine in various quantities (see previous posted script for alternative shipping costs), but also, you can buy gift boxes.

now the client wants the price of gift boxes to be reduced by €6 ONLY IF a customer buys wine as well.


here's the site im working on...

http://www.chateau-jeanbrun.com/

jeffrydell
04-20-2009, 10:40 AM
well, it wasn't my code to begin with. i inherited this task from an employee that is no longer here. anyway...

Please understand, I wasn't attacking ... just commenting for your benefit. And I believe you should consider that there could be a reason why that employee isn't there anymore (possibly in part because of taking short-cuts that end up being real time-suckers down the road).

Think about cleaning that up and telling your client that you are doing so. They'll likely respect you for having some foresight and keeping an eye on their bottom line. Maybe not - but it's good business practice that is likely to pay off for you in the long run.

OK - on to the task at hand and doing a little guess-work here.

It LOOKS like your Q6, Q7, and Q8 are the quantities of different kinds of gift boxes. That's an assumption - we know what that can mean.

According to your statement above, it appears that the client wants the price of shipping for each gift box reduced by 6 euro.

Working from that info, here's what I would 'plug in' right before the last line where you total up shipping:

if (($GiftShipping > 1) AND ($BotQuantity > 1))
{
$totboxes = (Q6 + Q7 + Q8);
$discount = ($totboxes * 6);
$GiftShipping = ($GiftShipping - $discount);
}

This takes 6 eu off the shipping of Gift boxes for each box purchased.

One more thing - and I may be showing some ignorance here because I've led a very sheltered life - this code doesn't look like php as I know it. Perhaps Javascript?

Anyway, I gave you code in php since you posted this in the php code section. If you need to translate this to Javascript, someone with a broader background will need to help further.

Teenager
04-20-2009, 11:11 AM
Javascript it is. see, thats how dumb i am. :)

i've had a fiddle with the code, and entered what you suggested (i changed it to javascript though)

GiftShipping = (Number(Q6.value) * 15) + (Number(Q7.value) * 21) + (Number(Q8.value) * 21);
BotQuantity = Number(Q1.value) + Number(Q2.value) + Number(Q3.value) + Number(Q4.value) + Number(Q5.value);
fShipping = (BotQuantity * 2.30);
if (BotQuantity > 18) {
fShipping = (BotQuantity * 1.40);
if (BotQuantity > 48) {
fShipping = (BotQuantity * 1.00);
if (BotQuantity >= 96) {
fShipping = (BotQuantity * 0.70);
if (BotQuantity > 1) AND (GiftShipping > 1) {
totboxes = (Q6 + Q7 + Q8);
discount = (totboxes * 6);
GiftShipping = (GiftShipping - discount);
}

}
}
}
fShipping = fShipping + GiftShipping;


still doesn't seem to work.

anyone help???

bradgrafelman
04-20-2009, 04:53 PM
Moved to ClientSide Technologies forum.

Also note that since client-side languages can easily be bypassed and/or manipulated, you should also be doing all of these calculations on the server-side application to verify that the submitted values match up.