Answer the question
In order to leave comments, you need to log in
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
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>';
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 questionAsk a Question
731 491 924 answers to any question