A
A
Andrey_Mirov2019-03-22 15:30:30
1C-Bitrix
Andrey_Mirov, 2019-03-22 15:30:30

How to display the price for a specific group of users in Bitrix?

Hello. Tell me, please, I'm already exhausted.
The user belongs to group 8(Wholesalers)
I need to display a different price for them

global $USER;
$arPrice = CCatalogProduct::GetOptimalPrice(6, 1, $USER->GetUserGroupArray(), "N");

Instead, Bitrix displays the total price, because it says that the user belongs to group 2, which is also known as All users, including unauthorized ones!
What to do(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Luchnikov, 2019-03-22
@lu4nik

Read the description of the CCatalogProduct::GetOptimalPrice method more carefully.
And then the description of the arUserGroups parameter:

An array of user groups. If it is empty, then the groups of the current user will be taken (provided that the $USER global variable of the CUser class exists, if not, the group with code 2 will be used).
If user groups are passed in the call, they will be forcibly added with a group code of 2 (All Users) if it does not exist.

Those. in any case, this method will process user group 2, and if the price for it is optimal (for example, taking into account some discounts), then it will return it.
Most likely you have a separate price type for the "Wholesales" user group, so you can get the price like this:
\Bitrix\Main\Loader::includeModule('catalog');

$price = \Bitrix\Catalog\PriceTable::query()
    ->setSelect(['*'])
    ->setFilter([
        '=PRODUCT_ID' => 123456,
        '=CATALOG_GROUP_ID' => 7,
    ])
    ->exec()
    ->fetch();

print_r($price);

where in CATALOG_GROUP_ID pass the previously calculated price type for the current user group.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question