![]() 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/Model/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_catalog_m2 * <[email protected]> */ declare(strict_types=1); namespace Cnc\Catalog\Model\Product; use Cnc\Catalog\Helper\Data as CncCatalogHelper; use Cnc\Catalog\Model\Config; use Cnc\Store\Model\Config as StoreConfig; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\View\Element\Block\ArgumentInterface; use Magento\Store\Model\StoreManagerInterface; class Warranty implements ArgumentInterface { /** * @var CncCatalogHelper */ protected $cncCatalogHelper; /** * @var StoreManagerInterface */ private $storeManager; /** * @var ScopeConfigInterface */ private $scopeConfig; /** * @var SerializerInterface */ private $serializer; /** * Warranty constructor. * @param CncCatalogHelper $cncCatalogHelper * @param StoreManagerInterface $storeManager * @param ScopeConfigInterface $scopeConfig * @param SerializerInterface $serializer */ public function __construct( CncCatalogHelper $cncCatalogHelper, StoreManagerInterface $storeManager, ScopeConfigInterface $scopeConfig, SerializerInterface $serializer ) { $this->cncCatalogHelper = $cncCatalogHelper; $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; $this->serializer = $serializer; } /** * @param ProductInterface $product * @param bool $withTranslate * * @return string */ public function getWarrantyLabel(ProductInterface $product, $withTranslate = true): string { if (is_object($product)) { $warrantyDuration = $this->cncCatalogHelper->getAttributeText($product, 'cnc_guarantee_duration'); $warrantyType = $this->cncCatalogHelper->getAttributeText($product, 'cnc_guarantee_type'); if (is_array($warrantyDuration) && array_key_exists('label', $warrantyDuration)) { $warrantyDuration = $warrantyDuration['label']; } $warrantyPhrase = ($withTranslate ? __($warrantyDuration)->__toString() : $warrantyDuration) . ' ' . ($withTranslate ? __($warrantyType)->__toString() : $warrantyType); return $warrantyPhrase; } return ''; } /** * @param ProductInterface $product * @return string * @throws NoSuchEntityException */ public function getWarrantyTooltip(ProductInterface $product): string { $tooltipConfig = $this->scopeConfig->getValue(Config::XML_PATH_WARRANTY_TOOLTIP); if (is_object($product) && $tooltipConfig) { $warrantyType = $product->getData('cnc_guarantee_type'); $storeCode = $this->storeManager->getStore()->getCode(); try { $tooltips = $this->serializer->unserialize($tooltipConfig); } catch (\InvalidArgumentException $e) { $tooltips = null; } if (is_array($tooltips)) { foreach ($tooltips as $tooltip) { if ($tooltip['guarantee_type_id'] == $warrantyType) { return ($storeCode == StoreConfig::STORE_CODE_FR_EU ? $tooltip['tooltip_fr'] : $tooltip['tooltip_en']); } } } } return ''; } }