/** * @param array $fields Item fields. * @return array */ public static function onBeforeIndex($fields) { if (!isset($fields['MODULE_ID']) || $fields['MODULE_ID'] != 'iblock') { return $fields; } if (empty($fields['PARAM2'])) { return $fields; } if (!isset(self::$catalogList[$fields['PARAM2']])) { self::$catalogList[$fields['PARAM2']] = false; $catalogIterator = CatalogIblockTable::getList(array('select' => array('IBLOCK_ID'), 'filter' => array('=IBLOCK_ID' => $fields['PARAM2']))); $catalog = $catalogIterator->fetch(); if (!empty($catalog)) { self::$catalogList[$fields['PARAM2']] = $catalog['IBLOCK_ID']; } unset($catalog, $catalogIterator); } if (!empty(self::$catalogList[$fields['PARAM2']])) { $fields["PARAMS"]["iblock_section"] = array(); if (strpos($fields['ITEM_ID'], 'S') === false) { $sections = \CIBlockElement::getElementGroups($fields["ITEM_ID"], true, array('ID')); while ($section = $sections->fetch()) { $nav = \CIBlockSection::getNavChain($fields['PARAM2'], $section["ID"], array('ID')); while ($chain = $nav->fetch()) { $fields["PARAMS"]["iblock_section"][] = $chain['ID']; } unset($chain, $nav); } unset($section, $sections); } else { $nav = \CIBlockSection::getNavChain($fields['PARAM2'], preg_replace('#[^0-9]+#', '', $fields["ITEM_ID"]), array('ID')); while ($chain = $nav->fetch()) { $fields["PARAMS"]["iblock_section"][] = $chain['ID']; } unset($chain, $nav); } } return $fields; }
/** * @param array $fields Item fields. * @return array */ public function onBeforeIndex($fields) { if ($fields["MODULE_ID"] == "iblock") { $catalogs = \CCatalog::getList(array(), array('IBLOCK_ID' => $fields['PARAM2']), false, false, array('IBLOCK_ID')); if ($catalogs->fetch()) { $fields["PARAMS"]["iblock_section"] = array(); if (strpos($fields['ITEM_ID'], 'S') === false) { $sections = \CIBlockElement::getElementGroups($fields["ITEM_ID"], true, array('ID')); while ($section = $sections->fetch()) { $nav = \CIBlockSection::getNavChain($fields['PARAM2'], $section["ID"], array('ID')); while ($chain = $nav->fetch()) { $fields["PARAMS"]["iblock_section"][] = $chain['ID']; } } } else { $nav = \CIBlockSection::getNavChain($fields['PARAM2'], preg_replace('#[^0-9]+#', '', $fields["ITEM_ID"]), array('ID')); while ($chain = $nav->fetch()) { $fields["PARAMS"]["iblock_section"][] = $chain['ID']; } } } } return $fields; }
/** * Returns product data. * * @param array &$productData Product data. * @param array $entityData Entity data. * @param array $iblockData Iblock list data. * @return void */ protected static function getProductData(&$productData, $entityData, $iblockData) { if (!empty($iblockData['iblockElement'])) { $productList = array_keys($productData); if (!empty($entityData['iblockFields'])) { $elementIterator = Iblock\ElementTable::getList(array('select' => array_merge(array('ID'), array_keys($entityData['iblockFields'])), 'filter' => array('@ID' => $productList))); while ($element = $elementIterator->fetch()) { $element['ID'] = (int) $element['ID']; $fields = array(); foreach ($entityData['iblockFields'] as $key => $alias) { $fields[$alias] = $element[$key]; } unset($key, $alias); $productData[$element['ID']] = empty($productData[$element['ID']]) ? $fields : array_merge($productData[$element['ID']], $fields); unset($fields); } } if ($entityData['sections']) { $productSection = array_fill_keys($productList, array()); $elementSectionIterator = Iblock\SectionElementTable::getList(array('select' => array('*'), 'filter' => array('@IBLOCK_ELEMENT_ID' => $productList))); while ($elementSection = $elementSectionIterator->fetch()) { $elementSection['IBLOCK_ELEMENT_ID'] = (int) $elementSection['IBLOCK_ELEMENT_ID']; $elementSection['IBLOCK_SECTION_ID'] = (int) $elementSection['IBLOCK_SECTION_ID']; $elementSection['ADDITIONAL_PROPERTY_ID'] = (int) $elementSection['ADDITIONAL_PROPERTY_ID']; if ($elementSection['ADDITIONAL_PROPERTY_ID'] > 0) { continue; } $productSection[$elementSection['IBLOCK_ELEMENT_ID']][$elementSection['IBLOCK_SECTION_ID']] = true; $parentSectionIterator = \CIBlockSection::getNavChain(0, $elementSection['IBLOCK_SECTION_ID'], array('ID')); while ($parentSection = $parentSectionIterator->fetch()) { $parentSection['ID'] = (int) $parentSection['ID']; $productSection[$elementSection['IBLOCK_ELEMENT_ID']][$parentSection['ID']] = true; } unset($parentSection, $parentSectionIterator); } unset($elementSection, $elementSectionIterator); foreach ($productSection as $element => $sections) { $productData[$element]['SECTION_ID'] = array_keys($sections); } unset($element, $sections, $productSection); } if (!empty($entityData['needProperties'])) { $propertyValues = array_fill_keys($productList, array()); foreach ($entityData['needProperties'] as $iblock => $propertyList) { if (empty($iblockData['iblockElement'][$iblock])) { continue; } $filter = array('ID' => $iblockData['iblockElement'][$iblock], 'IBLOCK_ID' => $iblock); \CTimeZone::disable(); \CIBlockElement::getPropertyValuesArray($propertyValues, $iblock, $filter, array('ID' => $propertyList)); \CTimeZone::enable(); } unset($filter, $iblock, $propertyList); self::convertProperties($productData, $propertyValues, $entityData, $iblockData); } if (!empty($entityData['catalogFields'])) { $productIterator = Catalog\ProductTable::getList(array('select' => array_merge(array('ID'), array_keys($entityData['catalogFields'])), 'filter' => array('@ID' => $productList))); while ($product = $productIterator->fetch()) { $product['ID'] = (int) $product['ID']; $fields = array(); foreach ($entityData['catalogFields'] as $key => $alias) { $fields[$alias] = $product[$key]; } unset($key, $alias); $productData[$product['ID']] = empty($productData[$product['ID']]) ? $fields : array_merge($productData[$product['ID']], $fields); unset($fields); } unset($product, $productIterator); } if (!empty($iblockData['skuIblockList'])) { self::getParentProducts($productData, $entityData, $iblockData); } } }
/** * Returns all section parents. * * @param integer $sectionId Section identifier. * * @return mixed */ public function getSectionParents($sectionId) { if (!isset(self::$sectionParents[$sectionId])) { $sections = array(); $sectionList = \CIBlockSection::getNavChain($this->iblockId, $sectionId, array("ID")); while ($section = $sectionList->fetch()) { $sections[] = $section["ID"]; } self::$sectionParents[$sectionId] = $sections; } return self::$sectionParents[$sectionId]; }