E
E
EvgenyJozef30002019-06-16 10:26:47
PHP
EvgenyJozef3000, 2019-06-16 10:26:47

What is the best way to optimize the work of cycles with enumeration of goods from 1C-Bitrix infoblocks?

Good afternoon. There is the following code: https://pastebin.com/ia2Qw8bN
The essence of this code is to sort through the goods from 3 infoblocks [ELKO, Treolan and OCS], combine them into a single infoblock [Market].
In each of the cycles, we add a product if it is not in the system (line - 115), otherwise we update the properties of the product (line - 118), the code lines were provided for sorting through the products of the ELKO infoblock, the rest of the cycles are almost the same. Product properties are stored in the $arLoadProductArray variable.
Let's move on to my problem. Let's pay attention to the self-made searchElementArr function and the $articul and $search_id variables. They are used in the condition and the searchElementArr function. More specifically - I said earlier that on line 115 (for ELKO) we add products in case it is not in the system, to check this, we access the $search_id variable, which is a call to the searchElementArr function - it looks for the product id in the system Bitrix by the following parameters ("CODE_PROPERTIES_BY_WHICH_WE ARE_LOOKING FOR", "VALUE_PROPERTIES", "ARRAY_WHERE_WE ARE_LOOKING FOR"). In all cycles, the property code in which we are looking for is "65", the property value is the article, which changes depending on the cycle (infoblock), that is, the article is taken from one or another infoblock (which we sort through) and finally the array where we are looking for these articles, is $marketArr - a selection of all products from the Market infoblock. The request to select elements in my code occurs once (line - 52). At the same time, in each cycle, I am adding products and, in theory, I need to update the $marketArr array each time (make a request for a selection) in order to correctly search for articles in it (since we do not know data about newly added products, because the array is static) , but the problem is that with each request for a selection, a request is made to the database in order to get the treasured elements from the infoblock.
I solved this problem in the following way - since the $marketArr array is static, I update the array every time I add a product: c072b299c7.pngI add this product to the $marketArr array using the array_push function. Where is the condition that such an article was not found, I write down, as it were, a change in the product in the array: 929ac8b76d.pngwhere first I go through the $marketArr array, look for the element with the found product ID ($search_id variable), delete this product from the array (unset), write a new one goods into an array using the array_push function.
Array examples 2f568e642b.pngbelow:

Один из товаров в массиве ELKO
Array
(
    [IBLOCK_NAME] => ELKO
    [ID] => 512552
    [NAME] => Ноутбук X540MB PMD-N5000 15" 4GB 500GB X540MB-GQ079 ASUS
    [IBLOCK_SECTION_ID] => 10953
    [PROPERTY_22_VALUE] => 90NB0IQ1-M01110               
    [PROPERTY_22_VALUE_ID] => 10820458
    [PROPERTY_3_VALUE] => 
    [PROPERTY_3_VALUE_ID] => 
    [PROPERTY_31_VALUE] => 
    [PROPERTY_31_VALUE_ID] => 
    [PROPERTY_25_VALUE] => 23770
    [PROPERTY_25_VALUE_ID] => 10820460
    [PROPERTY_27_VALUE] => 2
    [PROPERTY_27_VALUE_ID] => 10820461
    [PROPERTY_19_VALUE] => 1266489
    [PROPERTY_19_VALUE_ID] => 10820455
    [PROPERTY_7_VALUE] => 
    [PROPERTY_7_VALUE_ID] => 
    [PROPERTY_1_VALUE] => 
    [PROPERTY_1_VALUE_ID] => 
    [PROPERTY_39_VALUE] => 
    [PROPERTY_39_VALUE_ID] => 
    [PROPERTY_30_VALUE] => 
    [PROPERTY_30_VALUE_ID] => 
    [PROPERTY_65_VALUE] => 
    [PROPERTY_65_VALUE_ID] => 
)

Один из товаров в массиве Treolan
Array
(
    [IBLOCK_NAME] => Treolan
    [ID] => 351947
    [NAME] => ASUS Vivobook XMAS X540MB-GQ079 Pentium N5000/4Gb/500Gb HDD/15.6"HD (1366x768)/NVIDIA GeForce MX110 2Gb/DVD-RW/WiFi/BT/Cam/ENDLESS/2Kg/Black
    [IBLOCK_SECTION_ID] => 11248
    [PROPERTY_22_VALUE] => 
    [PROPERTY_22_VALUE_ID] => 
    [PROPERTY_3_VALUE] => 90NB0IQ1-M01110
    [PROPERTY_3_VALUE_ID] => 7147014
    [PROPERTY_31_VALUE] => 
    [PROPERTY_31_VALUE_ID] => 
    [PROPERTY_25_VALUE] => 
    [PROPERTY_25_VALUE_ID] => 
    [PROPERTY_27_VALUE] => 
    [PROPERTY_27_VALUE_ID] => 
    [PROPERTY_19_VALUE] => 
    [PROPERTY_19_VALUE_ID] => 
    [PROPERTY_7_VALUE] => 24171.00
    [PROPERTY_7_VALUE_ID] => 7147018
    [PROPERTY_1_VALUE] => 053001/1894
    [PROPERTY_1_VALUE_ID] => 7147012
    [PROPERTY_39_VALUE] => 
    [PROPERTY_39_VALUE_ID] => 
    [PROPERTY_30_VALUE] => 
    [PROPERTY_30_VALUE_ID] => 
    [PROPERTY_65_VALUE] => 
    [PROPERTY_65_VALUE_ID] => 
)

Один из товаров в массиве OCS
Array
(
    [IBLOCK_NAME] => OCS
    [ID] => 480805
    [NAME] => Ноутбуки
    [IBLOCK_SECTION_ID] => 13165
    [PROPERTY_22_VALUE] => 
    [PROPERTY_22_VALUE_ID] => 
    [PROPERTY_3_VALUE] => 
    [PROPERTY_3_VALUE_ID] => 
    [PROPERTY_31_VALUE] => 90NB0IQ1-M01110
    [PROPERTY_31_VALUE_ID] => 10220466
    [PROPERTY_25_VALUE] => 
    [PROPERTY_25_VALUE_ID] => 
    [PROPERTY_27_VALUE] => 
    [PROPERTY_27_VALUE_ID] => 
    [PROPERTY_19_VALUE] => 
    [PROPERTY_19_VALUE_ID] => 
    [PROPERTY_7_VALUE] => 
    [PROPERTY_7_VALUE_ID] => 
    [PROPERTY_1_VALUE] => 
    [PROPERTY_1_VALUE_ID] => 
    [PROPERTY_39_VALUE] => 23095.000000000000
    [PROPERTY_39_VALUE_ID] => 10220472
    [PROPERTY_30_VALUE] => 1000497541
    [PROPERTY_30_VALUE_ID] => 10220465
    [PROPERTY_65_VALUE] => 
    [PROPERTY_65_VALUE_ID] => 
)

This 3 products from different infoblocks (ELKO, Treolan, OCS) have the same article number 90NB0IQ1-M01110.
These products must be combined into a single one and saved into the final Market infoblock with the following structure in the $marketArr array:
Товар в итоговом массиве Market
Array
(
    [ID] => КАКОЙ-ТО_ID_В_СИСТЕМЕ_BITRIX
    [NAME] => ИМЯ_ТОВАРА
    [IBLOCK_SECTION_ID] => ID_РАЗДЕЛА_К_КОТОРОМУ_ОТНОСИТСЯ_ТОВАР
    [PROPERTY_22_VALUE] => 90NB0IQ1-M01110               
    [PROPERTY_3_VALUE] => 90NB0IQ1-M01110
    [PROPERTY_31_VALUE] => 90NB0IQ1-M01110
    [PROPERTY_25_VALUE] => 23770
    [PROPERTY_27_VALUE] => 2
    [PROPERTY_19_VALUE] => 1266489
    [PROPERTY_7_VALUE] => 24171.00
    [PROPERTY_1_VALUE] => 053001/1894
    [PROPERTY_39_VALUE] => 23095.000000000000
    [PROPERTY_30_VALUE] => 1000497541
    [PROPERTY_65_VALUE] => 90NB0IQ1-M01110
)

But in the end, when the script is executed, the products are not combined into one, but are created under each other (that is, as a result, 3 products are obtained in the final Market infoblock with different properties):
9bad819ef9.png
Although my model with adding and changing a product is not only being written to DB, but also in the $marketArr array, works correctly. Here is the code for an example of how this model works: https://pastebin.com/YQQNYVrS
The result of this code:
Arr1 | 
 Товар добавлен [art] => 546436456 
 Товар добавлен [art] => 7683435 

 Arr2 | 
 Товар изменён [art] => 546436456 
 Товар добавлен [art] => 76653834543283435 

 Arr3 | 
 Товар изменён [art] => 546436456 
 Товар добавлен [art] => 45435233 

 Итоговый масив Arr | 
Array
(
    [0] => Array
        (
            [ID] => 546436456
        )

    [1] => Array
        (
            [ID] => 7683435
        )

    [2] => Array
        (
            [ID] => 76653834543283435
        )

    [3] => Array
        (
            [ID] => 45435233
        )

)

That is, first a product with the property [art] => 546436456 is added, and already in the next cycles, when this [art] is found, the product changes.
Why doesn’t this happen with goods from infoblocks (ELKO, OCS and Treolan), which should be combined into one and go to the Market infoblock. I repeat, at the moment, the products are not combined, but each product is added with its own properties.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yaroslav Alexandrov, 2019-06-17
@EvgenyJozef3000

1) Upload all your three infoblocks to xml files.
2) Write your own script for loading goods by xml
3) Upload each xml in turn, at the output you will get everything in one infoblock.
It is possible to try to import also standard import.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question