A
A
alexwprof2019-09-17 14:51:33
1C-Bitrix
alexwprof, 2019-09-17 14:51:33

How to work with Bitrix CCatalogDiscount::GetList method correctly?

You need to get the values ​​of discounts for goods on the main page in the sliders. In the product card sliders.
I found the CCatalogDiscount::GetList method in the documentation, I can’t figure out how to work with it correctly. It returns the fields I need: NAME - the name of the discount, VALUE - the amount of the discount, and others.
There is already a ready-made code through which the goods are received in the slider by the property:

<?
if(CModule::IncludeModule("iblock")){

$arSelect = Array(
    "ID",
    "IBLOCK_ID",
    "DETAIL_PAGE_URL",
    "NAME", "PREVIEW_PICTURE",
    "PREVIEW_TEXT",
    "DATE_ACTIVE_FROM",
    "CATALOG_GROUP_1",
    
    
);
 $arrFilterMain["PROPERTY_CATMAIN_PROD_VALUE"] = "выгодные комплекты";
 $res = CIBlockElement::GetList(
    Array(),
    $arrFilterMain,
    false,
    Array("nPageSize"=>50),
    $arSelect
);
 
while($ob = $res->GetNextElement()) {


    $arFields = $ob->GetFields();
    $arProps = $ob->GetProperties();

//debug($arProps);
}
}

It is necessary to somehow add getting discounts here
. By itself, the CCatalogDiscount::GetList method does not work. On a separate test page, I try to get discounts on one specific product, it returns nothing.
<?
// Выберем все скидки для данного товара

$dbProductDiscounts = CCatalogDiscount::GetList(
    array("SORT" => "ASC"),
    array(
            "+PRODUCT_ID" => 64,
            "ACTIVE" => "Y",
            "!>ACTIVE_FROM" => $DB->FormatDate(date("Y-m-d H:i:s"), 
                                               "YYYY-MM-DD HH:MI:SS",
                                               CSite::GetDateFormat("FULL")),
            "!<ACTIVE_TO" => $DB->FormatDate(date("Y-m-d H:i:s"), 
                                             "YYYY-MM-DD HH:MI:SS", 
                                             CSite::GetDateFormat("FULL")),
            "COUPON" => ""
        ),
    false,
    false,
    array(
            "ID", "SITE_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", 
            "RENEWAL", "NAME", "SORT", "MAX_DISCOUNT", "VALUE_TYPE", 
    "VALUE", "CURRENCY", "PRODUCT_ID"
        )
    );
while ($arProductDiscounts = $dbProductDiscounts->Fetch())
{
  print_r = $arProductDiscounts;
}
?>

Instead of $PRODUCT_ID I substitute the product id 64. Maybe I'm doing something wrong?
Or is there another way to solve my problem
. There is an array in the catalog, this is an array from the product card:
[PRICES] => Array
        (
            [price_type] => Array
                (
                    [PRICE_ID] => 1
                    [ID] => 13
                    [CAN_ACCESS] => Y
                    [CAN_BUY] => Y
                    [MIN_PRICE] => Y
                    [CURRENCY] => RUB
                    [VALUE_VAT] => 6900
                    [VALUE_NOVAT] => 6900
                    [DISCOUNT_VALUE_VAT] => 6865
                    [DISCOUNT_VALUE_NOVAT] => 6865
                    [ROUND_VALUE_VAT] => 6865
                    [ROUND_VALUE_NOVAT] => 6865
                    [VALUE] => 6900
                    [UNROUND_DISCOUNT_VALUE] => 6865
                    [DISCOUNT_VALUE] => 6865
                    [DISCOUNT_DIFF] => 35
                    [DISCOUNT_DIFF_PERCENT] => 1
                    [VATRATE_VALUE] => 0
                    [DISCOUNT_VATRATE_VALUE] => 0
                    [ROUND_VATRATE_VALUE] => 0
                    [PRINT_VALUE_NOVAT] => 6 900 руб.
                    [PRINT_VALUE_VAT] => 6 900 руб.
                    [PRINT_VATRATE_VALUE] => 0 руб.
                    [PRINT_DISCOUNT_VALUE_NOVAT] => 6 865 руб.
                    [PRINT_DISCOUNT_VALUE_VAT] => 6 865 руб.
                    [PRINT_DISCOUNT_VATRATE_VALUE] => 0 руб.
                    [PRINT_VALUE] => 6 900 руб.
                    [PRINT_DISCOUNT_VALUE] => 6 865 руб.
                    [PRINT_DISCOUNT_DIFF] => 35 руб.
                )

It would be ideal to get fields from it, but it doesn't come out

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-09-17
@alexwprof

$arPrice = CCatalogProduct::GetOptimalPrice($productID);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question