D
D
Dmitry Grabko2020-11-18 15:44:13
1C-Bitrix
Dmitry Grabko, 2020-11-18 15:44:13

Change of price and available quantity at unloading?

There are 2 infoblocks on the site: Main (with structure and products) and auxiliary (only products here)

.

When importing into the service infoblock, I need to take the price and the balance of the goods from it and find the same in the main article by the article and substitute these values ​​for it

AddEventHandler("iblock", "OnAfterIBlockElementUpdate", "OrelBase");

function OrelBase(&$arFields)
{
  $price = CPrice::GetBasePrice($arFields['ID']);
  $count = CCatalogProduct::GetByID($arFields['ID']);
 	$item_orel = array(
    'NAME' => $arFields['NAME'],
    'ID' => $arFields['ID'],
    'ARTICUL' => $arFields['PROPERTY_VALUES']['9728']['271613275']['VALUE'],
    'PRICE_VALUE' => $price['PRICE'],
    'COUNT' => $count['QUANTITY']
   );

 	
  AddMessage2Log("<br/><br/><pre>".print_r($item_orel,true)."</pre><br/><br/>", "test");
   $res_tula = CIBlockElement::GetList(array("SORT"=>"ASC"),array('IBLOCK_ID' => 21,'PROPERTY_CML2_ARTICLE' => $item_orel['ARTICUL']), false,false, array("NAME", "ID", "PROPERTY_CML2_ARTICLE"));
  while($ob = $res_tula->GetNextElement())
  {
    $arFields = $ob->GetFields();
    //print_r($arFields);
    $price = CPrice::GetBasePrice($arFields['ID']);
    $count = CCatalogProduct::GetByID($arFields['ID']);

    /*меням цену*/

    $PRODUCT_ID = $arFields['ID'];
    $PRICE_TYPE_ID = 1;

    $arFields_price = Array(
        "PRODUCT_ID" => $PRODUCT_ID,
        "CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
        "PRICE" => $item_orel['PRICE_VALUE'],
        "CURRENCY" => "RUB"
    );

    $res = CPrice::GetList(
            array(),
            array(
                  "PRODUCT_ID" => $PRODUCT_ID,
                  "CATALOG_GROUP_ID" => $PRICE_TYPE_ID
              )
      );

    if ($arr = $res->Fetch())
    {
        CPrice::Update($arr["ID"], $arFields_price);
    }
    else
    {
        CPrice::Add($arFields_price);
    }
    /*меням цену конец*/

    /*меняем количество*/

    CCatalogProduct::Update($arFields['ID'], array('QUANTITY' => $item_orel['COUNT']));

    /*меняем количество конец*/
  }

}


When simply saving a resource in the admin panel, the replacement takes place every other time, and when importing, it does not happen at all

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
run182, 2020-11-18
@run182

Put logging and trace.
Add after

function OrelBase(&$arFields)
{

file_put_contents($_SERVER["DOCUMENT_ROOT"]."/log.txt", json_encode($arFields));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question