Skip to content

Commit

Permalink
Category service - Add level to get category attribute select, remove…
Browse files Browse the repository at this point in the history
… category repository from class
  • Loading branch information
supercid committed Apr 9, 2024
1 parent aba652a commit 81bab9c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions Model/Service/Product/Category/DefaultCategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
namespace Nosto\Tagging\Model\Service\Product\Category;

use Exception;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
use Magento\Catalog\Model\ResourceModel\Category\Collection;
use Magento\Framework\Event\ManagerInterface;
use Magento\Store\Api\Data\StoreInterface;
use Nosto\Tagging\Logger\Logger as NostoLogger;
Expand All @@ -50,24 +48,20 @@ class DefaultCategoryService implements CategoryServiceInterface
{

private NostoLogger $logger;
private CategoryRepositoryInterface $categoryRepository;
private CollectionFactory $categoryCollectionFactory;
private ManagerInterface $eventManager;

/**
* Builder constructor.
* @param CategoryRepositoryInterface $categoryRepository
* @param CollectionFactory $categoryCollectionFactory
* @param NostoLogger $logger
* @param ManagerInterface $eventManager
*/
public function __construct(
CategoryRepositoryInterface $categoryRepository,
CollectionFactory $categoryCollectionFactory,
NostoLogger $logger,
ManagerInterface $eventManager
) {
$this->categoryRepository = $categoryRepository;
$this->categoryCollectionFactory = $categoryCollectionFactory;
$this->logger = $logger;
$this->eventManager = $eventManager;
Expand Down Expand Up @@ -112,9 +106,10 @@ public function getCategory(Category $category, StoreInterface $store)

$categories = $this->categoryCollectionFactory->create()
->addAttributeToSelect('name')
->addAttributeToSelect('level')
->addAttributeToFilter('entity_id', $categoryIds)
->setStore($store->getId())
->addAttributeToSort('level', Collection::SORT_ORDER_ASC);
->addAttributeToSort('level');
foreach ($categories as $cat) {
if ($cat instanceof Category
&& $cat->getLevel() > 1
Expand All @@ -135,7 +130,6 @@ public function getCategory(Category $category, StoreInterface $store)
['categoryString' => $nostoCategory, 'magentoCategory' => $category]
);
}

return $nostoCategory;
}

Expand Down

0 comments on commit 81bab9c

Please sign in to comment.