Skip to content

Commit

Permalink
Merge pull request #849 from Nosto/spx_optimization_category
Browse files Browse the repository at this point in the history
Change select attribute, get category name only instead of all data f…
  • Loading branch information
supercid authored Apr 10, 2024
2 parents ed09840 + c495665 commit cc20c15
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 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 @@ -111,10 +105,11 @@ public function getCategory(Category $category, StoreInterface $store)
}

$categories = $this->categoryCollectionFactory->create()
->addAttributeToSelect('*')
->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 cc20c15

Please sign in to comment.