Пример #1
0
 public function getSlides()
 {
     if (CModule::IncludeModule("iblock")) {
         $res = \Bitrix\Iblock\ElementTable::getList(array('select' => array("PREVIEW_PICTURE", "PREVIEW_TEXT", "NAME"), 'filter' => array("IBLOCK_ID" => $this->arParams["IBLOCK_ID"], "ACTIVE" => "Y")));
         $arItems = array();
         while ($arItem = $res->fetch()) {
             $arItems[] = $arItem;
         }
         return $arItems;
     }
 }
Пример #2
0
 public static function getMap()
 {
     if (static::getIblockId() === null) {
         return parent::getMap();
     }
     $map = parent::getMap();
     foreach (self::getAdditionalMap() as $key => $mapItem) {
         $map[] = $mapItem;
     }
     return $map;
 }
Пример #3
0
 public function getArrINlockElements($IBlockId)
 {
     $listIBlockElement = \Bitrix\Iblock\ElementTable::getList(array('select' => array("CODE", "ACTIVE", "NAME", "SORT", "DETAIL_TEXT"), 'filter' => array("IBLOCK_ID" => $IBlockId)));
     while ($IBlockElement = $listIBlockElement->Fetch()) {
         if (isset($IBlockElement['DETAIL_TEXT_TYPE'])) {
             unset($IBlockElement['DETAIL_TEXT_TYPE']);
         }
         $arIBlockElements[] = $IBlockElement;
         //Массив с загруженными элементами инфоблока
     }
     return $arIBlockElements;
 }
 /**
  * {@inheritdoc}
  */
 public function generateRow(&$row, $data)
 {
     $elementId = $this->getValue();
     if (!empty($elementId)) {
         $rsElement = ElementTable::getList(['filter' => ['ID' => $elementId], 'select' => ['ID', 'NAME', 'IBLOCK_ID', 'IBLOCK.IBLOCK_TYPE_ID']]);
         $element = $rsElement->fetch();
         $html = '<a href="/bitrix/admin/iblock_element_edit.php?IBLOCK_ID=' . $element['IBLOCK_ID'] . '&type=' . $element['IBLOCK_ELEMENT_IBLOCK_IBLOCK_TYPE_ID'] . '&ID=' . $elementId . '&lang=ru">[' . $elementId . '] ' . static::prepareToOutput($element['NAME']) . '</a>';
     } else {
         $html = '';
     }
     $row->AddViewField($this->getCode(), $html);
 }
Пример #5
0
 function onIBlockElementDelete($id)
 {
     $modifier_id = intval(Option::get('modifier_id'));
     $params = array(
         'select' => array('IBLOCK_ID'),
         'filter' => array(
             '=ID' => $id
         )
     );
     $arElement = ElementTable::getRow($params);
     if (intval($arElement['IBLOCK_ID']) !== $modifier_id)
     {
         return ElementModifiers::delete($id);
     }
     return Modifiers::delete($id);
 }
Пример #6
0
 /**
  * Set values for fields type iblock_element.
  */
 protected function setElementValue()
 {
     $iblockList = $this->getListByType('iblock_element');
     $queryBuilder = new Entity\Query(Iblock\ElementTable::getEntity());
     $queryBuilder->setSelect(array('ID', 'NAME', 'IBLOCK_ID', 'IBLOCK_SECTION_ID'))->setFilter(array('IBLOCK_ID' => $iblockList))->setOrder(array());
     $elementResult = $queryBuilder->exec();
     while ($element = $elementResult->fetch()) {
         foreach ($this->highLoadBlockFields as &$field) {
             if ($field['USER_TYPE_ID'] != 'iblock_element') {
                 continue;
             }
             if ($field['SETTINGS']['IBLOCK_ID'] == $element['IBLOCK_ID']) {
                 $field['VALUE_LIST'][] = $element;
             }
         }
     }
 }
Пример #7
0
 public function queryValues()
 {
     $result = array();
     if ($this->hasTemplates()) {
         $connection = \Bitrix\Main\Application::getConnection();
         $query = $connection->query("\n\t\t\t\tSELECT\n\t\t\t\t\tP.ID\n\t\t\t\t\t,P.CODE\n\t\t\t\t\t,P.TEMPLATE\n\t\t\t\t\t,P.ENTITY_TYPE\n\t\t\t\t\t,P.ENTITY_ID\n\t\t\t\t\t,IP.VALUE\n\t\t\t\tFROM\n\t\t\t\t\tb_iblock_element_iprop IP\n\t\t\t\t\tINNER JOIN b_iblock_iproperty P ON P.ID = IP.IPROP_ID\n\t\t\t\tWHERE\n\t\t\t\t\tIP.IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\t\tAND IP.ELEMENT_ID = " . $this->element_id . "\n\t\t\t");
         while ($row = $query->fetch()) {
             $result[$row["CODE"]] = $row;
         }
         if (empty($result)) {
             $result = parent::queryValues();
             if (!empty($result)) {
                 $elementList = \Bitrix\Iblock\ElementTable::getList(array("select" => array("IBLOCK_SECTION_ID"), "filter" => array("=ID" => $this->element_id)));
                 $element = $elementList->fetch();
                 foreach ($result as $CODE => $row) {
                     $connection->add("b_iblock_element_iprop", array("IBLOCK_ID" => $this->iblock_id, "SECTION_ID" => intval($element["IBLOCK_SECTION_ID"]), "ELEMENT_ID" => $this->element_id, "IPROP_ID" => $row["ID"], "VALUE" => $row["VALUE"]));
                 }
             }
         }
     }
     return $result;
 }
Пример #8
0
 public function loadFromDatabase()
 {
     if (!isset($this->fields)) {
         $this->fields = array();
         $select = array_values($this->fieldMap);
         $elementList = \Bitrix\Iblock\ElementTable::getList(array("select" => $select, "filter" => array("=ID" => $this->id)));
         $this->elementFields = $elementList->fetch();
         if ($this->elementFields) {
             $arCatalog = \CCatalogSKU::getInfoByProductIBlock($this->elementFields["IBLOCK_ID"]);
             if (is_array($arCatalog)) {
                 $this->skuIblockId = $arCatalog["IBLOCK_ID"];
                 $skuList = \CIBlockElement::getList(array(), array("IBLOCK_ID" => $arCatalog["IBLOCK_ID"], "=PROPERTY_" . $arCatalog["SKU_PROPERTY_ID"] => $this->id), false, false, $select);
                 while ($sku = $skuList->fetch()) {
                     $this->skuList[] = $sku;
                     foreach ($sku as $fieldName => $fieldValue) {
                         $this->fields[$fieldName][] = $fieldValue;
                     }
                 }
             }
         }
     }
     return is_array($this->fields);
 }
<?php

require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
try {
    $request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();
    if (!$request->isPost()) {
        die;
    }
    $emp_id = (int) $request->getPost("emp_id");
    if ($emp_id < 0) {
        throw new \Exception("Не указан id");
    }
    $employees_iblock_id = 3;
    \Bitrix\Main\Loader::includeModule("iblock");
    $emp = \Bitrix\Iblock\ElementTable::getList(array("select" => array("ID", "NAME", "DETAIL_PICTURE", "DETAIL_TEXT"), "filter" => array("ID" => $emp_id)))->fetch();
    if ($emp["ID"] <= 0) {
        throw new \Exception("Элемент не найден");
    }
    $img_src = "";
    if ($emp["DETAIL_PICTURE"] > 0) {
        $img = CFile::GetFileArray($emp["DETAIL_PICTURE"]);
        $img_src = $img["SRC"];
    }
    echo json_encode(array("id" => $emp["ID"], "name" => $emp["NAME"], "detail_text" => $emp["DETAIL_TEXT"], "img_src" => $img_src));
    die;
} catch (\Exception $e) {
    echo json_encode(array("error" => $e->getMessage()));
    die;
}
Пример #10
0
 /**
  * Returns list of recommended products for specific product.
  *
  * @param int $USER_ID							User id.
  * @param string $LID							Site id.
  * @param array $arFilterRecomendet				Recomendation filter.
  * @param string $recomMore						Get more.
  * @param int $cntProductDefault				Max count.
  * @return array
  */
 function GetRecommendetProduct($USER_ID, $LID, $arFilterRecomendet = array(), $recomMore = 'N', $cntProductDefault = 2)
 {
     $arRecomendetResult = array();
     if (CModule::IncludeModule('catalog') && !empty($arFilterRecomendet)) {
         $arRecomendet = array();
         if (!is_array($arFilterRecomendet)) {
             $arFilterRecomendet = array($arFilterRecomendet);
         }
         Main\Type\Collection::normalizeArrayValuesByInt($arFilterRecomendet);
         if (empty($arFilterRecomendet)) {
             return $arRecomendetResult;
         }
         $iblockRecommended = array();
         $productIterator = Iblock\ElementTable::getList(array('select' => array('ID', 'IBLOCK_ID'), 'filter' => array('@ID' => $arFilterRecomendet, '=ACTIVE' => 'Y')));
         while ($product = $productIterator->fetch()) {
             $product['ID'] = (int) $product['ID'];
             $product['IBLOCK_ID'] = (int) $product['IBLOCK_ID'];
             if (!isset($iblockRecommended[$product['IBLOCK_ID']])) {
                 $iblockRecommended[$product['IBLOCK_ID']] = array();
             }
             $iblockRecommended[$product['IBLOCK_ID']][] = $product['ID'];
         }
         unset($product, $productIterator);
         if (empty($iblockRecommended)) {
             return $arRecomendetResult;
         }
         $propertyList = array();
         $propertyIterator = Iblock\PropertyTable::getList(array('select' => array('ID', 'IBLOCK_ID'), 'filter' => array('@IBLOCK_ID' => array_keys($iblockRecommended), '=CODE' => 'RECOMMEND', '=PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_ELEMENT)));
         while ($property = $propertyIterator->fetch()) {
             $property['ID'] = (int) $property['ID'];
             $property['IBLOCK_ID'] = (int) $property['IBLOCK_ID'];
             $propertyList[$property['IBLOCK_ID']] = $property['ID'];
         }
         unset($property, $propertyIterator);
         if (empty($propertyList)) {
             return $arRecomendetResult;
         }
         foreach ($propertyList as $iblockID => $propertyID) {
             $propertyValue = 'PROPERTY_' . $propertyID;
             $filter = array('ID' => $iblockRecommended[$iblockID], 'IBLOCK_ID' => $iblockID);
             $select = array('ID', 'IBLOCK_ID', $propertyValue);
             $propertyValue .= '_VALUE';
             $elementIterator = CIBlockElement::GetList(array(), $filter, false, false, $select);
             while ($element = $elementIterator->Fetch()) {
                 if (empty($element[$propertyValue])) {
                     continue;
                 }
                 if (is_array($element[$propertyValue])) {
                     foreach ($element[$propertyValue] as &$recId) {
                         $recId = (int) $recId;
                         if ($recId > 0) {
                             $arRecomendet[$recId] = true;
                         }
                     }
                     unset($recId);
                 } else {
                     $recId = (int) $element[$propertyValue];
                     if ($recId > 0) {
                         $arRecomendet[$recId] = true;
                     }
                 }
             }
         }
         unset($element, $elementIterator, $select, $filter, $propertyValue, $propertyID, $iblockID, $propertyList);
         if (!empty($arRecomendet)) {
             $arRecomendet = array_keys($arRecomendet);
             $arBuyerGroups = CUser::GetUserGroup($USER_ID);
             $arFilter = array("ID" => $arRecomendet, "ACTIVE" => "Y");
             $rsElement = CIBlockElement::GetList(array(), $arFilter, false, false, array("NAME", "ID", "LID", 'IBLOCK_ID', 'IBLOCK_SECTION_ID', "DETAIL_PICTURE", "PREVIEW_PICTURE", "DETAIL_PAGE_URL"));
             $currentVatMode = CCatalogProduct::getPriceVatIncludeMode();
             $currentUseDiscount = CCatalogProduct::getUseDiscount();
             CCatalogProduct::setUseDiscount(true);
             CCatalogProduct::setPriceVatIncludeMode(true);
             CCatalogProduct::setUsedCurrency(CSaleLang::GetLangCurrency($LID));
             $i = 0;
             while ($arElement = $rsElement->GetNext()) {
                 if (in_array($arElement["ID"], $arFilterRecomendet)) {
                     continue;
                 }
                 if ($recomMore == "N" && $i < $cntProductDefault || $recomMore == "Y") {
                     $arElement["MODULE"] = "catalog";
                     $arElement["PRODUCT_PROVIDER_CLASS"] = "CCatalogProductProvider";
                     $arElement["PRODUCT_ID"] = $arElement["ID"];
                     $arPrice = CCatalogProduct::GetOptimalPrice($arElement["ID"], 1, $arBuyerGroups, "N", array(), $LID, array());
                     $currentPrice = $arPrice['RESULT_PRICE']['DISCOUNT_PRICE'];
                     $arElement["PRICE"] = $currentPrice;
                     $arElement["CURRENCY"] = $arPrice["RESULT_PRICE"]["CURRENCY"];
                     $arElement["DISCOUNT_PRICE"] = $arPrice['RESULT_PRICE']['DISCOUNT'];
                     if ($arElement["IBLOCK_ID"] > 0 && $arElement["IBLOCK_SECTION_ID"] > 0) {
                         $arElement["EDIT_PAGE_URL"] = CIBlock::GetAdminElementEditLink($arElement["IBLOCK_ID"], $arElement["PRODUCT_ID"], array("find_section_section" => $arElement["IBLOCK_SECTION_ID"], 'WF' => 'Y'));
                     }
                     $arRecomendetResult[] = $arElement;
                     $i++;
                 }
             }
             CCatalogProduct::clearUsedCurrency();
             CCatalogProduct::setPriceVatIncludeMode($currentVatMode);
             CCatalogProduct::setUseDiscount($currentUseDiscount);
             unset($currentUseDiscount, $currentVatMode);
         }
     }
     return $arRecomendetResult;
 }
Пример #11
0
 static function getByPropCode($code)
 {
     if (strpos($code, self::PREFIX) !== false)
     {
         $id = str_replace(self::PREFIX, '', $code);
         $params = array(
             'select' => array(
                 'ELEMENT_XML_ID' => 'XML_ID',
                 'ELEMENT_NAME'   => 'NAME',
                 'SECTION_NAME'   => 'SECTION.NAME',
                 'SECTION_XML_ID' => 'SECTION.XML_ID'
             ),
             'filter' => array(
                 '=ID' => $id
             ),
             'runtime' => array(
                 new ReferenceField(
                     'SECTION',
                     '\Bitrix\Iblock\SectionTable',
                     array('=this.IBLOCK_SECTION_ID' => 'ref.ID'),
                     array('join_type' => 'LEFT')
                 )
             )
         );
         return ElementTable::getRow($params);
     }
     return '';
 }
Пример #12
0
/**
 * @param int $intProductID
 * @param array $arRewriteFields
 * @param array $arProductParams
 * @return bool|int
 */
function SubscribeProduct($intProductID, $arRewriteFields = array(), $arProductParams = array())
{
    global $USER, $APPLICATION;
    if (!CCatalog::IsUserExists()) {
        return false;
    }
    if (!$USER->IsAuthorized()) {
        return false;
    }
    $intUserID = (int) $USER->GetID();
    $intProductID = (int) $intProductID;
    if ($intProductID <= 0) {
        $APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_EMPTY_PRODUCT_ID'), "EMPTY_PRODUCT_ID");
        return false;
    }
    if (!Loader::includeModule("sale")) {
        $APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_NO_SALE_MODULE'), "NO_SALE_MODULE");
        return false;
    }
    if (Loader::includeModule("statistic") && isset($_SESSION['SESS_SEARCHER_ID']) && (int) $_SESSION["SESS_SEARCHER_ID"] > 0) {
        $APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_SESS_SEARCHER'), "SESS_SEARCHER");
        return false;
    }
    $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $intProductID), false, false, array('ID', 'WEIGHT', 'WIDTH', 'HEIGHT', 'LENGTH', 'TYPE', 'MEASURE', 'SUBSCRIBE'));
    if (!($arCatalogProduct = $rsProducts->Fetch())) {
        $APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_NO_PRODUCT'), "NO_PRODUCT");
        return false;
    }
    if ($arCatalogProduct['SUBSCRIBE'] == 'N') {
        $APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_NO_SUBSCRIBE'), 'SUBSCRIBE');
        return false;
    }
    $arCatalogProduct['MEASURE'] = (int) $arCatalogProduct['MEASURE'];
    $arCatalogProduct['MEASURE_NAME'] = '';
    $arCatalogProduct['MEASURE_CODE'] = 0;
    if ($arCatalogProduct['MEASURE'] <= 0) {
        $arMeasure = CCatalogMeasure::getDefaultMeasure(true, true);
        $arCatalogProduct['MEASURE_NAME'] = $arMeasure['~SYMBOL_RUS'];
        $arCatalogProduct['MEASURE_CODE'] = $arMeasure['CODE'];
    } else {
        $rsMeasures = CCatalogMeasure::getList(array(), array('ID' => $arCatalogProduct['MEASURE']), false, false, array('ID', 'SYMBOL_RUS', 'CODE'));
        if ($arMeasure = $rsMeasures->GetNext()) {
            $arCatalogProduct['MEASURE_NAME'] = $arMeasure['~SYMBOL_RUS'];
            $arCatalogProduct['MEASURE_CODE'] = $arMeasure['CODE'];
        }
    }
    $rsItems = CIBlockElement::GetList(array(), array("ID" => $intProductID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSIONS" => "Y", "MIN_PERMISSION" => "R"), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'XML_ID', 'DETAIL_PAGE_URL'));
    if (!($arProduct = $rsItems->GetNext())) {
        return false;
    }
    $arParentSku = CCatalogSku::GetProductInfo($intProductID, $arProduct['IBLOCK_ID']);
    if (!empty($arParentSku)) {
        if (strpos($arProduct["~XML_ID"], '#') === false) {
            $parentIterator = Iblock\ElementTable::getList(array('select' => array('ID', 'XML_ID'), 'filter' => array('ID' => $arParentSku['ID'])));
            if ($parent = $parentIterator->fetch()) {
                $arProduct["~XML_ID"] = $parent['XML_ID'] . '#' . $arProduct["~XML_ID"];
            }
            unset($parent, $parentIterator);
        }
    }
    $arPrice = array('PRICE' => 0.0, 'CURRENCY' => CSaleLang::GetLangCurrency(SITE_ID), 'VAT_RATE' => 0, 'PRODUCT_PRICE_ID' => 0, 'CATALOG_GROUP_NAME' => '');
    $arBuyerGroups = $USER->GetUserGroupArray();
    $arSubscrPrice = CCatalogProduct::GetOptimalPrice($intProductID, 1, $arBuyerGroups, "N", array(), SITE_ID, array());
    if (!empty($arSubscrPrice) && is_array($arSubscrPrice)) {
        $arPrice['PRICE'] = $arSubscrPrice['DISCOUNT_PRICE'];
        $arPrice['CURRENCY'] = CCurrency::GetBaseCurrency();
        $arPrice['VAT_RATE'] = $arSubscrPrice['PRICE']['VAT_RATE'];
        $arPrice['PRODUCT_PRICE_ID'] = $arSubscrPrice["PRICE"]["ID"];
        $arPrice['CATALOG_GROUP_NAME'] = $arSubscrPrice["PRICE"]["CATALOG_GROUP_NAME"];
    }
    $arProps = array();
    $strIBlockXmlID = (string) CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], 'XML_ID');
    if ($strIBlockXmlID !== '') {
        $arProps[] = array("NAME" => "Catalog XML_ID", "CODE" => "CATALOG.XML_ID", "VALUE" => $strIBlockXmlID);
    }
    if (!empty($arProductParams) && is_array($arProductParams)) {
        foreach ($arProductParams as &$arOneProductParams) {
            $arProps[] = array("NAME" => $arOneProductParams["NAME"], "CODE" => $arOneProductParams["CODE"], "VALUE" => $arOneProductParams["VALUE"], "SORT" => $arOneProductParams["SORT"]);
        }
        unset($arOneProductParams);
    }
    $arProps[] = array("NAME" => "Product XML_ID", "CODE" => "PRODUCT.XML_ID", "VALUE" => $arProduct["XML_ID"]);
    $arFields = array("PRODUCT_ID" => $intProductID, "PRODUCT_PRICE_ID" => $arPrice['PRODUCT_PRICE_ID'], "PRICE" => $arPrice['PRICE'], "CURRENCY" => $arPrice['CURRENCY'], "WEIGHT" => $arCatalogProduct["WEIGHT"], "DIMENSIONS" => serialize(array("WIDTH" => $arCatalogProduct["WIDTH"], "HEIGHT" => $arCatalogProduct["HEIGHT"], "LENGTH" => $arCatalogProduct["LENGTH"])), "QUANTITY" => 1, "LID" => SITE_ID, "DELAY" => "N", "CAN_BUY" => "N", "SUBSCRIBE" => "Y", "NAME" => $arProduct["~NAME"], "MODULE" => "catalog", "PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider", "NOTES" => $arPrice["CATALOG_GROUP_NAME"], "DETAIL_PAGE_URL" => $arProduct["~DETAIL_PAGE_URL"], "CATALOG_XML_ID" => $strIBlockXmlID, "PRODUCT_XML_ID" => $arProduct["~XML_ID"], "PROPS" => $arProps, "TYPE" => $arCatalogProduct["TYPE"] == CCatalogProduct::TYPE_SET ? CCatalogProductSet::TYPE_SET : NULL, "MEASURE_NAME" => $arCatalogProduct['MEASURE_NAME'], "MEASURE_CODE" => $arCatalogProduct['MEASURE_CODE'], 'IGNORE_CALLBACK_FUNC' => 'Y');
    if (!empty($arRewriteFields) && is_array($arRewriteFields)) {
        if (array_key_exists('SUBSCRIBE', $arRewriteFields)) {
            unset($arRewriteFields['SUBSCRIBE']);
        }
        if (array_key_exists('CAN_BUY', $arRewriteFields)) {
            unset($arRewriteFields['CAN_BUY']);
        }
        if (array_key_exists('DELAY', $arRewriteFields)) {
            unset($arRewriteFields['DELAY']);
        }
        if (!empty($arRewriteFields)) {
            $arFields = array_merge($arFields, $arRewriteFields);
        }
    }
    $mxBasketID = CSaleBasket::Add($arFields);
    if ($mxBasketID) {
        if (!isset($_SESSION['NOTIFY_PRODUCT'])) {
            $_SESSION['NOTIFY_PRODUCT'] = array($intUserID = array());
        } elseif (!isset($_SESSION['NOTIFY_PRODUCT'][$intUserID])) {
            $_SESSION['NOTIFY_PRODUCT'][$intUserID] = array();
        }
        $_SESSION["NOTIFY_PRODUCT"][$intUserID][$intProductID] = $intProductID;
        if (Loader::includeModule("statistic")) {
            CStatistic::Set_Event("sale2basket", "subscribe", $intProductID);
        }
    }
    return $mxBasketID;
}
Пример #13
0
 /**
  * Set values for property with type E(link to element).
  */
 protected function setElementValue()
 {
     $iblockList = $this->getListByType('E');
     $queryBuilder = new Entity\Query(Iblock\ElementTable::getEntity());
     $queryBuilder->setSelect(array('ID', 'NAME', 'IBLOCK_ID', 'IBLOCK_SECTION_ID'))->setFilter(array('IBLOCK_ID' => $iblockList))->setOrder(array());
     $elementResult = $queryBuilder->exec();
     while ($element = $elementResult->fetch()) {
         foreach ($this->iblockProperty as &$field) {
             if ($field['PROPERTY_TYPE'] != 'E') {
                 continue;
             }
             if ($field['LINK_IBLOCK_ID'] == $element['IBLOCK_ID']) {
                 $field['VALUE_LIST'][] = $element;
             }
         }
     }
 }
Пример #14
0
 protected static function getIblockFieldList()
 {
     $fieldCodeList = array('NAME', 'CODE', 'PREVIEW_TEXT', 'DETAIL_TEXT');
     $resultList = array();
     $entity = ElementTable::getEntity();
     foreach ($fieldCodeList as $fieldCode) {
         $field = $entity->getField($fieldCode);
         $resultList[] = array('ID' => $fieldCode, 'NAME' => $field->getTitle());
     }
     return $resultList;
 }
Пример #15
0
 protected function load()
 {
     $elementList = \Bitrix\Iblock\ElementTable::getList(array("select" => array("NAME"), "filter" => array("=ID" => $this->key)));
     $element = $elementList->fetch();
     if ($element) {
         return $element["NAME"];
     } else {
         return "";
     }
 }
Пример #16
0
 /**
  * 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);
         }
     }
 }
Пример #17
0
 protected function getSectionIdByElement($elementId, $elementCode = '')
 {
     $sectionId = 0;
     $elementId = (int) $elementId;
     $elementCode = (string) $elementCode;
     $filter = array('IBLOCK_ID' => $this->arParams['IBLOCK_ID']);
     if ($elementId > 0) {
         $filter['ID'] = $elementId;
     } elseif ($elementCode !== '') {
         $filter['=CODE'] = $elementCode;
     } else {
         return $sectionId;
     }
     $itemIterator = Iblock\ElementTable::getList(array('select' => array('ID', 'IBLOCK_SECTION_ID'), 'filter' => $filter));
     if ($item = $itemIterator->fetch()) {
         $sectionId = (int) $item['IBLOCK_SECTION_ID'];
     }
     return $sectionId;
 }
Пример #18
0
	public static function getProductList($offerID, $iblockID = 0)
	{
		$iblockID = (int)$iblockID;
		if (!is_array($offerID))
			$offerID = array($offerID);
		Collection::normalizeArrayValuesByInt($offerID);
		if (empty($offerID))
			return false;

		$iblockSku = array();
		$iblockOffers = array();
		if ($iblockID == 0)
		{
			$iblockList = array();
			$elementIterator = Iblock\ElementTable::getList(array(
				'select' => array('ID', 'IBLOCK_ID'),
				'filter' => array('=ID' => $offerID)
			));
			while ($element = $elementIterator->fetch())
			{
				$element['ID'] = (int)$element['ID'];
				$element['IBLOCK_ID'] = (int)$element['IBLOCK_ID'];
				if (!isset($iblockList[$element['IBLOCK_ID']]))
					$iblockList[$element['IBLOCK_ID']] = array();
				$iblockList[$element['IBLOCK_ID']][] = $element['ID'];
			}
			unset($element, $elementIterator);
			if (!empty($iblockList))
			{
				$iblockIterator = Catalog\CatalogIblockTable::getList(array(
					'select' => array('IBLOCK_ID', 'PRODUCT_IBLOCK_ID', 'SKU_PROPERTY_ID', 'VERSION' => 'IBLOCK.VERSION'),
					'filter' => array('=IBLOCK_ID' => array_keys($iblockList), '!PRODUCT_IBLOCK_ID' => 0)
				));
				while ($iblock = $iblockIterator->fetch())
				{
					$iblock['IBLOCK_ID'] = (int)$iblock['IBLOCK_ID'];
					$iblock['PRODUCT_IBLOCK_ID'] = (int)$iblock['PRODUCT_IBLOCK_ID'];
					$iblock['SKU_PROPERTY_ID'] = (int)$iblock['SKU_PROPERTY_ID'];
					$iblock['VERSION'] = (int)$iblock['VERSION'];
					$iblockSku[$iblock['IBLOCK_ID']] = $iblock;
					self::$arProductCache[$iblock['PRODUCT_IBLOCK_ID']] = $iblock;
					$iblockOffers[$iblock['IBLOCK_ID']] = $iblockList[$iblock['IBLOCK_ID']];
				}
				unset($iblock, $iblockIterator);
			}
			unset($iblockList);
		}
		else
		{
			$iblockIterator = Catalog\CatalogIblockTable::getList(array(
				'select' => array('IBLOCK_ID', 'PRODUCT_IBLOCK_ID', 'SKU_PROPERTY_ID', 'VERSION' => 'IBLOCK.VERSION'),
				'filter' => array('=IBLOCK_ID' => $iblockID, '!PRODUCT_IBLOCK_ID' => 0)
			));
			if ($iblock = $iblockIterator->fetch())
			{
				$iblock['IBLOCK_ID'] = (int)$iblock['IBLOCK_ID'];
				$iblock['PRODUCT_IBLOCK_ID'] = (int)$iblock['PRODUCT_IBLOCK_ID'];
				$iblock['SKU_PROPERTY_ID'] = (int)$iblock['SKU_PROPERTY_ID'];
				$iblock['VERSION'] = (int)$iblock['VERSION'];
				$iblockSku[$iblock['IBLOCK_ID']] = $iblock;
				self::$arProductCache[$iblock['PRODUCT_IBLOCK_ID']] = $iblock;
				$iblockOffers[$iblockID] = $offerID;
			}
			unset($iblock, $iblockIterator);
		}
		if (empty($iblockOffers))
			return array();

		$result = array_fill_keys($offerID, array());

		foreach ($iblockOffers as $iblockID => $offerList)
		{
			$skuProperty = 'PROPERTY_'.$iblockSku[$iblockID]['SKU_PROPERTY_ID'];
			$iblockFilter = array(
				'IBLOCK_ID' => $iblockID,
				'=ID' => $offerList
			);
			$iblockFields = array('ID', 'IBLOCK_ID', $skuProperty);
			$skuProperty .= '_VALUE';

			$offersIterator = CIBlockElement::GetList(
				array('ID' => 'ASC'),
				$iblockFilter,
				false,
				false,
				$iblockFields
			);
			while ($offer = $offersIterator->Fetch())
			{
				$currentOffer = (int)$offer['ID'];
				$productID = (int)$offer[$skuProperty];
				if (!isset($result[$currentOffer]) || $productID <= 0)
					continue;
				unset($offer[$skuProperty]);

				$result[$currentOffer] = array(
					'ID' => $productID,
					'IBLOCK_ID' => $iblockSku[$iblockID]['PRODUCT_IBLOCK_ID'],
					'OFFER_IBLOCK_ID' => $iblockID,
					'SKU_PROPERTY_ID' => $iblockSku[$iblockID]['SKU_PROPERTY_ID']
				);
			}
			unset($currentOffer, $offer, $offersIterator, $skuProperty);
		}

		unset($iblockID, $iblockOffers);

		return array_filter($result);
	}
Пример #19
0
 protected function separateItemsByIblock()
 {
     $this->iblockItems = array();
     $this->needItemProperties = array();
     if (empty($this->productIdsMap)) {
         return;
     }
     $itemsIterator = Iblock\ElementTable::getList(array('select' => array('ID', 'IBLOCK_ID'), 'filter' => array('@ID' => $this->productIdsMap)));
     while ($item = $itemsIterator->fetch()) {
         $item['ID'] = (int) $item['ID'];
         $item['IBLOCK_ID'] = (int) $item['IBLOCK_ID'];
         if (!isset($this->iblockItems[$item['IBLOCK_ID']])) {
             $this->iblockItems[$item['IBLOCK_ID']] = array();
         }
         $this->iblockItems[$item['IBLOCK_ID']][] = $item['ID'];
         if (!isset($this->needItemProperties[$item['IBLOCK_ID']])) {
             $this->needItemProperties[$item['IBLOCK_ID']] = isset($this->arParams['PROPERTY_CODE'][$item['IBLOCK_ID']]) && !empty($this->arParams['PROPERTY_CODE'][$item['IBLOCK_ID']]) || isset($this->arParams['ADDITIONAL_PICT_PROP'][$item['IBLOCK_ID']]) || isset($this->arParams['LABEL_PROP'][$item['IBLOCK_ID']]);
         }
     }
     unset($item, $itemsIterator);
 }
Пример #20
0
 public static function getProductIdsByOfferIds($offerIds)
 {
     if (empty($offerIds)) {
         return array();
     }
     $bestList = array();
     $iblockGroup = array();
     $itemIterator = \Bitrix\Iblock\ElementTable::getList(array('select' => array('ID', 'IBLOCK_ID'), 'filter' => array('ID' => $offerIds, 'ACTIVE' => 'Y')));
     while ($item = $itemIterator->fetch()) {
         if (!isset($iblockGroup[$item['IBLOCK_ID']])) {
             $iblockGroup[$item['IBLOCK_ID']] = array();
         }
         $iblockGroup[$item['IBLOCK_ID']][] = $item['ID'];
         $bestList[$item['ID']] = array();
     }
     if (empty($iblockGroup)) {
         return array();
     }
     $offerLink = array();
     foreach ($iblockGroup as $iblockId => $items) {
         $skuInfo = \CCatalogSKU::GetInfoByOfferIBlock($iblockId);
         if (empty($skuInfo)) {
             continue;
         }
         $offerItetator = \CIBlockElement::GetList(array(), array('IBLOCK_ID' => $iblockId, 'ID' => $items), false, false, array('ID', 'IBLOCK_ID', 'PROPERTY_' . $skuInfo['SKU_PROPERTY_ID']));
         while ($offer = $offerItetator->Fetch()) {
             $productId = (int) $offer['PROPERTY_' . $skuInfo['SKU_PROPERTY_ID'] . '_VALUE'];
             if ($productId <= 0) {
                 unset($bestList[$offer['ID']]);
             } else {
                 $bestList[$offer['ID']]['PARENT_ID'] = $productId;
                 $bestList[$offer['ID']]['PARENT_IBLOCK'] = $skuInfo['PRODUCT_IBLOCK_ID'];
                 if (!isset($offerLink[$productId])) {
                     $offerLink[$productId] = array();
                 }
                 $offerLink[$productId][] = $offer['ID'];
             }
         }
     }
     if (!empty($offerLink)) {
         $productIterator = \Bitrix\Iblock\ElementTable::getList(array('select' => array('ID'), 'filter' => array('@ID' => array_keys($offerLink), 'ACTIVE' => 'N')));
         while ($product = $productIterator->fetch()) {
             if (empty($offerLink[$product['ID']])) {
                 continue;
             }
             foreach ($offerLink[$product['ID']] as $value) {
                 unset($bestList[$value]);
             }
         }
     }
     if (empty($bestList)) {
         return array();
     }
     $finalIds = array();
     foreach ($bestList as $id => $info) {
         if (empty($info)) {
             $finalIds[] = $id;
         } else {
             $finalIds[] = $info['PARENT_ID'];
         }
     }
     return $finalIds;
 }
Пример #21
0
            "PAGER_TITLE" => "Страница",
            "PAGER_SHOW_ALL" => "N",
            "PAGER_BASE_LINK_ENABLE" => "N",
            "SET_STATUS_404" => "N",
            "SHOW_404" => "N",
            "MESSAGE_404" => ""
        )
    );?>
    <!--endajax-->
<?else:?>
    <?
    $parameters = array(
        'select'=>array('ID'),
        'filter'=>array('IBLOCK_ID'=>'2','CODE'=>$_REQUEST["ELEMENT_CODE"])
    );
    $EL = EL::getList($parameters)->fetchAll();
    $id_element = $EL[0]['ID'];
    $parameters = array(
        'filter'=>array('IBLOCK_ID'=>'2','ENTITY_ID'=>$id_element)
    );
    $rows = SEO::getList($parameters)->fetchAll();
    if(!empty($rows))
    {
        foreach($rows as $item)
        {
            switch ($item['CODE']) {
                case 'ELEMENT_META_TITLE':
                    $APPLICATION->SetPageProperty("title", $item['TEMPLATE']);
                    $APPLICATION->SetTitle($item['TEMPLATE']);
                    break;
            }
Пример #22
0
 public static function getItemsInfo(&$arSets)
 {
     $arItemList = array();
     if (empty($arSets) || !is_array($arSets)) {
         return;
     }
     foreach ($arSets as $key => $arOneSet) {
         foreach ($arOneSet['ITEMS'] as $keyItem => $arItem) {
             if ('' == $arItem['ITEM_ID']) {
                 continue;
             }
             $intItemID = (int) $arItem['ITEM_ID'];
             if (0 >= $intItemID) {
                 continue;
             }
             if (!isset($arItemList[$intItemID])) {
                 $arItemList[$intItemID] = array();
             }
             $arItemList[$intItemID][] = array('SET' => $key, 'ITEM' => $keyItem);
         }
     }
     if (!empty($arItemList)) {
         $arFilter = array('@ID' => array_keys($arItemList));
         $productIterator = Iblock\ElementTable::getList(array('select' => array('ID', 'NAME'), 'filter' => $arFilter));
         while ($arProduct = $productIterator->fetch()) {
             $arProduct['ID'] = (int) $arProduct['ID'];
             if (isset($arItemList[$arProduct['ID']])) {
                 foreach ($arItemList[$arProduct['ID']] as $arOneKey) {
                     $arSets[$arOneKey['SET']]['ITEMS'][$arOneKey['ITEM']]['ITEM_NAME'] = $arProduct['NAME'];
                 }
             }
         }
         unset($arProduct, $productIterator);
     }
 }
Пример #23
0
    private function importOffers($arOffers = array())
    {
        // в эту переменную будем кэшировать выборку из инфоблока модификаторов
        $arCache = array();
        foreach ($arOffers as $arElement)
        {
            foreach ($arElement['OFFERS'] as $arModifier)
            {
                $sectionKey = $arModifier['XML_ID'];
                $elementKey = $arModifier['VALUE_XML_ID'];

                $boolCached = isset($arCache[$sectionKey]);
                if (strlen($elementKey) > 0)
                {
                    $boolCached = isset($arCache[$sectionKey][$elementKey]);
                }
                if (!$boolCached)
                {
                    $params = array(
                        'select' => array('ID', 'XML_ID'),
                        'filter' => array(
                            '=IBLOCK_ID'      => $this->OFFERS_ID,
                            '=SECTION.XML_ID' => $sectionKey
                        ),
                        'runtime' => array(
                            new ReferenceField(
                                'SECTION',
                                '\Bitrix\Iblock\SectionTable',
                                array('=this.IBLOCK_SECTION_ID' => 'ref.ID'),
                                array('join_type' => 'LEFT')
                            )
                        )
                    );
                    if (strlen($elementKey) > 0)
                    {
                        $params['filter']['=XML_ID'] = $elementKey;
                    }

                    $result = ElementTable::getList($params);
                    while ($row = $result->fetch())
                    {
                        $arCache[$sectionKey][$row['XML_ID']] = $row['ID'];
                    }
                }

                foreach ($arCache[$sectionKey] as $modifierID)
                {
                    ElementModifiers::add($arElement['ID'], $modifierID, $arModifier['REQUIRED']);
                }
            }
        }
    }
Пример #24
0
 }
 if (!empty($element) && $parentId > 0) {
     $bBasketUpdate = false;
     $arPropsValues["CML2_LINK"] = $parentId;
     $newProductId = getProductByProps($element['IBLOCK_ID'], $arPropsValues, true);
     if (!empty($newProductId)) {
         if ($productProvider = CSaleBasket::GetProductProvider($arItem)) {
             $arFieldsTmp = $productProvider::GetProductData(array("PRODUCT_ID" => $newProductId['ID'], "QUANTITY" => $arItem['QUANTITY'], "RENEWAL" => "N", "USER_ID" => $USER->GetID(), "SITE_ID" => SITE_ID, "BASKET_ID" => $arItem['ID'], "CHECK_QUANTITY" => "Y", "CHECK_PRICE" => "Y", "NOTES" => $arItem["NOTES"]));
         } elseif (isset($arItem["CALLBACK_FUNC"]) && !empty($arItem["CALLBACK_FUNC"])) {
             $arFieldsTmp = CSaleBasket::ExecuteCallbackFunction($arItem["CALLBACK_FUNC"], $arItem["MODULE"], $newProductId['ID'], $arItem['QUANTITY'], "N", $USER->GetID(), SITE_ID);
         }
         if (!empty($arFieldsTmp) && is_array($arFieldsTmp)) {
             $arFields = array('PRODUCT_ID' => $newProductId['ID'], 'PRODUCT_PRICE_ID' => $arFieldsTmp["PRODUCT_PRICE_ID"], 'PRICE' => $arFieldsTmp["PRICE"], 'CURRENCY' => $arFieldsTmp["CURRENCY"], 'QUANTITY' => $arFieldsTmp['QUANTITY'], 'WEIGHT' => $arFieldsTmp['WEIGHT']);
             $arProps = array();
             if (strpos($newProductId['XML_ID'], '#') === false) {
                 $parentIterator = \Bitrix\Iblock\ElementTable::getList(array('select' => array('ID', 'XML_ID'), 'filter' => array('ID' => $parentId)));
                 if ($parentProduct = $parentIterator->fetch()) {
                     $newProductId['XML_ID'] = $parentProduct['XML_ID'] . '#' . $newProductId['XML_ID'];
                 }
                 unset($parentProduct, $parentIterator);
             }
             $arFields["PRODUCT_XML_ID"] = $newProductId['XML_ID'];
             $propertyIterator = \Bitrix\Iblock\PropertyTable::getList(array('select' => array('ID', 'CODE'), 'filter' => array('IBLOCK_ID' => $newProductId['IBLOCK_ID'], '!ID' => $sku['SKU_PROPERTY_ID'])));
             while ($property = $propertyIterator->fetch()) {
                 $property['CODE'] = (string) $property['CODE'];
                 $arPropsSku[] = $property['CODE'] != '' ? $property['CODE'] : $property['ID'];
             }
             unset($property, $propertyIterator);
             $product_properties = CIBlockPriceTools::GetOfferProperties($newProductId['ID'], $sku['PRODUCT_IBLOCK_ID'], $arPropsSku);
             $newValues = array();
             foreach ($product_properties as $productSkuProp) {
Пример #25
0
 /**
  * Loads values from database.
  * Returns true on success.
  *
  * @return boolean
  */
 protected function loadFromDatabase()
 {
     if (!isset($this->fields)) {
         //Element fields
         $elementList = \Bitrix\Iblock\ElementTable::getList(array("select" => array_values($this->fieldMap), "filter" => array("=ID" => $this->id)));
         $this->fields = $elementList->fetch();
     }
     return is_array($this->fields);
 }
Пример #26
0
 public static function getList(array $parameters = array())
 {
     $arSelect =& $parameters['select'];
     if (!static::$_metadata) {
         static::$_metadata = static::getMetadata();
     }
     $iblockId = static::$IBLOCK_ID;
     $arProps = static::$_metadata['props'];
     $arPropCodesMap = array_flip(static::$arPropsAlias);
     $bHasMultiple = false;
     foreach ($arProps as $propCode => $arProp) {
         if ($arProp['MULTIPLE'] == 'Y') {
             $alias = static::$arPropsAlias[$propCode];
             if (($key = array_search($alias, $arSelect)) !== false) {
                 $arSelect[$key] = $alias . self::postfixToArray;
                 $bHasMultiple = true;
             }
         }
     }
     if ($bHasMultiple && !array_intersect([static::$arFieldsAlias['ID'], 'ID'], $arSelect)) {
         $arSelect[] = static::$arFieldsAlias['ID'];
     }
     if (!array_intersect([static::$arFieldsAlias['ID'], 'ID'], $parameters['group'])) {
         $parameters['group'][] = 'ID';
     }
     $parameters['filter']['IBLOCK_ID'] = static::$IBLOCK_ID;
     $dbRes = parent::getList($parameters);
     $dbRes->addFetchDataModifier(function (&$arItem) use($arProps, $arPropCodesMap, $arSelect, $iblockId) {
         global $DB;
         $arPropsUpdate = [];
         //Массив для обновления свойств в таблице b_iblock_element_prop_s*. Обновляется по аналогии с CIBlockResult::fetch.
         $id = intval($arItem[static::$arFieldsAlias['ID']] ?: $arItem['ID']);
         foreach ($arItem as $key => $value) {
             $selectAlias = $arSelect[$key];
             $fieldName = $selectAlias ?: $key;
             $bMultipleField = substr($fieldName, -strlen(self::postfixToArray)) === self::postfixToArray;
             if ($bMultipleField) {
                 $alias = str_replace(self::postfixToArray, '', $fieldName);
                 if ($value === null && $id && $iblockId) {
                     $propCode = $arPropCodesMap[$alias];
                     $propId = intval($arProps[$propCode]['ID']);
                     if ($propId) {
                         $strSql = "\n\t\t\t\t\t\t\t\tSELECT ID, VALUE, DESCRIPTION\n\t\t\t\t\t\t\t\tFROM b_iblock_element_prop_m{$iblockId}\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tIBLOCK_ELEMENT_ID = {$id}\n\t\t\t\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID = {$propId}\n\t\t\t\t\t\t\t\tORDER BY ID\n\t\t\t\t\t\t\t";
                         $dbPropVals = $DB->Query($strSql);
                         $arPropVals = ['ID' => [], 'VALUE' => [], 'DESCRIPTION' => []];
                         while ($arPropVal = $dbPropVals->Fetch()) {
                             $arPropVals['ID'][] = $arPropVal['ID'];
                             $arPropVals['VALUE'][] = $arPropVal['VALUE'];
                             $arPropVals['DESCRIPTION'][] = $arPropVal['DESCRIPTION'];
                         }
                         $arPropsUpdate["b_iblock_element_prop_s{$iblockId}"]["PROPERTY_{$propId}"] = serialize($arPropVals);
                         $value = $arPropVals['VALUE'];
                     }
                 }
                 unset($arItem[$key]);
                 $arItem[$selectAlias ? $key : $alias] = $value;
             }
         }
         foreach ($arPropsUpdate as $strTable => $arFields) {
             if ($strUpdate = $DB->PrepareUpdate($strTable, $arFields)) {
                 $strSql = "UPDATE {$strTable} SET {$strUpdate} WHERE IBLOCK_ELEMENT_ID = {$id}";
                 $DB->QueryBind($strSql, $arFields);
             }
         }
     });
     return $dbRes;
 }
Пример #27
0
 public static function getProductIdsByOfferIds($offerIds)
 {
     if (empty($offerIds)) {
         return array();
     }
     $bestList = array();
     $iblockGroup = array();
     $itemIterator = \Bitrix\Iblock\ElementTable::getList(array('select' => array('ID', 'IBLOCK_ID'), 'filter' => array('ID' => $offerIds, 'ACTIVE' => 'Y')));
     while ($item = $itemIterator->fetch()) {
         if (!isset($iblockGroup[$item['IBLOCK_ID']])) {
             $iblockGroup[$item['IBLOCK_ID']] = array();
         }
         $iblockGroup[$item['IBLOCK_ID']][] = $item['ID'];
         $bestList[$item['ID']] = array();
     }
     if (empty($iblockGroup)) {
         return array();
     }
     $iblockSku = array();
     $iblockOffers = array();
     if (!empty($iblockGroup)) {
         $iblockIterator = \Bitrix\Catalog\CatalogIblockTable::getList(array('select' => array('IBLOCK_ID', 'PRODUCT_IBLOCK_ID', 'SKU_PROPERTY_ID', 'VERSION' => 'IBLOCK.VERSION'), 'filter' => array('=IBLOCK_ID' => array_keys($iblockGroup), '!PRODUCT_IBLOCK_ID' => 0)));
         while ($iblock = $iblockIterator->fetch()) {
             $iblock['IBLOCK_ID'] = (int) $iblock['IBLOCK_ID'];
             $iblock['PRODUCT_IBLOCK_ID'] = (int) $iblock['PRODUCT_IBLOCK_ID'];
             $iblock['SKU_PROPERTY_ID'] = (int) $iblock['SKU_PROPERTY_ID'];
             $iblock['VERSION'] = (int) $iblock['VERSION'];
             $iblockSku[$iblock['IBLOCK_ID']] = $iblock;
             $iblockOffers[$iblock['IBLOCK_ID']] = $iblockGroup[$iblock['IBLOCK_ID']];
         }
         unset($iblock, $iblockIterator);
     }
     if (empty($iblockOffers)) {
         return array();
     }
     $offerLink = array();
     foreach ($iblockOffers as $iblockId => $items) {
         $skuProperty = 'PROPERTY_' . $iblockSku[$iblockId]['SKU_PROPERTY_ID'];
         $iblockFilter = array('IBLOCK_ID' => $iblockId, '=ID' => $items);
         $iblockFields = array('ID', 'IBLOCK_ID', $skuProperty);
         $skuProperty .= '_VALUE';
         $offersIterator = \CIBlockElement::getList(array('ID' => 'ASC'), $iblockFilter, false, false, $iblockFields);
         while ($offer = $offersIterator->Fetch()) {
             $productId = (int) $offer[$skuProperty];
             if ($productId <= 0) {
                 unset($bestList[$offer['ID']]);
             } else {
                 $bestList[$offer['ID']]['PARENT_ID'] = $productId;
                 $bestList[$offer['ID']]['PARENT_IBLOCK'] = $iblockSku[$iblockId]['PRODUCT_IBLOCK_ID'];
                 if (!isset($offerLink[$productId])) {
                     $offerLink[$productId] = array();
                 }
                 $offerLink[$productId][] = $offer['ID'];
             }
         }
     }
     if (!empty($offerLink)) {
         $productIterator = \Bitrix\Iblock\ElementTable::getList(array('select' => array('ID'), 'filter' => array('@ID' => array_keys($offerLink), 'ACTIVE' => 'N')));
         while ($product = $productIterator->fetch()) {
             if (empty($offerLink[$product['ID']])) {
                 continue;
             }
             foreach ($offerLink[$product['ID']] as $value) {
                 unset($bestList[$value]);
             }
         }
     }
     if (empty($bestList)) {
         return array();
     }
     $finalIds = array();
     $dublicate = array();
     foreach ($bestList as $id => $info) {
         if (empty($info)) {
             if (!isset($dublicate[$id])) {
                 $finalIds[] = $id;
             }
             $dublicate[$id] = true;
         } else {
             if (!isset($dublicate[$id])) {
                 $finalIds[] = $info['PARENT_ID'];
             }
             $dublicate[$info['PARENT_ID']] = true;
         }
     }
     unset($id, $info, $dublicate);
     return $finalIds;
 }
Пример #28
0
 public function getBlockElementByCode($CODE)
 {
     $listIBlockElement = \Bitrix\Iblock\ElementTable::getList(array('select' => array(), 'filter' => array("CODE" => $this->{$CODE}, "ACTIVE" => "Y")));
     return $IBlockElement = $listIBlockElement->Fetch();
 }
				"LINK_TYPE", "LINK_ID",
				"ELEMENT_NAME" => "IBLOCK_ELEMENT.NAME",
				"ELEMENT_IBLOCK_ID" => "IBLOCK_ELEMENT.IBLOCK_ID",
				"ELEMENT_IBLOCK_TYPE_ID" => "IBLOCK_ELEMENT.IBLOCK.IBLOCK_TYPE_ID",
				'ELEMENT_IBLOCK_SECTION_ID' => 'IBLOCK_ELEMENT.IBLOCK_SECTION_ID',
			)
		));
	}
	else
	{
		$dbRes = \Bitrix\Iblock\ElementTable::getList(array(
			'filter' => array(
				"=ID" => $elementId,
			),
			'select' => array(
				'LINK_ID' => 'ID',
				'ELEMENT_NAME' => 'NAME',
				'ELEMENT_IBLOCK_ID' => 'IBLOCK_ID',
				'ELEMENT_IBLOCK_TYPE_ID' => 'IBLOCK.IBLOCK_TYPE_ID',
				'ELEMENT_IBLOCK_SECTION_ID' => 'IBLOCK_SECTION_ID',
			)
		));
	}

	$arLinks = array();
	while($link = $dbRes->fetch())
	{
		if(!isset($link['LINK_TYPE']) && $elementId > 0)
		{
			$link['LINK_TYPE'] = Adv\LinkTable::TYPE_IBLOCK_ELEMENT;
		}
Пример #30
0
 public static function getItemsInfo(&$arSets)
 {
     $itemList = array();
     $itemIds = array();
     if (empty($arSets) || !is_array($arSets)) {
         return;
     }
     foreach ($arSets as $key => $arOneSet) {
         foreach ($arOneSet['ITEMS'] as $keyItem => $arItem) {
             if ('' == $arItem['ITEM_ID']) {
                 continue;
             }
             $intItemID = (int) $arItem['ITEM_ID'];
             if (0 >= $intItemID) {
                 continue;
             }
             if (!isset($itemList[$intItemID])) {
                 $itemList[$intItemID] = array();
                 $itemIds[] = $intItemID;
             }
             $itemList[$intItemID][] =& $arSets[$key]['ITEMS'][$keyItem];
         }
     }
     if (!empty($itemList)) {
         $productIterator = Iblock\ElementTable::getList(array('select' => array('ID', 'NAME'), 'filter' => array('@ID' => $itemIds)));
         while ($product = $productIterator->fetch()) {
             $product['ID'] = (int) $product['ID'];
             if (!isset($itemList[$product['ID']])) {
                 continue;
             }
             foreach ($itemList[$product['ID']] as &$setItem) {
                 $setItem['ITEM_NAME'] = $product['NAME'];
             }
             unset($setItem);
         }
         unset($product, $productIterator);
         $productRatio = Catalog\ProductTable::getCurrentRatioWithMeasure($itemIds);
         if (!empty($productRatio)) {
             foreach ($productRatio as $productId => $productData) {
                 if (!isset($itemList[$productId])) {
                     continue;
                 }
                 foreach ($itemList[$productId] as &$setItem) {
                     $setItem['RATIO'] = $productData['RATIO'];
                     $setItem['MEASURE'] = $productData['MEASURE'];
                 }
                 unset($setItem);
             }
             unset($productId, $productData);
         }
         unset($productRatio);
     }
     unset($itemIds, $itemList);
 }