Skip to content

Commit

Permalink
Adapat code for category reindex
Browse files Browse the repository at this point in the history
  • Loading branch information
ugljesaspx committed Nov 1, 2024
1 parent 7a2d8ee commit ee3b5b5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
54 changes: 28 additions & 26 deletions Model/Category/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,11 @@ public function getByIds(array $ids)
}

/**
* @param Store $store
* @param array $categoryIds
*
* @return CategoryCollection
* @throws LocalizedException
*/
public function getCategoryCollectionQuery(Store $store, array $categoryIds = [])
{
$categories = $this->categoryCollectionFactory->create()
->distinct(true)
->addNameToResult()
->setStoreId($store->getId())
->addUrlRewriteToResult()
->addAttributeToFilter('level', ['gt' => 1])
->addAttributeToSelect(array_merge(['name', 'is_active', 'include_in_menu']))
->addOrderField('entity_id');

if ($categoryIds) {
$categories->addAttributeToFilter('entity_id', ['in' => $categoryIds]);
}

return $categories;
}

/**
* Gets the parent category ID's for a given category
* Gets the parent category ID's for a given category
*
* @param CategoryInterface $category
* @return string[]|null
*
* @throws ParentCategoryDisabledException
*/
public function resolveParentCategoryIds(CategoryInterface $category): ?array
Expand All @@ -139,6 +116,31 @@ public function resolveParentCategoryIds(CategoryInterface $category): ?array
return $parentCategoryIds;
}

/**
* @param Store $store
* @param array $categoryIds
*
* @return CategoryCollection
* @throws LocalizedException
*/
public function getCategoryCollectionQuery(Store $store, array $categoryIds = [])
{
$categories = $this->categoryCollectionFactory->create()
->distinct(true)

Check warning on line 129 in Model/Category/Repository.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Possible slow SQL method distinct detected
->addNameToResult()
->setStoreId($store->getId())
->addUrlRewriteToResult()
->addAttributeToFilter('level', ['gt' => 1])
->addAttributeToSelect(array_merge(['name', 'is_active', 'include_in_menu']))
->addOrderField('entity_id');

if ($categoryIds) {
$categories->addAttributeToFilter('entity_id', ['in' => $categoryIds]);
}

return $categories;
}

/**
* Get Parent Category IDS
*
Expand Down
1 change: 1 addition & 0 deletions Model/Service/Update/CategoryUpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private function toParentCategoryIds(CategoryCollection $collection): array
/** @var CategoryInterface $category */
foreach ($collection->getItems() as $category) {
try {
/** @phan-suppress-next-line PhanTypeMismatchArgument */
$parents = $this->nostoCategoryRepository->resolveParentCategoryIds($category);
} catch (ParentCategoryDisabledException $e) {
$this->getLogger()->debug($e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion etc/indexer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</indexer>
<indexer id="nosto_index_category" view_id="nosto_index_category" class="Nosto\Tagging\Model\Indexer\CategoryIndexer">
<title>Nosto Category Indexer</title>
<!-- @TODO: Add description-->
<description>Populates message queue with category ids to be sent to Nosto</description>
<description>Category</description>
</indexer>
</config>

0 comments on commit ee3b5b5

Please sign in to comment.