Spamworldpro Mini Shell
Spamworldpro


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/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/app/code/Webkul/PrivateShop/Model/LabelManagement.php
<?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\Model;

use Webkul\PrivateShop\Api\Data\PrivateGroupInterface;
use Webkul\PrivateShop\Model\ResourceModel\PrivateGroup\CollectionFactory;
use Magento\Customer\Api\CustomerRepositoryInterface;

class LabelManagement
{
    /**
     * Constant for Label Image Enable
     */
    public const LABEL_IMAGE_ENABLE = "private_shop/general/enable_lable_image";
    /**
     * Constant for Label Image Config Path
     */
    public const LABEL_IMAGE_CONFIG_PATH = "private_shop/general/label_image";
    /**
     * Constant for Label Enable Path
     */
    public const LABEL_ENABLE_PATH = "private_shop/general/enable";

    /**
     * @var \Magento\Framework\App\Http\Context
     */
    protected $httpContext;

    /**
     * @var \Magento\Catalog\Model\Product|null
     */
    protected $_product = null;

     /**
      * @var \Magento\Catalog\Model\ProductFactory
      */
    protected $productFactory;

    /**
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $scopeConfig;

    /**
     * @var CollectionFactory
     */
    protected $groupCollectionFactory;

    /**
     * @var array
     */
    protected $groupIds = [];

    /**
     * @var \Magento\Framework\Serialize\Serializer\Json
     */
    protected $jsonSerializer;

    /**
     * @var CustomerRepositoryInterface
     */
    protected $customerRepository;
    
    /**
     * @var CollectionFactory
     */
    protected $collectionFactory;

    /**
     * Constructor
     *
     * @param \Magento\Framework\App\Http\Context $httpContext
     * @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,
        CustomerRepositoryInterface $customerRepository,
        CollectionFactory $collectionFactory,
        \Magento\Catalog\Model\ProductFactory $productFactory,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    ) {
        $this->httpContext = $httpContext;
        $this->customerRepository = $customerRepository;
        $this->collectionFactory = $collectionFactory;
        $this->productFactory = $productFactory;
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * Get All private groups ids
     *
     * @return void
     */
    private function getPrivateGroupIds()
    {
        
        if (empty($this->groupIds)) {
            $this->groupIds = $this->getGroupCollection()->create()
            ->addFieldToFilter('status', '1')
            ->getAllIds();
        }
        return $this->groupIds;
    }

    /**
     * GetGroupCollection
     *
     * @return \Webkul\PrivateShop\Model\ResourceModel\PrivateGroup\Collection
     */
    private function getGroupCollection()
    {
        if ($this->groupCollectionFactory === null) {
            $this->groupCollectionFactory = \Magento\Framework\App\ObjectManager::getInstance()
                ->get(CollectionFactory::class);
        }
        return $this->groupCollectionFactory;
    }

    /**
     * GetJsonSerializer
     *
     * @return \Magento\Framework\Serialize\Serializer\Json
     */
    private function getJsonSerializer()
    {
        if ($this->jsonSerializer === null) {
            $this->jsonSerializer = \Magento\Framework\App\ObjectManager::getInstance()
                ->get(\Magento\Framework\Serialize\Serializer\Json::class);
        }
        return $this->jsonSerializer;
    }

    /**
     * SetProduct
     *
     * @param \Magento\Catalog\Model\Product $product
     * @return void
     */
    public function setProduct(\Magento\Catalog\Model\Product $product = null)
    {
        $this->_product = $product;
    }

    /**
     * Get configuration values
     *
     * @param string $path
     * @return string|int|null
     */
    public function getConfigData($path)
    {
        return $this->scopeConfig->getValue(
            $path,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }

    /**
     * Is product is private
     *
     * @param int $productId
     * @return bool
     */
    public function isPrivateProduct($productId = null)
    {
        $productGroups = [];
        $product = $this->_product;
        $privateGroup = $product->getData('product_private_group');
        if ($privateGroup) {
            $productGroups = $this->getJsonSerializer()->unserialize(
                $privateGroup
            );
        }
        if (empty(array_intersect($this->getPrivateGroupIds(), $productGroups))) {
            return false;
        }
        return (bool)$product->getIsPrivateProduct();
    }

    /**
     * Is Label image active in admin config
     *
     * @return bool
     */
    public function isLabelImageActive()
    {
        $active = $this->scopeConfig->getValue(
            self::LABEL_IMAGE_ENABLE,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
        if ($active && $active==1) {
            return true;
        }
        return false;
    }

    /**
     * Is Label config active
     *
     * @return bool
     */
    public function isLabelActive()
    {
        $activeLabel = $this->scopeConfig->getValue(
            self::LABEL_ENABLE_PATH,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
        
        $activeImage = $this->scopeConfig->getValue(
            self::LABEL_IMAGE_ENABLE,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
        
        if ($activeLabel && $activeLabel==1) {
            return true;
        } elseif ($activeImage && $activeImage==1) {
            return true;
        }
        return false;
    }

    /**
     * Set Html to private products
     *
     * @return void
     */
    protected function _setLabelHTML()
    {
        $class = "private-label-available";
        if ($this->isPrivateProduct($this->_product->getData('entity_id')) === true) {
            return $this->_getHTML($class);
        }
        return '';
    }
    /**
     * Get Html to private products
     *
     * @param _getHTML $class
     * @return html
     */
    protected function _getHTML($class)
    {
        if ($this->isLabelImageActive()) {
            $class.= ' label-image-enable';
        }
        $html = "<input type='hidden' class='".$class."' value='1' />";
        return $html;
    }

    /**
     * Return is customer logged in
     *
     * @return bool
     */
    private function getIsLoggedIn()
    {
        return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
    }
}

Spamworldpro Mini