![]() 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/SerialNumber/Model/ |
<?php /** * Copyright (c) 2021 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved. * https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * Krzysztof Majkowski <[email protected]> */ declare(strict_types=1); namespace Cnc\SerialNumber\Model; use Cnc\SerialNumber\Api\IsSerialNumberEnabledForProductInterface; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\NoSuchEntityException; class IsSerialNumberEnabledForProduct implements IsSerialNumberEnabledForProductInterface { /** * @var ProductRepositoryInterface */ private $productRepository; /** * @var ScopeConfigInterface */ private $scopeConfig; /** * IsSerialNumberEnabledForProduct constructor. * @param ProductRepositoryInterface $productRepository * @param ScopeConfigInterface $scopeConfig */ public function __construct(ProductRepositoryInterface $productRepository, ScopeConfigInterface $scopeConfig) { $this->productRepository = $productRepository; $this->scopeConfig = $scopeConfig; } /** * @param int|string|ProductInterface $product * @return bool * @throws NoSuchEntityException */ public function execute($product): bool { if (is_int($product) || is_numeric($product)) { $product = $this->productRepository->getById($product); } elseif (is_string($product)) { $product = $this->productRepository->get($product); } //Check if product is excluded from the excluded category if ($product->getCncSerialExcludedException()) { return true; } $disabledCategories = $this->scopeConfig->getValue('checkout/serial_number/disabled_categories'); $categories = $disabledCategories ? explode( ',', $disabledCategories ) : false; if (!$categories) { return true; } $productCategories = $product->getCategoryIds(); foreach ($productCategories as $productCategoryId) { if (in_array($productCategoryId, $categories)) { return false; } } return true; } }