J
J
jenny_sunny2017-09-21 22:10:57
1C-Bitrix
jenny_sunny, 2017-09-21 22:10:57

Display user data from personal account when placing an order in Bitrix?

Hello!
There is a site on 1C-Bitrix.
A person adds a product to the cart, if the user is authorized, then proceeds to checkout.
When placing an order, you need to display the user's data from your personal account, that is, his name, phone number, so that the user does not need to fill out.
How can I do that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sidorov, 2017-09-29
@serjazz

If the user is authorized, then the global variable $USER is filled in, which contains his authorization data, i.e. do:

global $USER; 
echo '<pre>';
print_r($USER):
echo '</pre>';

and after that it returns an object with the following fields
to you. with all the information that is in the profile.
I understand that you need this when you first purchase a user, because. if you use the standard components of Bitrix for ordering, the buyer's profile will be saved and in the future all data will be substituted automatically if the user is authorized.

D
DennisPetrov, 2019-08-01
@DennisPetrov

The task is solved in several different ways, for example, when registering a user, immediately create a buyer profile and fill it with values ​​from the main profile. You can read about it here
. You can also fill in the values ​​in result_modifier.php, I settled on this approach as a result, though I can’t say that it is optimal.
In result_modifier.php sale.order.ajax we get the data of the current user, then we pass it to the object used in js. In my case, it was convenient to do this in a loop, since there are a lot of properties. Previously, I set the symbolic codes of the order properties to be the same as those of the corresponding properties from the user profile (for example, in the profile for the "legal address" field, the code is UF_LEGAL_ADDRESS, respectively, in the order properties, the symbolic code of this property was made the same)

$currentUser = CUser::GetByID($USER->GetParam('USER_ID'));
$arUser = $currentUser->Fetch();
foreach ($arResult["JS_DATA"]["ORDER_PROP"]['properties'] as $propKey => $propItem) {
  if (array_key_exists($propItem["CODE"], $arUser)
   && !empty($arUser[$propItem["CODE"]]) 
   && empty($propItem["VALUE"][0]) ) {
    $arResult["JS_DATA"]["ORDER_PROP"]['properties'][$propKey]["VALUE"][0] = $arUser[$propItem["CODE"]];
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question