![]() 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/Block/Product/ |
<?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\Block\Product; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Reports\Model\ResourceModel\Product as ReportsProducts; use Magento\Sales\Model\ResourceModel\Report\Bestsellers as SalesReportFactory; use Webkul\PrivateShop\Model\ResourceModel\PrivateProduct\CollectionFactory as PrivateCollectionFactory; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Catalog\Model\Layer\Resolver; use Webkul\PrivateShop\Api\Data\PrivateGroupInterfaceFactory; use Magento\Catalog\Helper\Output; class ListProduct extends \Magento\Catalog\Block\Product\ListProduct { /** * Store scope */ public const STORE_SCOPE = "private_shop/general/group_store_view"; /** * @var \Magento\Catalog\Model\Layer\Resolver */ protected $_catalogLayer; /** * @var CollectionFactory */ protected $_productFactory; /** * @var ReportsProducts\CollectionFactory */ protected $_reportproductsFactory; /** * @var SalesReportFactory\CollectionFactory */ protected $_salesReportFactory; /** * @var PrivateCollectionFactory */ protected $privateCollectionFactory; /** * @var \Magento\Framework\App\Http\Context */ protected $httpContext; /** * @var \Magento\Framework\Serialize\Serializer\Json */ protected $jsonSerializer; /** * @var CustomerRepositoryInterface */ protected $customerRepository; /** * @var \Magento\Catalog\Model\Product\Visibility */ protected $visibilty; /** * @var PrivateGroupInterfaceFactory */ protected $privateGroupFactory; /** * @var Output */ protected $output; /** * @var \Magento\Framework\App\Config\ScopeConfigInterface */ protected $scopeConfig; /** * @var \Magento\Store\Model\StoreManagerInterface $storeManager */ protected $storeManager; /** * @param \Magento\Catalog\Block\Product\Context $context * @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param CategoryRepositoryInterface $categoryRepository * @param \Magento\Framework\Url\Helper\Data $urlHelper * @param CollectionFactory $productFactory * @param ReportsProducts\CollectionFactory $reportproductsFactory * @param SalesReportFactory\CollectionFactory $salesReportFactory * @param \Magento\Framework\App\Http\Context $httpContext * @param CustomerRepositoryInterface $customerRepository * @param \Magento\Framework\Serialize\Serializer\Json $jsonSerializer * @param \Magento\Catalog\Model\Product\Visibility $visibilty * @param PrivateCollectionFactory $privateCollectionFactory * @param PrivateGroupInterfaceFactory $privateGroupFactory * @param Output $output * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Store\Model\StoreManagerInterface $storeManager */ public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Framework\Data\Helper\PostHelper $postDataHelper, \Magento\Catalog\Model\Layer\Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository, \Magento\Framework\Url\Helper\Data $urlHelper, CollectionFactory $productFactory, ReportsProducts\CollectionFactory $reportproductsFactory, SalesReportFactory\CollectionFactory $salesReportFactory, \Magento\Framework\App\Http\Context $httpContext, CustomerRepositoryInterface $customerRepository, \Magento\Framework\Serialize\Serializer\Json $jsonSerializer, \Magento\Catalog\Model\Product\Visibility $visibilty, PrivateCollectionFactory $privateCollectionFactory, PrivateGroupInterfaceFactory $privateGroupFactory, Output $output, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager ) { $this->_productFactory = $productFactory; $this->_reportproductsFactory = $reportproductsFactory; $this->_salesReportFactory = $salesReportFactory; $this->privateCollectionFactory = $privateCollectionFactory; $this->httpContext = $httpContext; $this->jsonSerializer = $jsonSerializer; $this->_catalogLayer = $layerResolver->get(); $this->customerRepository = $customerRepository; $this->visibilty = $visibilty; $this->privateGroupFactory = $privateGroupFactory; $this->output = $output; $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; parent::__construct( $context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper ); } /** * Get catalog layer model * * @return Layer */ public function getLayer() { return $this->_catalogLayer; } /** * Display private products according to customer * * @return Magento\Eav\Model\Entity\Collection\AbstractCollection */ protected function _getProductCollection() { $currentStoreId = $this->storeManager->getStore()->getId(); $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() ); } $groupCollection = $this->privateGroupFactory->create() ->getCollection() ->addFieldToFilter('entity_id', ['in' => $customerGroups]); $availableIds = []; $stores = []; foreach ($groupCollection as $group) { if (($group->getStoreId() == $currentStoreId || $group->getStoreId() == 0) && $group->getStatus()==1) { $availableIds[] = $group->getId(); $stores[] = $group->getStoreId(); } } $collection = $this->_productFactory->create(); $collection->addAttributeToSelect('*') ->addAttributeToFilter('is_private_product', ['eq' => 1]) ->setVisibility($this->visibilty->getVisibleInCatalogIds()); if (empty($availableIds)) { $enabledGroupIds=[]; $groupCollection = $this->privateGroupFactory->create() ->getCollection(); foreach ($groupCollection as $group) { if (($group->getStoreId() == $currentStoreId || $group->getStoreId() == 0) && $group->getStatus() ==1) { $enabledGroupIds[] = $group->getId(); } } $collection = $this->privateCollectionFactory->create() ->getPrivateProductCollectionForGroupDisabled( $collection, $enabledGroupIds, ); } $collection = $this->privateCollectionFactory->create() ->getPrivateProductCollection( $collection, $availableIds, $stores, ); return $collection; } /** * Retun is customer logged in * * @return bool */ private function getIsLoggedIn() { return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); } /** * Get Catalog Helper * * @return object */ public function getCatalogHelper() { return $this->output; } }