![]() 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/Catalog/Block/Product/ |
<?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) * Cnc * Radosław Stępień <[email protected]> <[email protected]> */ namespace Cnc\Catalog\Block\Product; use Cnc\Catalog\Helper\Data as CncCatalogHelper; use Cnc\Catalog\Model\Config; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Block\Product\Context; use Magento\Catalog\Block\Product\View; use Magento\Catalog\Helper\Product; use Magento\Catalog\Model\Category; use Magento\Catalog\Model\ProductTypes\ConfigInterface; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; use Magento\Customer\Model\Session; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Json\EncoderInterface as JsonEncoderInterface; use Magento\Framework\Locale\FormatInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Framework\Stdlib\StringUtils; use Magento\Framework\Url\EncoderInterface; class BrandLogo extends View { /** @var CollectionFactory */ protected $categoryCollectionFactory; /** * @var CncCatalogHelper */ protected $cncCatalogHelper; /** * BrandLogo constructor. * @param Context $context * @param EncoderInterface $urlEncoder * @param JsonEncoderInterface $jsonEncoder * @param StringUtils $string * @param Product $productHelper * @param ConfigInterface $productTypeConfig * @param FormatInterface $localeFormat * @param Session $customerSession * @param ProductRepositoryInterface $productRepository * @param PriceCurrencyInterface $priceCurrency * @param CollectionFactory $categoryCollectionFactory * @param CncCatalogHelper $cncCatalogHelper * @param array $data */ public function __construct( Context $context, EncoderInterface $urlEncoder, JsonEncoderInterface $jsonEncoder, StringUtils $string, Product $productHelper, ConfigInterface $productTypeConfig, FormatInterface $localeFormat, Session $customerSession, ProductRepositoryInterface $productRepository, PriceCurrencyInterface $priceCurrency, CollectionFactory $categoryCollectionFactory, CncCatalogHelper $cncCatalogHelper, array $data = [] ) { parent::__construct( $context, $urlEncoder, $jsonEncoder, $string, $productHelper, $productTypeConfig, $localeFormat, $customerSession, $productRepository, $priceCurrency, $data ); $this->categoryCollectionFactory = $categoryCollectionFactory; $this->cncCatalogHelper = $cncCatalogHelper; } /** * @return mixed * @throws LocalizedException */ public function getBrandLogoUrl() { $brandCategory = $this->getBrandCategory(); return $brandCategory->getImageUrl(); } /** * @throws LocalizedException */ public function getBrandCategory() { $brandName = $this->cncCatalogHelper->getAttributeText( $this->getProduct(), Config::PRODUCT_ATTRIBUTE_CODE_MANUFACTURER ); $categoryCollection = $this->categoryCollectionFactory->create(); $categoryCollection->addAttributeToFilter('name', $brandName) ->addAttributeToSelect('image') ->setPageSize(1); /** @var Category $result */ $result = $categoryCollection->getFirstItem(); return $result; } }