V
V
VicTHOR2019-08-20 14:16:41
1C-Bitrix
VicTHOR, 2019-08-20 14:16:41

How to copy items when exchanging to another section?

The bottom line is that if you make a page with the products of the section according to some attribute, then the "smart" filter shows the values ​​for all the products in the section. for some filter values ​​there will be 0 products.
Therefore, I want to duplicate products in another section and display its products. But the goods are essentially the same.
I need to copy them during the exchange, to a new section (and there will be several of them), and not create duplicates.
I suppose you need to hang a handler on the OnBeforeIBlockElementAdd and OnBeforeIBlockElementUpdate events .
And then how to catch the goods, get their property and copy the goods with a certain value of the property to another section?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yaroslav Alexandrov, 2019-08-21
@alexyarik

In general terms, the checklist is as follows:
In the OnBeforeIBlockElementAdd event , the $arFields array will contain the necessary data to create a duplicate product using the API. An example of an array https://yadi.sk/d/V19S_ncKNVif4g
In the event handler:

function OnAfterIBlockElementAddHandler(&$arFields)
    {
     if($arFields["ID"]>0) { 
           If($arFields['IBLOCK_ID'] == 5) {//инфоблок каталога

You receive data, process and create an element, then a product
1) CIBlockElement:Add
2) Then CCatalogProduct::Add
3) I would add some property to indicate a duplicate or link to a product, so that later it would be easier to calculate the product when updating.
In the OnBeforeIBlockElementUpdate event, the essence is the same, only you update the necessary data.
1) CIBlockElement:Update - updating the element
2) CIBlockElement::SetPropertyValuesEx - updating the properties
3) CCatalogProduct::Update - updating the product
4) CPrice::GetList - getting the price ID for updating
5) CPrice::Update - updating the price

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question