Documentation

GetDiscountByPrice

Description and parameters

bool
CCatalogDiscount::GetDiscountByPrice(
 int productPriceID[,
 array arUserGroups = array()[,
 string renewal = "N"[,
 string siteID = false[,
 array arDiscountCoupons = false]]]]
);

Method calculates discount with productPriceID for user as a member in groups arUserGroups. Non-static method.

Call parameters

ParameterDescriptionAvailable from version
productPriceID Price code.
arUserGroups Array with this user groups. For current user, its returned by the method $USER->GetUserGroupArray()
renewal "Subscription renewal" flag.
siteID Site (current by default).
arDiscountCoupons Array with coupons that affect discount selection. In case of false, array with coupons will be sourced from CCatalogDiscountCoupon::GetCoupons

Returned values

Method returns array with associative discount arrays or false otherwise. The array contains an associative array with parameters of max percentage rate (if available) and associative array with parameters of max fixed rate (if available).

Example

<?
$dbPrice = CPrice::GetList(
    array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", 
          "SORT" => "ASC"),
    array("PRODUCT_ID" => $ID),
    false,
    false,
    array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", 
          "QUANTITY_FROM", "QUANTITY_TO")
);
while ($arPrice = $dbPrice->Fetch())
{
    $arDiscounts = CCatalogDiscount::GetDiscountByPrice(
            $arPrice["ID"],
            $USER->GetUserGroupArray(),
            "N",
            SITE_ID
        );
    $discountPrice = CCatalogProduct::CountPriceWithDiscount(
            $arPrice["PRICE"],
            $arPrice["CURRENCY"],
            $arDiscounts
        );
    $arPrice["DISCOUNT_PRICE"] = $discountPrice;

    echo "<pre>&quot;;
    print_r($arPrice);
    echo &quot;</pre>";
}
?>

© «Bitrix24», 2001-2024
Up