You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
I need to apply the 'Total of X Save Y' discount to one category of products. Now that I've altered the code, how do I actually apply it to a category so that the discount takes affect?
$sale_pct = "20";
$total_needed = "81.00";
if ($tracking_subtotal >= "$total_needed") {
$sale_pct_calc = ($sale_pct / 100);
$tracking_saletotal = ($tracking_subtotal * $sale_pct_calc);
$tracking_saletotal = sprintf("%.2f", $tracking_saletotal);
$tracking_saledesc = "Spend $currency_symbol$total_needed Or More - Save $sale_pct\%";
} ######### End of if statement.
Offline
On the above codes, you need to apply an if statement with a category_id_encoded then equal it with your $tracking_subtotal.
Offline
I'm a CCP newbie and not a programming whiz either. My category reference string is CCM. Where/How do I insert this if/then statement? Thanks!
Offline
Try this:
$sale_pct = "20"; $total_needed = "81.00"; $category_total = "0.00"; $sql_statement = " SELECT cart_amtprod,cart_cat FROM cart "; @cat = database_call('cart','SELECT',$sql_statement); foreach $row(@cat) { ($cart_amtprod,$cart_cat) = @$row; if ($cart_cat eq "YOUR_CAT_STRING_HERE") { $category_total = ($category_total + $cart_amtprod); } ######### End of if statement. } ######### End of foreach statement. if ($category_total >= "$total_needed") { $sale_pct_calc = ($sale_pct / 100); $tracking_saletotal = ($category_total * $sale_pct_calc); $tracking_saletotal = sprintf("%.2f", $tracking_saletotal); $tracking_saledesc = "Spend $currency_symbol$total_needed Or More - Save $sale_pct\%"; } ######### End of if statement.
Offline
Thanks! I tried this, but it still doesn't seem to be working. I add over $81.00 to the cart and then check out, but the price doesn't drop.
The only thing I changed is "YOUR_CAT_STRING_HERE" to "CCM" (which is the category's reference string). Do I need to change anything else? Thanks.
Offline
In this case, replace
this line :
if ($cart_cat eq "YOUR_CAT_STRING_HERE") {
with this line :
Offline
Thanks. I tried this, but something is still off and it isn't working. Do I need to make any changes to the category itself? Or the products within the category?
Offline
In this case,
replace this :
if ($cart_cat eq "YOUR_CAT_STRING_HERE") {
with this :
Offline
(Thanks) Any combination of 36 ceramic coffee mugs should drop the price of each mug to $2.00 per mug. Since 36 x 2.25 = $81.00, once they reach this amount, the 20% discount should kick in, dropping the price to $72.00.
I'm realizing that I figured the math incorrectly also, but that's not the point. All I need to do is drop the price by .25 for each mug AFTER 36 have been added to the cart. I'm now thinking that maybe I should be using the Total of X Save Y Amount discount instead of this one. Anyhoo, here's what I've got for this one.
#########
######### This custom script calculates a sale
######### at checkout based on the contents of
######### the user's shopping cart when they enter
######### checkout.
#########
######### A listing of available variables:
#########
######### $cart_quantity_found Total quantity of items
######### $tracking_subtotal Subtotal for all items
#########
######### This script sets X percent off on purchases of
######### Y amount or more.
#########
$sale_pct = "20";
$total_needed = "81.00";
$category_total = "0.00";
$sql_statement = "
SELECT cart_amtprod,cart_cat
FROM cart
";
@cat = database_call('cart','SELECT',$sql_statement);
foreach $row(@cat) {
($cart_amtprod,$cart_cat) = @$row;
if ($cart_cat eq "CCM") {
$category_total = ($category_total + $cart_amtprod);
} ######### End of if statement.
} ######### End of foreach statement.
if ($category_total >= "$total_needed") {
$sale_pct_calc = ($sale_pct / 100);
$tracking_saletotal = ($category_total * $sale_pct_calc);
$tracking_saletotal = sprintf("%.2f", $tracking_saletotal);
$tracking_saledesc = "Spend $currency_symbol$total_needed Or More - Save $sale_pct\%";
} ######### End of if statement.
Offline
Hi, How would I implement this with amount rather than %?
Thanks
John
Offline
Follow the example given in the sample provided with the program. You'll find it under Orders & Payment -> Manage Custom Sale Methods -> Buy X Items Save Y Amount. You can modify that one to suit or make a new one using that as a guide.
Offline
Thanks Rachael,
Its a category based one; I'm trying to implement an offer on a particular brand of spend £150 and get £17 discount and spend £300 and get £40 discount. It is related to 9 products which I have placed into one brand category for this purpose.
Do you know what code I would have to implement for that? The example in this topic is % based but I need it on Amount and cant get my head around it.
Any help appreciated, I have looed around the forums but they all seem to be % related.
Thanks
John
Offline
If you just want it to deduct a specific amount, instead of a percentage, then just remove the percentage calculation and replace it with a fixed number. In other words, take this line:
$tracking_saletotal = ($category_total * $sale_pct_calc);
And replace it with something like:
$tracking_saletotal = 4.95;
Not a lot more to it than that, unless I'm misunderstanding something you're asking.
Offline
would that apply it to everything though, not just the products in the category?
and would I be able to apply both discounts in one script?
It just seems rather brief compared to the one for % as below
if ($category_total >= "$total_needed") {
$sale_pct_calc = ($sale_pct / 100);
$tracking_saletotal = ($category_total * $sale_pct_calc);
$tracking_saletotal = sprintf("%.2f", $tracking_saletotal);
$tracking_saledesc = "Spend $currency_symbol$total_needed Or More - Save $sale_pct\%";
Thanks
John
Last edited by juiceland (07-03-2009 05:44:17)
Offline
I was not abbreviating the script, only changing the one line where it calculates the discount. The rest of the script that figures out which products are in the right category would remain the same, I think. As for applying another discount to the rest of the products, that could certainly be done, but it would take a bit more programming. If you need professional help with it, Stephen at cartmod.com would be able to help.
Offline
Okay, I was just a little confused as there were 2 other lines with "pct" in it
$sale_pct_calc = ($sale_pct / 100);
$tracking_saledesc = "Spend $currency_symbol$total_needed Or More - Save $sale_pct\%";
Thanks for your help Rachael, I'll probably email Cartmod.
John
Offline
You can just change the one line from a multiplication to a fixed assignment, like I demonstrated above, if you just want to change from percentage to a fixed amount. If you need something more involved than that though, probably best to look for a quote.
Offline