View Full Version : Discount on total quantity
SteveMac
08-Dec-2003, 09:29 AM
Need to calculate a discount based on total quantity purchased, but my perl skills are not that good.
I know that the change needs to go into AdjustmentTemplate.pl and I can do most of the required changes. However I cannot work out how to pull in the running quatity total variable (CartItem) that appears at the top of the cart pages.
Have taken this over from MTD, who could not resolve it.
Can anyone give me a pointer?
Many thanks.:confused:
Hi Steve
Is it the number of items in the cart you want to base the discount on, or the total value of items in the cart? If it's the value, you can set the discounts in the UI under View | Discounts.
Ben
SteveMac
09-Dec-2003, 03:17 PM
Ben
It is the total quatity that I need. I know how to discount against the total value.
I am implementing an online wine sales system. I need to offer a discount once the total number of bottles exceeds 12 (i.e. a case).
I just need to be able to call in the Cart Item variable (into AdjustmentTemplate.pl) that is displayed at the top of the page.
Thanks in anticipation.
Regards Steve
Ok, I'll ask development to have a look at this.
SteveMac
09-Dec-2003, 04:09 PM
Thanks Ben.
zmagyar
09-Dec-2003, 06:16 PM
Hmmm... It doesn't look like a simple issue what we can do within the frame of support. Anyway I'm going to check and post at least some pointers.However I cannot work out how to pull in the running quatity total variable It is Cart::CountQuantities()
Regards,
zmagyar
09-Dec-2003, 07:11 PM
Ok, lets try the following code. Just add it to the end of AdjustmentTemplate.pl above the return statement.
#
# Get a reference of the cart object first
#
my @Response = $::Session->GetCartObject();
if ($Response[0] != $::SUCCESS) # general error
{
return($::SUCCESS, '', \@arrAdjustments);
}
my $pCartObject = $Response[2];
my $pCartList = $pCartObject->GetCartList();
#
# Get the total item count from the cart
#
my $nCount = $pCartObject->CountQuantities();
#
# Now set up the quantity discount
#
my $nLimit = 3;
my $nAdjustment = -2500 * int($nCount/$nLimit);
my $sCaption = "The discount name in the cart";
#
# And check if this qualifies
#
if ($nCount >= $nLimit &&
scalar(@$parrOrderTotals) == 2)
{
my @arrAdjustment =
($sCaption,
$nAdjustment,
$::eAdjTaxProRataAdjusted,
"",
0);
push @arrAdjustments, \@arrAdjustment;
}
return($::SUCCESS, '', \@arrAdjustments);Obviously you can customise this. Try to edit the followings:
$nLimit to change the triggering quantity. Actually the discount is triggered if there are 3 items in the cart. You can change the number 3 to whatever you wish (e.g. 12 :)).
$nAdjustment to change the discount value. Actually this adds 25GBP discount to the cart for each 3 items. If you wish to have only one discount above the triggering quantity (and not for each 3) then remove the *int(...) part of that line. Percentage discounts can also be created just let me know if you require details about this.
$sCaption to customise the text which appears in the cart as discount description.
I hope this helps. Enjoy.
SteveMac
10-Dec-2003, 07:00 PM
zmagyar
You are a star!
The code was not exactly what I needed, but it opened the door and provided the template.
The site now offers two levels of discount. 2.5% on 6 -11 bottles. 5% on 12 or more bottles.
Thanks for your help.
Regards Steve
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.