Advertisement
Eresken

sku+items+sections

Sep 14th, 2021
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.51 KB | None | 0 0
  1. $sql = [
  2.     'select' => [
  3.         "ID",
  4.     ],
  5.     'runtime' => [
  6.         new \Bitrix\Main\Entity\ReferenceField( // получим свойство связи с SKU
  7.             'CML2_LINK',
  8.             '\Bitrix\Iblock\PropertyTable',
  9.             [
  10.                 "=ref.CODE" => new \Bitrix\Main\DB\SqlExpression('?', 'CML2_LINK'),
  11.             ],
  12.             ["join_type" => "left"]
  13.         ),
  14.         new \Bitrix\Main\Entity\ReferenceField( // получим свойство артикула
  15.             'CML2_ARTICLE',
  16.             '\Bitrix\Iblock\PropertyTable',
  17.             [
  18.                 "=ref.CODE" => new \Bitrix\Main\DB\SqlExpression('?', 'CML2_ARTICLE'),
  19.             ],
  20.             ["join_type" => "left"]
  21.         ),
  22.         new \Bitrix\Main\Entity\ReferenceField( // получим свойство штрихкода
  23.             'CML2_BAR_CODE',
  24.             '\Bitrix\Iblock\PropertyTable',
  25.             [
  26.                 "=ref.CODE" => new \Bitrix\Main\DB\SqlExpression('?', 'CML2_BAR_CODE'),
  27.             ],
  28.             ["join_type" => "left"]
  29.         ),
  30.         new \Bitrix\Main\Entity\ReferenceField(
  31.             'SKU_LINK_ID',
  32.             '\Bitrix\Iblock\ElementPropertyTable',
  33.             [
  34.                 "=this.ID" => "ref.VALUE",
  35.                 "=this.CML2_LINK.ID" => "ref.IBLOCK_PROPERTY_ID",
  36.             ],
  37.             ["join_type" => "inner"]
  38.         ),
  39.         new \Bitrix\Main\Entity\ReferenceField(
  40.             'SKU_ITEM',
  41.             '\Bitrix\Iblock\ElementTable',
  42.             [
  43.                 "=this.SKU_LINK_ID.IBLOCK_ELEMENT_ID" => "ref.ID",
  44.             ],
  45.             ["join_type" => "left"]
  46.         ),
  47.         new \Bitrix\Main\Entity\ReferenceField(
  48.             'SKU_ITEM_PROPERTY_CML2_ARTICLE',
  49.             '\Bitrix\Iblock\ElementPropertyTable',
  50.             [
  51.                 "=this.SKU_ITEM.ID" => "ref.IBLOCK_ELEMENT_ID",
  52.                 "=this.CML2_ARTICLE.ID" => "ref.IBLOCK_PROPERTY_ID",
  53.             ],
  54.             ["join_type" => "left"]
  55.         ),
  56.         new \Bitrix\Main\Entity\ReferenceField(
  57.             'SKU_ITEM_PROPERTY_CML2_BAR_CODE',
  58.             '\Bitrix\Iblock\ElementPropertyTable',
  59.             [
  60.                 "=this.SKU_ITEM.ID" => "ref.IBLOCK_ELEMENT_ID",
  61.                 "=this.CML2_BAR_CODE.ID" => "ref.IBLOCK_PROPERTY_ID",
  62.             ],
  63.             ["join_type" => "left"]
  64.         ),
  65.         new \Bitrix\Main\Entity\ReferenceField(
  66.       'SECTION',
  67.       '\Bitrix\Iblock\SectionTable',
  68.       [
  69.          "=this.IBLOCK_SECTION_ID" => "ref.ID",
  70.       ],
  71.       ["join_type" => "left"]
  72.    ),
  73.    new \Bitrix\Main\Entity\ReferenceField(
  74.       'TOP_SECTION',
  75.       '\Bitrix\Iblock\SectionTable',
  76.       [
  77.          ">this.SECTION.LEFT_MARGIN" => "ref.LEFT_MARGIN",
  78.          "<this.SECTION.RIGHT_MARGIN" => "ref.RIGHT_MARGIN",
  79.          "=ref.DEPTH_LEVEL" => new \Bitrix\Main\DB\SqlExpression('?', '1'),
  80.       ],
  81.       ["join_type" => "left"]
  82.    ),
  83.  
  84.     ],
  85.     'group' => [
  86.         'ID',
  87.         //'SKU_ITEM.ID',
  88.     ],
  89.     'filter' => [
  90.         "ACTIVE" => "Y",
  91.         "IBLOCK_ID" => $arParams["IBLOCK_ID"], // только товары
  92.         "!=TOP_SECTION.CODE" => $_SESSION["SKIP_INDEX_SECTION_CODE"],
  93.     ],
  94.     'order' => ['ID' => "ASC"],
  95.     'cache' => ($arParams["CACHE_TYPE"] != "N" ? ["ttl" => $arParams["CACHE_TIME"], "cache_joins" => true] : null),
  96.     'limit' => 50000
  97. ];
  98. $iterator = \Bitrix\Iblock\ElementTable::getList($sql);
  99. while ($filtredElementArr = $iterator->fetch()) {
  100.     $ids[] = $filtredElementArr["ID"];
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement