![]() 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 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\Product as ProductModel; use Magento\Catalog\Model\ProductTypes\ConfigInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Locale\FormatInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Framework\Stdlib\StringUtils; use Magento\Framework\Url\EncoderInterface; use Magento\Framework\Json\EncoderInterface as JsonEncoder; class BannerImage extends View { /** * @var File */ protected $file; /** * @var \Magento\Store\Model\StoreManagerInterface */ private $store; /** * BannerImage constructor. * @param Context $context * @param EncoderInterface $urlEncoder * @param JsonEncoder $jsonEncoder * @param StringUtils $string * @param Product $productHelper * @param ConfigInterface $productTypeConfig * @param FormatInterface $localeFormat * @param Session $customerSession * @param ProductRepositoryInterface $productRepository * @param PriceCurrencyInterface $priceCurrency * @param File $file * @param array $data */ public function __construct( Context $context, EncoderInterface $urlEncoder, JsonEncoder $jsonEncoder, StringUtils $string, Product $productHelper, ConfigInterface $productTypeConfig, FormatInterface $localeFormat, Session $customerSession, ProductRepositoryInterface $productRepository, PriceCurrencyInterface $priceCurrency, File $file, array $data = [] ) { parent::__construct( $context, $urlEncoder, $jsonEncoder, $string, $productHelper, $productTypeConfig, $localeFormat, $customerSession, $productRepository, $priceCurrency, $data ); $this->file = $file; $this->store = $context->getStoreManager(); } /** * @param ProductModel $product * @throws FileSystemException */ public function getBannerImage($product) { $imagePath = ''; $fileName = $product->getCncProductBanner(); $path = $this->_filesystem->getDirectoryRead( DirectoryList::MEDIA )->getAbsolutePath( 'catalog/product/file/' ); if ($fileName && $this->file->isExists($path . $fileName)) { $mediaBaseUrl = $this->store->getStore()->getBaseUrl( \Magento\Framework\UrlInterface::URL_TYPE_MEDIA ); $imagePath = $mediaBaseUrl . 'catalog/product/file/' . $fileName; } return $imagePath; } }