P
P
pareshok2019-06-18 14:50:09
1C-Bitrix
pareshok, 2019-06-18 14:50:09

Why are the custom fields in sale.order.ajax not populated?

A question. For some reason, the automatic completion of user properties in sage.order.ajax does not work. In the administrative panel, in the properties of the order, it is indicated: use as e-mail, etc. There is data in the profile, the component template is standard. But the data is not filled in, moreover, an inscription is displayed: we have filled in your fields. Maybe I forgot to specify something else in the settings?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Prilepa, 2019-06-20
@pareshok

As far as I understand, it doesn’t work like that out of the box, but you can solve it with an event handler in /bitrix/php_interface/init.php

<?php
AddEventHandler("sale", "OnSaleComponentOrderResultPrepared", ['\SaleEvents', "OnSaleComponentOrderResultPrepared"]);
class SaleEvents {
  public static function OnSaleComponentOrderResultPrepared($order, &$user_result, $request, &$params, &$result)
  {
    /**@global \CUser $USER */
    global $USER;
    if ($USER->IsAuthorized()
      && ($user_info = \Bitrix\Main\UserTable::getList([
        'filter' => [
          '=ID' => $USER->GetID(),
        ],
        'select' => [
          'EMAIL',
          'NAME',
          'LAST_NAME',
          'SECOND_NAME',
          'PERSONAL_PHONE',
        ],
      ])->fetch())
    ) {
      foreach($result['JS_DATA']['ORDER_PROP']['properties'] as &$prop) {
        if (!empty(reset($prop['VALUE']))) {
          continue;
        }
        switch($prop['CODE']) {
          case 'EMAIL':
            $prop['VALUE'] = [$user_info['EMAIL']];
            break;
          case 'FIO':
            $name_parts = [];
            foreach([
              'LAST_NAME',
              'NAME',
              'SECOND_NAME',
                ] as $name_key) {
              if (empty($user_info[$name_key])) {
                continue;
              }
              $name_parts[] = $user_info[$name_key];
            }
            $prop['VALUE'] = [
              implode(' ', $name_parts)
            ];
            break;
          case 'PHONE':
            $prop['VALUE'] = [$user_info['PERSONAL_PHONE']];
            break;
        }
      }
      unset($prop);
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question