PDA

View Full Version : Discount calculation improvements


radicaledward
03-15-2005, 01:28 AM
One of the big issues that I have had with the shop is that it didn't check secondary usergroups for discounts. Since members that donate to the site get a discount this is necessary on our board, and it has been necessary for me to write a fix for this issue. So to solve this problem I have written the following code - feel free to use it as you see fit. :)

In /includes/functions_uttstore.php:

Find in function calculate_discounted_price:
// Generate Usergroup Discount
if ($permissions['uttstore_discount'] != "0") {
$adiscountd = ($permissions['uttstore_discount'] / 100);
$adiscount = ($adiscountd * $price);
(isset($discount) ? $discount = ($discount - $adiscount) : $discount = ($price - $adiscount));
}
Replace with:
//------------------------------------------------------------------------
// Generate Discounts
//------------------------------------------------------------------------
// Get the list of groups and discounts
global $DB_site;
$groupdiscounts = $DB_site->query("SELECT usergroupid, uttstore_discount FROM usergroup WHERE uttstore_discount != '0'");
// Loop through the groups
if (!empty($groupdiscounts)) {
while ($groupdiscount = $DB_site->fetch_array($groupdiscounts)) {
// Check to see if the user is a member, if so then add the discount
if (is_member_of($bbuserinfo, $groupdiscount['usergroupid'])) {
$adiscountd += ($groupdiscount['uttstore_discount'] / 100);
}
}
}
// Determine the price
$adiscount = ($adiscountd * $price);
(isset($discount) ? $discount = ($discount - $adiscount) : $discount = ($price - $adiscount));
//------------------------------------------------------------------------
Find in function calculate_discount_percent:
// Generate Usergroup Discount
if ($permissions['uttstore_discount'] != "0") {
$adiscountd = ($permissions['uttstore_discount']);
(isset($discount) ? $discount = ($discount + $adiscountd) : $discount = ($price + $adiscountd));
}
Replace with:
//------------------------------------------------------------------------
// Generate Discount Percentage
//------------------------------------------------------------------------
// Get the list of groups and discounts
global $DB_site;
$groupdiscounts = $DB_site->query("SELECT usergroupid, uttstore_discount FROM usergroup WHERE uttstore_discount != '0'");
// Loop through the groups
if (!empty($groupdiscounts)) {
while ($groupdiscount = $DB_site->fetch_array($groupdiscounts)) {
// Check to see if the user is a member, if so then add the discount
if (is_member_of($bbuserinfo, $groupdiscount['usergroupid'])) {
$adiscountd += ($groupdiscount['uttstore_discount']);
}
}
}
// Determine the amount
(isset($discount) ? $discount = ($discount + $adiscountd) : $discount = ($price + $adiscountd));
//------------------------------------------------------------------------

Link14716
03-15-2005, 03:14 AM
This might be a better solution. Instead of all that, in includes/init.php, find:
'pmsendmax' => 0,
Add under:
'uttstore_discount' => 0,

It won't loop through each usergroup and add the discounts, but it will take the highest value instead.

radicaledward
03-15-2005, 04:29 AM
I thought of doing that, but our site is a bit unique in that we make extensive use of secondary groups for members. For example, my account has the following group memberships:

Administrators: 0% discount
Senior Members (been on the site for a long time): 5% discount
Friends of ACF (people that donated money to the site): 10% discount
Loyal member discount (registered on site for 365 days): 5% discount

Since the members were complaining about not getting all of the discounts this was judged to be the best course of action, as opposed to telling them that the highest discount is the total discount.