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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/app/code/Webkul/PrivateShop/Block/ProductLabel.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\Block;

class ProductLabel extends \Magento\Framework\View\Element\Template
{
    public const LABEL_IMAGE_ENABLE = "private_shop/general/enable_lable_image";
    public const LABEL_IMAGE_CONFIG_PATH = "private_shop/general/label_image";
    public const LABEL_TITLE_CONFIG_PATH = "private_shop/general/label_title";
    public const LABEL_POSITION_PATH = "private_shop/general/sticker_position";

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

    /**
     * @var \Magento\Framework\Registry
     */
    protected $_coreRegistry;

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

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

    /**
     * @var \Magento\Customer\Model\Session
     */
    protected $customerSession;

    /**
     * @var \Magento\Customer\Model\CustomerFactory
     */
    protected $customer;

    /**
     * @var \Webkul\PrivateShop\Model\PrivateGroupFactory
     */
    protected $privateGroupFactory;

    /**
     * @var \Webkul\PrivateShop\Model\LabelManagement
     */
    protected $_labelManagement;

    /**
     * @var \Magento\Framework\View\Asset\Repository
     */
    protected $_assetRepo;

    /**
     * Construct function
     *
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param \Magento\Catalog\Model\ProductFactory $productFactory
     * @param \Webkul\PrivateShop\Model\LabelManagement $labelManagemnet
     * @param \Magento\Framework\View\Asset\Repository $assetRepo
     * @param \Magento\Customer\Model\Session $customerSession
     * @param \Magento\Customer\Model\CustomerFactory $customer
     * @param \Webkul\PrivateShop\Model\PrivateGroupFactory $privateGroupFactory
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Catalog\Model\ProductFactory $productFactory,
        \Webkul\PrivateShop\Model\LabelManagement $labelManagemnet,
        \Magento\Framework\View\Asset\Repository $assetRepo,
        \Magento\Customer\Model\SessionFactory $customerSession,
        \Magento\Customer\Model\CustomerFactory $customer,
        \Webkul\PrivateShop\Model\PrivateGroupFactory $privateGroupFactory,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;
        $this->_productFactory = $productFactory;
        $this->_labelManagement = $labelManagemnet;
        $this->_assetRepo = $assetRepo;
        $this->customerSession = $customerSession;
        $this->customer = $customer;
        $this->privateGroupFactory = $privateGroupFactory;
        parent::__construct($context, $data);
    }
    /**
     * @inheritDoc
     */
    protected function _getProduct()
    {
        if (!$this->_product) {
            $this->_product = $this->_coreRegistry->registry('product');
        }
        return $this->_product;
    }

    /**
     * Is LabelActive
     *
     * @return bool
     */
    public function isLabelActive()
    {
        $customerId = $this->customerSession->create()->getCustomer()->getId();
        if ($customerId) {
            $customerData = $this->customer->create()->load($customerId);
            $customerGroup = $customerData->getCustomerPrivateGroup();
            $customerGroup = isset($customerGroup) ? json_decode($customerGroup, true) : '';
            if ($customerGroup) {
                $collection = $this->privateGroupFactory->create()->getCollection();
                $collection->addFieldToFilter('entity_id', ['in' => $customerGroup]);
                $collection->addFieldToFilter('status', '1');
                if ($collection->getSize()) {
                    return $this->_labelManagement->isLabelActive();
                }
                return false;
            }
        }
        return false;
    }

     /**
      * Return html data for product view page
      *
      * @return string
      */
    public function setViewLabelHTML()
    {
        $this->_labelManagement->setProduct($this->_getProduct());
        if ($this->_labelManagement->isPrivateProduct($this->_getProduct()->getId())) {
            return $this->_getViewHTML();
        }
    }

    /**
     * Return html data for category page
     *
     * @return string
     */
    public function setLabelHTML()
    {
        $this->_labelManagement->setProduct($this->_getProduct());
        return $this->_getHTML();
    }

    /**
     * @inheritDoc
     */
    private function _getHTML()
    {
        if ($this->_labelManagement->isLabelImageActive()) {
            if ($this->getLabelImage() == null) {
                $html = "<div class='private-label-image-wrapper ".$this->getStickerPosition()."'>";
                $html .= "<img class='private-label-image' src='".
                         $this->_assetRepo->getUrl('Webkul_PrivateShop::images/dummy.png')."' />";
                $html .= "</div>";
                return $html;
            }
            $html = "<div class='private-label-image-wrapper ".$this->getStickerPosition()."'>";
            $html .= "<img class='private-label-image' src='".
            $this->getUrl('media')."privateshop/label/".$this->getLabelImage()."' />";
            $html .= "</div>";
        } else {
            $html = "<div class='private-label-text-wrapper ".$this->getStickerPosition()."'>";
            $html .= "<div class='private-label-text-content'>";
            $html .= "<span>".$this->getLabelText()."</span>";
            $html .= "</div>";
            $html .= "</div>";
        }
        return $html;
    }

    /**
     * @inheritDoc
     */
    private function _getViewHTML()
    {
        if ($this->_labelManagement->isLabelImageActive()) {
            if ($this->getLabelImage() == null) {
                $html = '';
                return $html;
            }
            $html = "<div class='private-label-image-view ".$this->getStickerPosition()."'>";
            $html .= "<img class='private-label-image' src='".
            $this->getUrl('media')."privateshop/label/".$this->getLabelImage()."' />";
            $html .= "</div>";
        } else {
            $html = "<div class='private-label-text-view ".$this->getStickerPosition()."'>";
            $html .= "<div class='private-label-text-content'>";
            $html .= "<span>".$this->getLabelText()."</span>";
            $html .= "</div>";
            $html .= "</div>";
        }
        return $html;
    }

    /**
     * Get LabelBackground
     *
     * @return void
     */
    public function getLabelBackground()
    {
        return '';
    }

    /**
     * Get position from config
     *
     * @return string
     */
    public function getStickerPosition()
    {
        $position = $this->_labelManagement->getConfigData(self::LABEL_POSITION_PATH);
        if (!$position) {
            $position =  'top-left';
        }
        return $position;
    }

    /**
     * Label text display if image display is No
     *
     * @return string
     */
    public function getLabelText()
    {
        $text = $this->_labelManagement->getConfigData(self::LABEL_TITLE_CONFIG_PATH);
        if (!$text) {
            $text = __('Only for You');
        }
        return $this->escapeHtml($text);
    }

    /**
     * Label text display if image display is Yes
     *
     * @return string
     */
    public function getLabelImage()
    {
        return $this->_labelManagement->getConfigData(self::LABEL_IMAGE_CONFIG_PATH);
    }
}

Spamworldpro Mini