J
J
Jupiter Max2018-12-09 14:20:42
1C-Bitrix
Jupiter Max, 2018-12-09 14:20:42

How to display a list of users who have items in their cart?

What I do:
Get a list of users I need by their ID
Get a list of products in the basket of selected users through FUSER_ID
What you need:
Let's just say, you need to build such a layout. There are lines with user data. Clicking on each opens a list with the products that he currently has in his cart.
Question
How to connect the obtained values ​​and build the layout described above.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2018-12-10
@winer

1) If you have Bitrix in the Business edition, then there is no need to reinvent the wheel. This page already exists in the admin panel. Shop -> Customers -> Baskets.
2) If, nevertheless, this is a small business editorial or you need to display all this in public, then:
List of buyers:

$users = \Bitrix\Sale\Internals\BasketTable::getList([
    "select" => [
        "USER_ID" => "FUSER.USER.ID",
        "USER_EMAIL" => "FUSER.USER.EMAIL",
    ],
    "filter" => [
        "!FUSER.USER_ID" => NULL,
        "ORDER_ID" => NULL,
    ],
    "group" => [
        "FUSER.USER.ID",
        "FUSER.USER.EMAIL"
    ]
])->fetchAll();

IMPORTANT clarification. This request will not display the baskets of unauthorized users, because nothing useful can be done with them anyway. If these baskets are still needed, then the request will look like this:
$users = \Bitrix\Sale\Internals\BasketTable::getList([
    "select" => [
        "FUSER_ID",
        "USER_ID" => "FUSER.USER.ID",
        "USER_EMAIL" => "FUSER.USER.EMAIL",
    ],
    "filter" => [
        "ORDER_ID" => NULL,
    ],
    "group" => [
        "FUSER_ID",
        "FUSER.USER.ID",
        "FUSER.USER.EMAIL"
    ]
])->fetchAll();

Shopping carts:
$fuserId = 44514;//ID покупателя !!!!!  НЕ пользователя
$basket = \Bitrix\Sale\Internals\BasketTable::getList([
    "select" => [
        "*"
    ],
    "filter" => [
        "FUSER_ID" => $fuserId,
        "ORDER_ID" => NULL,
    ],
])->fetchAll();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question