Example #1
0
/**
 * Determine the group based price for a particular product.
 *
 * note: product level > category level > storewide
 *
 * @param array Array of information for the product.
 * @param string The price we want to fetch the adjusted value for.
 * @param int The group id to fetch the pricing for. If none specified, the current customers group is used.
 */
function CalcProdCustomerGroupPrice($product, $price, $groupId=null)
{

	// If the group is not passed, get the group for the current customer
	$GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER');
	if($groupId === null && !defined('ISC_ADMIN_CP')) {
		$group = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerGroup();
	}
	else {
		$group = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerGroup($groupId);
	}

	// If here isn't a customer group then we just return the price we already had
	if(!is_array($group)) {
		return $price;
	}

	// ISC-708: attempt to retrieve product level group discount (now that group id is known)
	if (!isset($product['prodgroupdiscount']) || $product['prodgroupdiscount'] == 0) {
		$query = "
			SELECT p.*, ".GetProdCustomerGroupPriceSQL($group['customergroupid'])."
			FROM [|PREFIX|]products p
			WHERE p.productid='".(int)$product['productid']."'
		";
		$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
		$product = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
	}

	// Does this product have a custom price?
	if(isset($product['prodgroupdiscount']) && $product['prodgroupdiscount'] > 0) {
		return CalculateDiscount($price,$product['discountmethod'], $product['prodgroupdiscount']);
	}

	// Do we have a group price for any of the categories this product is in?
	$categories = explode(',', $product['prodcatids']);
	$discountPrice = $price;

	foreach($categories as $category) {
		$catDiscount = GetGroupCategoryDiscount($group['customergroupid'], $category);

		if(isset($catDiscount['discountAmount'])) {
			$currentDiscountPrice = CalculateDiscount($price, $catDiscount['discountMethod'], $catDiscount['discountAmount']);

			//get the lowest discount for the product
			$discountPrice = min($discountPrice, $currentDiscountPrice);
		}
	}

	if($discountPrice < $price) {
		return $discountPrice;
	}

	// Otherwise, if the group has a default discount then we use it
	if($group['discount'] > 0) {
		$discountPrice = CalculateDiscount($price, $group['discountmethod'], $group['discount']);

		return $discountPrice;
	}

	return $price;
}
Example #2
0
/**
 * Determine the group based price for a particular product.
 *
 * @param array Array of information for the product.
 * @param string The price we want to fetch the adjusted value for.
 * @param int The group id to fetch the pricing for. If none specified, the current customers group is used.
 */
function CalcProdCustomerGroupPrice($product, $price, $groupId = null)
{
    // If the group is not passed, get the group for the current customer
    $GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER');
    if ($groupId === null && !defined('ISC_ADMIN_CP')) {
        $group = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerGroup();
    } else {
        if ($groupId === 0) {
            return $price;
        } else {
            $group = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerGroup($groupId);
        }
    }
    // If here isn't a customer group then we just return the price we already had
    if (!is_array($group)) {
        return $price;
    }
    // Does this product have a custom price?
    if (isset($product['prodgroupdiscount']) && $product['prodgroupdiscount'] > 0) {
        return CalculateDiscount($price, $product['discountmethod'], $product['prodgroupdiscount']);
    }
    // Do we have a group price for any of the categories this product is in?
    $categories = explode(',', $product['prodcatids']);
    $discountPrice = 0;
    foreach ($categories as $category) {
        $catDiscount = GetGroupCategoryDiscount($group['customergroupid'], $category);
        if (isset($catDiscount['discountAmount'])) {
            $currentDiscountPrice = CalculateDiscount($price, $catDiscount['discountMethod'], $catDiscount['discountAmount']);
            //get the lowest discount for the product
            if ($discountPrice != 0) {
                $discountPrice = min($discountPrice, $currentDiscountPrice);
            } else {
                $discountPrice = $currentDiscountPrice;
            }
        }
    }
    if ($discountPrice > 0) {
        return $discountPrice;
    }
    // Otherwise, if the group has a default discount then we use it
    if ($group['discount'] > 0) {
        //	$price -= $price * ($group['discount'] / 100);
        $price = CalculateDiscount($price, $group['discountmethod'], $group['discount']);
        return $price;
    }
    return $price;
}