Created
April 26, 2019 10:23
-
-
Save anoriar/fa48a34160f2904a1a450b125fc3639d to your computer and use it in GitHub Desktop.
elastic index all + sort by cities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function indexModels($arFilter, $indexToReindex = false, $deleteNotExistsOffers = false) | |
{ | |
if ($indexToReindex) { | |
$index = $indexToReindex; | |
} else { | |
$index = $this->index; | |
} | |
// получим товары | |
$arModels = $this->getModels($arFilter); | |
$arProductsId = array_unique(Util::getAssocArrItemsKey($arModels)); | |
//NEW | |
$allShopSections = $this->getAllShopsSections(); | |
foreach ($arModels as &$model) { | |
foreach ($allShopSections as $shopSection) { | |
$model['SORT_' . $shopSection] = 40; | |
} | |
} | |
unset($model); | |
//NEW | |
// установим секции для товаров | |
$this->setSections($arModels, $arProductsId); | |
// получим тп | |
$arOffers = $this->getOfferPacks($arProductsId); | |
$arOffersId = array_unique(array_keys($arOffers)); | |
// формируем правильную структуру для индекса | |
$arOffersDocs = $this->createOfferDocs($arOffers); | |
$arModelDocs = $this->createModelDocs($arModels, $arOffersDocs); | |
// индексируем данные | |
$this->sendModels($index, $arModelDocs); | |
$this->sendOffers($index, $arOffersDocs); | |
if($deleteNotExistsOffers && !empty($arProductsId)) { | |
$this->deleteNotExistsOffers($index, $arProductsId, $arOffersId); | |
} | |
} | |
public function __construct($code) | |
{ | |
$this->config = new Config(); | |
$this->timer = new Timer(); | |
$this->elastic = Manager::buildClient(); | |
$index = Manager::getIndex($code); | |
$this->index = $index; | |
$externalCatalogCode = str_replace(Manager::$reservePrefix, '', $code); | |
$this->iblockModels = Prototype::getInstanceByXmlId($externalCatalogCode); | |
$arInfoByProductIBlock = \CCatalogSKU::GetInfoByProductIBlock($this->iblockModels->getId()); | |
if ($arInfoByProductIBlock['IBLOCK_ID']) { // у каталога есть иб с тп | |
$this->iblockOffers = Prototype::getInstanceById($arInfoByProductIBlock['IBLOCK_ID']); | |
} else { | |
$this->iblockOffers = Prototype::getInstanceByXmlId($externalCatalogCode); | |
$this->setCatalogHasOffersIblock(false); | |
} | |
$this->propsModels = $this->getProps($this->iblockModels->getId()); | |
$this->propsOffers = $this->getProps($this->iblockOffers->getId()); | |
//NEW | |
$sections = $this->getAllShopsSections(); | |
foreach($sections as $section){ | |
$this->selectModels[] = 'SORT_' . $section; | |
} | |
//NEW | |
$this->catalogGroups = Price::getInstance()->getElements( | |
[ | |
'cacheTime' => 0, | |
'filter' => ['!XML_ID' => false], | |
'select' => $this->selectGroups, | |
'indexArray' => 'ID', | |
'group' => false | |
] | |
); | |
$this->generateSelectFields(); | |
//$this->filter = ['IBLOCK_ID' => $this->iblockModels->getId()]; | |
$this->filter = ['IBLOCK_ID' => $this->iblockModels->getId(), "ACTIVE" => "Y"]; | |
$this->logger = new Logger(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment