Z
Z
Zikdelk2021-04-10 22:33:13
1C-Bitrix
Zikdelk, 2021-04-10 22:33:13

How to display products from different infoblocks?

There is such a product export script connected to the mail template. And either I output infoblock 65 (I substitute infoblock 65 instead of 66). Or it turns out 66 infoblocks.

And how to display sections from two infoblocks 65 and 66?

$DOCUMENT_ROOT = str_replace('/scripts/exportlin.php','',__FILE__);
if(empty($_SERVER["DOCUMENT_ROOT"])) $_SERVER["DOCUMENT_ROOT"] = $DOCUMENT_ROOT;
require($DOCUMENT_ROOT."/bitrix/modules/main/include/prolog_before.php");
define("NO_KEEP_STATISTIC", true);
define("NOT_CHECK_PERMISSIONS", true);
set_time_limit(0);
ini_set('max_execution_time', '3600');
ini_set('memory_limit', '512M');
// if ( !$USER->IsAdmin() ) {
    // $APPLICATION->AuthForm("");
// }
CModule::IncludeModule("iblock");
CModule::IncludeModule("catalog");
CModule::IncludeModule("sale");
$IBLOCK_ID = 66;
$IBLOCK_SECTION_ID_ARR = Array(
  0 => 23590
);
$c = 0;



// exit;
foreach($IBLOCK_SECTION_ID_ARR as $k => $IBLOCK_SECTION_ID) {
  $sectArr[$IBLOCK_SECTION_ID] = $IBLOCK_SECTION_ID;

$rsParentSection = CIBlockSection::GetByID($IBLOCK_SECTION_ID);
if ($arParentSection = $rsParentSection->GetNext())
{
   $arFilter = array('IBLOCK_ID' => $arParentSection['IBLOCK_ID'],'>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'],'<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'],'>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']); // выберет потомков без учета активности
   $rsSect = CIBlockSection::GetList(array('left_margin' => 'asc'),$arFilter);
   while ($arSect = $rsSect->GetNext())
   {
       // получаем подразделы
     // echo $arSect["ID"].'<br />';
     $sectArr[$arSect["ID"]] = $arSect["ID"];
   }
}

}
// echo '<pre>';

foreach($sectArr as $v){
$arFilter = Array(
   "IBLOCK_ID"=>$IBLOCK_ID,
   "IBLOCK_SECTION_ID"=>$v,
   // "SECTION_ID"=>$IBLOCK_SECTION_ID,
);
$res = CIBlockElement::GetList(Array("ID"=>"ASC"), $arFilter, Array("ID","NAME","DETAIL_PAGE_URL","CODE","SVOB_OZHIDAEMYY_OSTATOK","CATALOG_MEASURE_NAME"));
while ($ar_fields = $res->GetNext()) {
  
  $ID = $ar_fields["ID"];
$ar_res = CCatalogProduct::GetByID($ID);
/*echo "<br>Товар с кодом ".$ID." имеет следующие параметры:<pre>";
print_r($ar_res);
echo "</pre>";
  echo '***<pre>';
  print_r($ar_fields);
  exit;*/
  
$svob = CIBlockElement::GetByID($ID)->GetNextElement()->GetProperties();
$svob = $svob['SVOB_OZHIDAEMYY_OSTATOK']['VALUE']?' Своб.ожидаемый остаток: '.$svob['SVOB_OZHIDAEMYY_OSTATOK']['VALUE']:'';

if($ar_res["AVAILABLE"] == "Y" && $ar_res["QUANTITY"] > 0){
$str .= <<<EOD

<table border="1" cellpadding="1" cellspacing="1" style="width: 850px">
  <tbody>
    <tr>
      <td style="width: 100px;">{$ID}</td>
      <td>{$ar_fields["NAME"]}</td>
      <td style="width: 80px;">{$ar_res["QUANTITY"]}</td>
    </tr>
  </tbody>
</table>

{$svob} \n\r
EOD;
}
$c++;

}
}

//echo $ar_fields['PROREPTY_SVOB_OZHIDAEMYY_OSTATOK_VALUE']." ;<br>";

echo $c.'<br />';
$MESSAGE = $str;
$str = nl2br($str);
echo $str;

$arEventFields = array(
  "MESSAGE" => $MESSAGE
);
CEvent::SendImmediate("EXPORTLIN", Array("s1"), $arEventFields);
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-04-12
@Zikdelk

the rest is the SVOB_OZHIDAEMYY_OSTATOK property? Or is there still a balance in the trade catalog?
If in the sales catalog

\Bitrix\Main\Loader::includeModule('catalog');

$iblockIds = [65, 66];
$elements = \Bitrix\Catalog\ProductTable::getList([
  'select' => ['ELEMENT_ID' => 'IBLOCK_ELEMENT.ID', 'ELEMENT_NAME' => 'IBLOCK_ELEMENT.NAME', 'QUANTITY'],
  'filter' => ['IBLOCK_ELEMENT.IBLOCK_ID' => $iblockIds, '>QUANTITY' => 0]
])->fetchAll();

print_r($elements);

If property
$elements = [];
$iblockIds = [65, 66];

$iterator = \CIBlockElement::GetList(['ID' => 'ASC'], ['IBLOCK_ID' => $iblockIds, '>PROPERTY_SVOB_OZHIDAEMYY_OSTATOK' => 0], false, false, ['ID', 'NAME', 'PROPERTY_SVOB_OZHIDAEMYY_OSTATOK']);
while($row = $iterator->Fetch()) {
  $elements[] = $row;
}

print_r($elements);

Comment out all the previous code, it is not needed
<?
//...................
// это не надо
/*
CModule::IncludeModule("iblock");
CModule::IncludeModule("catalog");
CModule::IncludeModule("sale");
*/

\Bitrix\Main\Loader::includeModule('catalog');

$iblockIds = [65, 66];
$elements = \Bitrix\Catalog\ProductTable::getList([
  'select' => ['ELEMENT_ID' => 'IBLOCK_ELEMENT.ID', 'ELEMENT_NAME' => 'IBLOCK_ELEMENT.NAME', 'QUANTITY'],
  'filter' => ['IBLOCK_ELEMENT.IBLOCK_ID' => $iblockIds, '>QUANTITY' => 0]
])->fetchAll();

// дальше все комментируешь до своей таблицы
?>

<?if($elements):?>
  <table border="1" cellpadding="1" cellspacing="1" style="width: 850px">
    <tbody>
    <?foreach($elements as $element):?>
      <tr>
        <td style="width: 100px;"><?=$element['ELEMENT_ID'];?></td>
        <td><?=$element['ELEMENT_NAME'];?></td>
        <td style="width: 80px;"><?=$element['QUANTITY'];?></td>
      </tr>
    <?endforeach;?>
    </tbody>
  </table>
<?endif;?>

if you need to write a table to a variable, then you need to add buffering
<?ob_start();?>
    <?if($elements):?>
.................................................
    <?endif;?>
<?$MESSAGE = ob_get_clean();?>

PS
do not use uppercase in variables ($MESSAGE), it should always be camelcase

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question