diff --git a/Model/Category/Repository.php b/Model/Category/Repository.php index ec22a9b3e..21cc14309 100644 --- a/Model/Category/Repository.php +++ b/Model/Category/Repository.php @@ -37,6 +37,7 @@ namespace Nosto\Tagging\Model\Category; use Magento\Catalog\Api\Data\CategoryInterface; +use Magento\Catalog\Model\Category; use Magento\Catalog\Model\CategoryRepository; use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection; use Magento\Framework\Api\SearchCriteriaBuilder; @@ -84,7 +85,6 @@ public function getByIds(array $ids) //@TODO implement } - /** * @param Store $store * @param array $categoryIds @@ -110,15 +110,13 @@ public function getCategoryCollectionQuery(Store $store, array $categoryIds = [] return $categories; } - /** * Gets the parent category ID's for a given category * - * @param CategoryInterface $category * @return string[]|null * @throws ParentCategoryDisabledException */ - public function resolveParentCategoryIds(CategoryInterface $category) + public function resolveParentCategoryIds(Category $category): ?array { if ($this->getParentIdsFromCache($category)) { return $this->getParentIdsFromCache($category); @@ -135,14 +133,13 @@ public function resolveParentCategoryIds(CategoryInterface $category) $parentCategoryIds = null; if ($category->getLevel() >= 1) { - //@TODO: get parents from root category, check if this works $parentCategoryIds = $category->getParentIds(); $this->saveParentIdsToCache($category, $parentCategoryIds); } + return $parentCategoryIds; } - /** * Get parent ids from cache. Return null if the cache is not available * diff --git a/Model/ResourceModel/Magento/Category/Collection.php b/Model/ResourceModel/Magento/Category/Collection.php index d3b3dac93..44703b881 100644 --- a/Model/ResourceModel/Magento/Category/Collection.php +++ b/Model/ResourceModel/Magento/Category/Collection.php @@ -36,27 +36,27 @@ namespace Nosto\Tagging\Model\ResourceModel\Magento\Category; -//use Magento\Catalog\Model\Category\Attribute\Source\Status; use Magento\Catalog\Model\ResourceModel\Category\Collection as MagentoCategoryCollection; +use Magento\Framework\Exception\LocalizedException; class Collection extends MagentoCategoryCollection { /** * @return Collection + * @throws LocalizedException */ - public function addActiveFilter() + public function addActiveFilter(): Collection { - // @TODO: Here should be included in the menu return $this->addAttributeToFilter('status', ['eq' => 1]); } /** * @param array $ids * @return Collection + * @throws LocalizedException */ - public function addIdsToFilter(array $ids) + public function addIdsToFilter(array $ids): Collection { - return $this->addAttributeToFilter($this->getIdFieldName(), ['in' => $ids]); } } diff --git a/Model/Service/Update/CategoryUpdateService.php b/Model/Service/Update/CategoryUpdateService.php index 7f9fa4e8a..aeac25f20 100644 --- a/Model/Service/Update/CategoryUpdateService.php +++ b/Model/Service/Update/CategoryUpdateService.php @@ -38,6 +38,7 @@ use Exception; use Magento\Catalog\Api\Data\CategoryInterface; +use Magento\Catalog\Model\Category; use Magento\Store\Model\Store; use Nosto\NostoException; use Nosto\Tagging\Exception\ParentCategoryDisabledException; @@ -124,7 +125,7 @@ public function addCollectionToUpdateMessageQueue(CategoryCollection $collection private function toParentCategoryIds(CategoryCollection $collection): array { $categoryIds = []; - /** @var CategoryInterface $category */ + /** @var Category $category */ foreach ($collection->getItems() as $category) { try { $parents = $this->nostoCategoryRepository->resolveParentCategoryIds($category);