![]() 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/cartforge.co/app/code/Webkul/PrivateShop/Plugin/Catalog/Widget/ |
<?php /** * Webkul Software * * @category Webkul * @package Webkul_PrivateShop * @author Webkul Software Private Limited * @copyright Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ namespace Webkul\PrivateShop\Plugin\Catalog\Widget; use Webkul\PrivateShop\Model\ResourceModel\PrivateProduct\CollectionFactory; use Magento\Customer\Api\CustomerRepositoryInterface; class LablePlugin extends \Webkul\PrivateShop\Model\LabelManagement { public const LABEL_ENABLE_PATH = "private_shop/general/enable"; /** * @var \Magento\Catalog\Model\ProductFactory */ protected $productFactory; /** * @var \Magento\Framework\App\Config\ScopeConfigInterface */ protected $scopeConfig; /** * @var \Magento\Framework\App\Http\Context */ protected $httpContext; /** * @var \Magento\Framework\Serialize\Serializer\Json */ protected $jsonSerializer; /** * @var CustomerRepositoryInterface */ protected $customerRepository; /** * @var CollectionFactory */ protected $collectionFactory; /** * @var \Magento\Catalog\Model\Product */ protected $_product; /** * * @param \Magento\Framework\App\Http\Context $httpContext * @param \Magento\Framework\Serialize\Serializer\Json $jsonSerializer * @param CustomerRepositoryInterface $customerRepository * @param CollectionFactory $collectionFactory * @param \Magento\Catalog\Model\ProductFactory $productFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */ public function __construct( \Magento\Framework\App\Http\Context $httpContext, \Magento\Framework\Serialize\Serializer\Json $jsonSerializer, CustomerRepositoryInterface $customerRepository, CollectionFactory $collectionFactory, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig ) { $this->productFactory = $productFactory; $this->scopeConfig = $scopeConfig; $this->httpContext = $httpContext; $this->jsonSerializer = $jsonSerializer; $this->customerRepository = $customerRepository; $this->collectionFactory = $collectionFactory; } /** * Before GetProductPriceHtml * * @param \Magento\CatalogWidget\Block\Product\ProductsList $list * @param \Magento\Catalog\Model\Product $product * @param string|null $priceType * @param [type] $renderZone * @param array $arguments * * @return void */ public function beforeGetProductPriceHtml( \Magento\CatalogWidget\Block\Product\ProductsList $list, \Magento\Catalog\Model\Product $product, $priceType = null, $renderZone = \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST, array $arguments = [] ) { $this->_product = $product; } /** * After GetProductPriceHtml * * @param \Magento\CatalogWidget\Block\Product\ProductsList $list * @param string $result * @return string */ public function afterGetProductPriceHtml( \Magento\CatalogWidget\Block\Product\ProductsList $list, $result ) { if ($this->isLabelActive()) { $result .= $this->_setLabelHTML(); } return $result; } /** * Modify widget collection * * @param \Magento\CatalogWidget\Block\Product\ProductsList $list * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection * @return \Magento\Catalog\Model\ResourceModel\Product\Collection */ public function afterCreateCollection( \Magento\CatalogWidget\Block\Product\ProductsList $list, $collection ) { $collection->addAttributeToFilter('is_private_product', [['null' => true],['neq' => 1]], 'left'); if ($this->getIsLoggedIn()) { $customerId = $this->httpContext->getValue('customer_id'); $customer = $this->customerRepository->getById($customerId); $customerGroups = []; $privateGroup = $customer->getCustomAttribute('customer_private_group'); if ($privateGroup) { $customerGroups = $this->jsonSerializer->unserialize( $privateGroup->getValue() ); } $collection = $this->collectionFactory->create()->getWidetProductCollection( $collection, $customerGroups ); } return $collection; } /** * Return is customer logged in * * @return bool */ private function getIsLoggedIn() { return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); } }