B
B
Barders2022-03-27 14:01:33
1C-Bitrix
Barders, 2022-03-27 14:01:33

How to insert weight and quantity in the Advanced tab at the time of creation?

I create an element programmatically:

$arLoadProductArray = Array(
        "MODIFIED_BY"    => $USER->GetID(), // элемент изменен текущим пользователем
        "ACTIVE_FROM" => date('d.m.Y H:i:s'),
      	  "IBLOCK_SECTION" => $cat,          // элемент лежит в корне раздела
        "IBLOCK_ID"      => 5,
        "PROPERTY_VALUES"=> $PROP,
        "NAME"           => trim($data[2]),
        "QUANTITY" 		=> 100,
        "CODE"			=> $data[0],
        "ACTIVE"         	=> "N",  
        "WEIGHT" 			=> (int)$data[5],          // активен
        "PREVIEW_TEXT"   	=> $data[3],
        "DETAIL_TEXT"    	=> $data[3],
        "DETAIL_TEXT_TYPE" => 'text',
        "PREVIEW_PICTURE" => $arFile,
        "DETAIL_PICTURE" 	=> $arFile
      );
      
      if($PRODUCT_ID = $el->Add($arLoadProductArray)) {
        $add = true;
        	echo "Создан : ".$PRODUCT_ID . " Товар: " . $data[2]."<BR>";
        	CPrice::SetBasePrice($PRODUCT_ID, (int)$data[4], "RUB", 0);
        	CCatalogProduct::Add($PRODUCT_ID, array('QUANTITY' => 100));
        	CCatalogProduct::Add($PRODUCT_ID, array('WEIGHT' => (int)$data[5]));
        	
      }else{
        	echo "Error: ".$el->LAST_ERROR . " " . $file . "<BR>";
        	

      }


tried CCatalogProduct
::Update($PRODUCT_ID, array('QUANTITY' => 100));
CCatalogProduct::Update($PRODUCT_ID, array('WEIGHT' => (int)$data[5]));

and adds neither weight nor available quantity

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Barders, 2022-03-28
@Barders

In general, I decided this:

$existProduct = \Bitrix\Catalog\Model\Product::getCacheItem($arFields['ID'],true);

        if(!empty($existProduct)){
         \Bitrix\Catalog\Model\Product::update(intval($PRODUCT_ID),array("ID" => $PRODUCT_ID, array('WEIGHT' => (int)$data[5])));
        } else {
         \Bitrix\Catalog\Model\Product::add(array("ID" => $PRODUCT_ID, 'WEIGHT' => (int)$data[5]));
        }

A
Alexander, 2022-03-27
@kikher

Here is a piece of code how I update the data

$arFields = array(
        'WEIGHT' => $arrResult['Вес'],
        'WIDTH' => $arrResult['Ширина'],
        'LENGTH' => $arrResult['Глубина'],
        'HEIGHT' => $arrResult['Высота'],
    );

    // обновляем данные
   CCatalogProduct::Update($arrResult['ID'], $arFields);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question