P
P
Prog-Time2021-06-10 13:02:54
1C-Bitrix
Prog-Time, 2021-06-10 13:02:54

How to read D7 Bitrix objects?

I am using the following code to get product information

$orderId = 396;
$order = Sale\Order::load($orderId);
$test = $order->getTradeBindingCollection();

if($USER->IsAdmin()) {
    echo '<pre>'; 
    var_dump($test); 
    echo '</pre>';
}


I am getting the following code

object(Bitrix\Sale\TradeBindingCollection)#555 (5) {
  ["order":protected]=>
  object(Bitrix\Sale\Order)#545 (19) {
    ["shipmentCollection":protected]=>
    NULL
    ["paymentCollection":protected]=>
    NULL
    ["tradeBindingCollection":protected]=>
    *RECURSION*
    ["printedChecks":protected]=>
    array(0) {
    }
    ["calculatedFields":protected]=>
    object(Bitrix\Sale\Internals\Fields)#213 (5) {
      ["values":protected]=>
      array(0) {
      }
      ["changedValues":protected]=>
      array(0) {
      }
      ["originalValues":"Bitrix\Sale\Internals\Fields":private]=>
      array(0) {
      }
      ["customFields":"Bitrix\Sale\Internals\Fields":private]=>
      array(0) {
      }
      ["isClone":protected]=>
      bool(false)
    }
    ["basketCollection":protected]=>
    NULL
    ["propertyCollection":protected]=>
    NULL
    ["discount":protected]=>
    NULL
    ["tax":protected]=>
    NULL
    ["internalId":protected]=>
    int(0)
    ["isNew":protected]=>
    bool(false)
    ["isSaveExecuting":protected]=>
    bool(false)
    ["isClone":protected]=>
    bool(false)
    ["isOnlyMathAction":protected]=>
    NULL
    ["isMeaningfulField":protected]=>
    bool(false)
    ["isStartField":protected]=>
    NULL
    ["calculateType":protected]=>
    string(1) "C"
    ["fields":protected]=>
    object(Bitrix\Sale\Internals\Fields)#544 (5) {
      ["values":protected]=>
      array(69) {
        ["ID"]=>
        string(3) "396"
        ["LID"]=>
        string(2) "s1"
        ["ACCOUNT_NUMBER"]=>
        string(4) "3329"
        ["TRACKING_NUMBER"]=>
        NULL
        ["PAY_SYSTEM_ID"]=>
        string(1) "1"
        ["DELIVERY_ID"]=>
        string(1) "1"
        ["DATE_INSERT"]=>
        object(Bitrix\Main\Type\DateTime)#554 (1) {
          ["value":protected]=>
          object(DateTime)#553 (3) {
            ["date"]=>
            string(26) "2021-06-07 19:39:00.000000"
            ["timezone_type"]=>
            int(3)
            ["timezone"]=>
            string(3) "UTC"
          }
        }
        ["DATE_UPDATE"]=>
        object(Bitrix\Main\Type\DateTime)#552 (1) {
          ["value":protected]=>
          object(DateTime)#551 (3) {
            ["date"]=>
            string(26) "2021-06-07 19:39:00.000000"
            ["timezone_type"]=>
            int(3)
            ["timezone"]=>
            string(3) "UTC"
          }
        }
        ["PERSON_TYPE_ID"]=>
        string(1) "1"
        ["USER_ID"]=>
        string(3) "106"
        ["PAYED"]=>
        string(1) "N"
        ["IS_SYNC_B24"]=>
        string(1) "N"
        ["DATE_PAYED"]=>
        NULL
        ["EMP_PAYED_ID"]=>
        NULL
        ["DEDUCTED"]=>
        string(1) "N"
        ["DATE_DEDUCTED"]=>
        NULL
        ["EMP_DEDUCTED_ID"]=>
        NULL
        ["REASON_UNDO_DEDUCTED"]=>
        NULL
        ["STATUS_ID"]=>
        string(1) "N"
        ["DATE_STATUS"]=>
        object(Bitrix\Main\Type\DateTime)#550 (1) {
          ["value":protected]=>
          object(DateTime)#549 (3) {
            ["date"]=>
            string(26) "2021-06-07 19:39:00.000000"
            ["timezone_type"]=>
            int(3)
            ["timezone"]=>
            string(3) "UTC"
          }
        }
        ["EMP_STATUS_ID"]=>
        NULL
        ["MARKED"]=>
        string(1) "N"
        ["DATE_MARKED"]=>
        NULL
        ["EMP_MARKED_ID"]=>
        NULL
        ["REASON_MARKED"]=>
        NULL
        ["PRICE_DELIVERY"]=>
        float(0)
        ["ALLOW_DELIVERY"]=>
        string(1) "N"
        ["DATE_ALLOW_DELIVERY"]=>
        NULL
        ["EMP_ALLOW_DELIVERY_ID"]=>
        NULL
        ["RESERVED"]=>
        string(1) "N"
        ["PRICE"]=>
        float(8800)
        ["CURRENCY"]=>
        string(3) "RUB"
        ["DISCOUNT_VALUE"]=>
        float(0)
        ["TAX_VALUE"]=>
        string(7) "1466.67"
        ["SUM_PAID"]=>
        float(0)
        ["USER_DESCRIPTION"]=>
        string(132) "Адрес доставки
Тульская область. Ленинский район. Посёлок Иншинский д63

"
        ["PAY_VOUCHER_NUM"]=>
        NULL
        ["PAY_VOUCHER_DATE"]=>
        NULL
        ["ADDITIONAL_INFO"]=>
        NULL
        ["COMMENTS"]=>
        NULL
        ["COMPANY_ID"]=>
        NULL
        ["CREATED_BY"]=>
        NULL
        ["RESPONSIBLE_ID"]=>
        NULL
        ["STAT_GID"]=>
        NULL
        ["DATE_PAY_BEFORE"]=>
        NULL
        ["DATE_BILL"]=>
        NULL
        ["IS_RECURRING"]=>
        string(1) "N"
        ["RECURRING_ID"]=>
        NULL
        ["LOCKED_BY"]=>
        string(2) "47"
        ["DATE_LOCK"]=>
        object(Bitrix\Main\Type\DateTime)#548 (1) {
          ["value":protected]=>
          object(DateTime)#547 (3) {
            ["date"]=>
            string(26) "2021-06-10 08:44:00.000000"
            ["timezone_type"]=>
            int(3)
            ["timezone"]=>
            string(3) "UTC"
          }
        }
        ["RECOUNT_FLAG"]=>
        string(1) "Y"
        ["AFFILIATE_ID"]=>
        NULL
        ["DELIVERY_DOC_NUM"]=>
        NULL
        ["DELIVERY_DOC_DATE"]=>
        NULL
        ["UPDATED_1C"]=>
        string(1) "N"
        ["ORDER_TOPIC"]=>
        NULL
        ["XML_ID"]=>
        string(18) "YAMARKET_2_8562141"
        ["ID_1C"]=>
        NULL
        ["VERSION_1C"]=>
        NULL
        ["VERSION"]=>
        string(1) "0"
        ["EXTERNAL_ORDER"]=>
        string(1) "N"
        ["STORE_ID"]=>
        NULL
        ["CANCELED"]=>
        string(1) "N"
        ["EMP_CANCELED_ID"]=>
        NULL
        ["DATE_CANCELED"]=>
        NULL
        ["REASON_CANCELED"]=>
        NULL
        ["BX_USER_ID"]=>
        NULL
        ["SEARCH_CONTENT"]=>
        NULL
        ["RUNNING"]=>
        string(1) "N"
      }
      ["changedValues":protected]=>
      array(0) {
      }
      ["originalValues":"Bitrix\Sale\Internals\Fields":private]=>
      array(0) {
      }
      ["customFields":"Bitrix\Sale\Internals\Fields":private]=>
      array(0) {
      }
      ["isClone":protected]=>
      bool(false)
    }
    ["eventName":protected]=>
    NULL
  }
  ["index":"Bitrix\Sale\Internals\EntityCollection":private]=>
  int(0)
  ["isClone":protected]=>
  bool(false)
  ["anyItemDeleted":protected]=>
  bool(false)
  ["collection":protected]=>
  array(1) {
    [0]=>
    object(Bitrix\Sale\TradeBindingEntity)#462 (6) {
      ["tradePlatform":"Bitrix\Sale\TradeBindingEntity":private]=>
      NULL
      ["collection":protected]=>
      *RECURSION*
      ["internalIndex":protected]=>
      int(0)
      ["isClone":protected]=>
      bool(false)
      ["fields":protected]=>
      object(Bitrix\Sale\Internals\Fields)#465 (5) {
        ["values":protected]=>
        array(6) {
          ["ID"]=>
          string(2) "12"
          ["ORDER_ID"]=>
          string(3) "396"
          ["EXTERNAL_ORDER_ID"]=>
          string(7) "8562141"
          ["PARAMS"]=>
          bool(false)
          ["TRADING_PLATFORM_ID"]=>
          string(1) "2"
          ["XML_ID"]=>
          string(16) "bx_60be75d48d3e7"
        }
        ["changedValues":protected]=>
        array(0) {
        }
        ["originalValues":"Bitrix\Sale\Internals\Fields":private]=>
        array(0) {
        }
        ["customFields":"Bitrix\Sale\Internals\Fields":private]=>
        array(0) {
        }
        ["isClone":protected]=>
        bool(false)
      }
      ["eventName":protected]=>
      NULL
    }
  }
}


How can I get the TRADING_PLATFORM_ID ?
How to read such objects in general? Can they be represented as simple arrays or simple objects?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2021-06-10
@winer

How can I get the TRADING_PLATFORM_ID ?

$tradeBindingCollection = $order->getTradeBindingCollection();

/** @var Bitrix\Sale\TradeBindingEntity $item */
foreach ($tradeBindingCollection as $item) {
    $tpId = $item->getField('TRADING_PLATFORM_ID');
}

How to read such objects in general?

In a dump which you resulted types of objects are specified.
For example $order->getTradeBindingCollection(); returns the Bitrix\Sale\TradeBindingCollection
collection. Like other Bitrix collections, it has the implementation of the \ArrayAccess, \Countable, \IteratorAggregate interfaces
. Therefore, it can be passed through the foreach loop.
In turn, each object inside the collection is an object of the Bitrix\Sale\TradeBindingEntity class, which is also visible from the dump. This class inherits from Internals\Entity, which has methods for getting the fields stored in the values ​​field.
In order to understand, you need to look at the documentation or source codes. I recommend looking at the source codes through the IDE (not in notePad ++), for easy navigation and ease of work.
In principle, all this comes with experience.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question