A
A
anriko2020-06-29 11:09:42
1C-Bitrix
anriko, 2020-06-29 11:09:42

How to update the name of trade offers via $el->Update?

it did not work out in the admin panel did not change

$el = new CIBlockElement;
      $arLoadProductArray = Array(
          "SUB_NAME"   => "1.3.1 Однопутная железная дорога"
      );
      $res = $el->Update(8319, $arLoadProductArray);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Gritsuk, 2020-06-29
@winer

a trade offer (TP) is the same infoblock element as the parent product.
The TP will be located in a separate infoblock and have its own ID.
Therefore, to update the TP fields, it is necessary to pass the TP ID, not the product ID, to the CIBlockElement::Update method.

$el = new CIBlockElement;
$fields = Array(
     "NAME"   => "1.3.1 Однопутная железная дорога"
);
$skuId = 8140;//ID торгового предложения
$res = $el->Update($skuId, $fields );

A
anriko, 2020-06-29
@anriko

* $_FROM_FIELD_NAMES = array(DATE_ACTIVE_FROM, DATE_ACTIVE_TO);
 * $TO_PROPERTY_NAMES = array(DATE_BEGIN, DATE_END);
 * copy_from_fields_to_propertys_values(22, array("DATE_ACTIVE_FROM","DATE_ACTIVE_TO"), array("DATE_BEGIN","DATE_END"));
 * */

/* для сео свойств */
function copy_from_fields_to_propertys_values($SECTION_ID, $_FROM_FIELD_NAMES){
    if ( CModule::IncludeModule ( "iblock" ) ){
        $arOrder = array(
            "sort" => "ASC",
        );
        $arFilter = array(
      //"IBLOCK_ID" => $IBLOCK_ID,
      "SECTION_ID" => $SECTION_ID
        );
        foreach ( $_FROM_FIELD_NAMES as $property_name ) {
            $_FROM_PROPERTY_NAMES_with_prop[] = 'PROPERTY_' . $property_name;
        }
        $arSelect = array(
            "NAME",
      "ID" );
        $arSelect = array_merge ( $arSelect,$_FROM_PROPERTY_NAMES_with_prop );
        $db_elemens = CIBlockElement::GetList ( $arOrder, $arFilter, false, false, $arSelect );
        while ( $arElement = $db_elemens->Fetch () ) {
            $PRODUCT_ID = $arElement["ID"];
      $el = new CIBlockElement;
        $arLoadProductArray = Array(
          "IPROPERTY_TEMPLATES"   => array(
          "ELEMENT_META_TITLE" => $arElement["PROPERTY_UN_TITLE_VALUE"],
          "ELEMENT_META_DESCRIPTION" => $arElement["PROPERTY_UN_DESCR_VALUE"],
          "ELEMENT_META_KEYWORDS" => $arElement["PROPERTY_UN_KEY_VALUE"],
          )
        );
        $res = $el->Update($PRODUCT_ID, $arLoadProductArray);  }

    } else {
        die( "Модуль iblock не установлен" );
    }
}

copy_from_fields_to_propertys_values( 824, array("UN_TITLE","UN_DESCR","UN_KEY"));
/*для торговых предложений*/
function copy_from_fields_to_propertys_values($SECTION_ID){
    if ( CModule::IncludeModule ( "iblock" ) ){
        $arOrder = array(
            "sort" => "ASC",
        );
        $arFilter = array(
            //"IBLOCK_ID" => $IBLOCK_ID,
            "SECTION_ID" => $SECTION_ID
        );
        $arSelect = array(
            "NAME",
            "ID",
        );
        $arSelect = array_merge ($arSelect);
        $db_elemens = CIBlockElement::GetList ( $arOrder, $arFilter, false, false, $arSelect );

        while ( $arElement = $db_elemens->Fetch () ) {
            $PRODUCT_ID = $arElement["ID"];
            $el = new CIBlockElement;
            /*для торговых предложений*/
            $arSKU = CCatalogSKU::getOffersList(
                $PRODUCT_ID,
                0,
                array('ACTIVE' => 'Y'),
                array('ID', 'NAME'),
                array()
            );
            foreach ($arSKU as $key =>$prod) {
                foreach ($prod as $key =>$torgpred) {
                    $arLoadProductArray = Array("NAME" => $arElement["NAME"]);
                    $res = $el->Update($torgpred["ID"], $arLoadProductArray);
                    echo $torgpred["ID"];
                }
            }
        }
    } else {
        die( "Модуль iblock не установлен" );
    }
}

copy_from_fields_to_propertys_values( 839);
copy_from_fields_to_propertys_values( 825);
copy_from_fields_to_propertys_values( 880);
copy_from_fields_to_propertys_values( 824);
copy_from_fields_to_propertys_values( 821);

/* поменял сосотояние в торговых предложения взависимоти от цены*/
 $productID = $arResult["ITEM"]["ID"];
                            $res = CCatalogSKU::getOffersList($productID, 0, array('ACTIVE' => 'Y'), array(""), array(""));
                            foreach ($res["$productID"] as $key => $tpred){

                                $rsOffers = CIBlockElement::GetList(
                                    array("sort" => "ASC"), // Свойства, по которым идет сортировка
                                    array('ID' => $tpred["ID"]), // Фильтрация
                                    false,
                                    false,
                                    array("ID", "IBLOCK_ID", "NAME","ACTIVE","PROPERTY_SIZE_IMG_SIGN","PROPERTY_MINIMUM_PRICE") // Свойства, которые нужно получить.
                                );
                                $price = GetCatalogProductPrice($tpred["ID"], 1);
                                while ( $arElement = $rsOffers->Fetch () ) {
                                    $el = new CIBlockElement;


                                    $arLoadProductArray = Array(
                                        "ACTIVE"   => "N"
                                    );
                                    if(round($price["PRICE"]) == 1){
                                        echo round($price["PRICE"])."!";
                                        $res = $el->Update($tpred["ID"], $arLoadProductArray);
                                    }

                                }
                            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question