![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Cnc/ShopbyBrand/Plugin/Block/Widget/ |
<?php /** * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved. * https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * <[email protected]> */ declare(strict_types=1); namespace Cnc\ShopbyBrand\Plugin\Block\Widget; use Amasty\ShopbyBrand\Block\Widget\BrandList as OriginalBrandList; use Closure; use Exception; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Framework\UrlInterface; use Magento\Store\Model\StoreManagerInterface; use Psr\Log\LoggerInterface; class BrandList { /** * @var array */ private $items; /** * @var CategoryRepositoryInterface */ private $categoryRepository; /** * @var StoreManagerInterface */ private $storeManager; /** * @var UrlInterface */ private $url; /** * @var LoggerInterface */ private $logger; /** * BrandList constructor. * @param CategoryRepositoryInterface $categoryRepository * @param StoreManagerInterface $storeManager * @param UrlInterface $url * @param LoggerInterface $logger */ public function __construct( CategoryRepositoryInterface $categoryRepository, StoreManagerInterface $storeManager, UrlInterface $url, LoggerInterface $logger ) { $this->categoryRepository = $categoryRepository; $this->storeManager = $storeManager; $this->url = $url; $this->logger = $logger; } /** * @override native getItems method, in order to change data source * from product manufacturer attribute values to level 1 categories * * @param OriginalBrandList $subject * @param Closure $proceed * @return array * */ public function aroundGetItems(OriginalBrandList $subject, Closure $proceed): array { if ($this->items === null) { $items = []; try { $rootCategory = $this->categoryRepository->get( $this->storeManager->getStore()->getRootCategoryId() ); $topLevelCategories = $rootCategory->getChildrenCategories(); foreach ($topLevelCategories as $category) { $items[] = [ 'brandId' => $category->getId(), 'label' => $category->getName(), 'url' => $this->url->getBaseUrl() . $category->getRequestPath(), 'img' => '', 'image' => '', 'description' => '', 'short_description' => '', 'cnt' => 0, 'alt' => $category->getName(), ]; } } catch (Exception $e) { $this->logger->warning($e->getMessage()); } $this->items = $items; } return $this->items; } }