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/Plugin/CatalogSearch/Result/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/cartforge.co/app/code/Webkul/PrivateShop/Plugin/CatalogSearch/Result/Index.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\Plugin\CatalogSearch\Result;

use Magento\Framework\App\Http\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\ScopeInterface;

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

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

    /**
     * @var \Magento\Framework\Message\ManagerInterface
     */
    protected $messageManager;

    /**
     * @var ResultFactory
     */
    protected $resultFactory;

    /**
     * @var UrlInterface
     */
    protected $url;
    
    /**
     *
     * @param Context $httpContext
     * @param ScopeConfigInterface $scopeConfig
     * @param ManagerInterface $messageManager
     * @param ResultFactory $resultFactory
     * @param UrlInterface $url
     */
    public function __construct(
        Context $httpContext,
        ScopeConfigInterface $scopeConfig,
        ManagerInterface $messageManager,
        ResultFactory $resultFactory,
        UrlInterface $url
    ) {
        $this->httpContext = $httpContext;
        $this->scopeConfig = $scopeConfig;
        $this->messageManager = $messageManager;
        $this->resultFactory = $resultFactory;
        $this->url = $url;
    }

    /**
     * After Execute
     *
     * @param \Magento\CatalogSearch\Controller\Result\Index $subject
     * @param [mixed] $result
     * @return void
     */
    public function afterExecute(
        \Magento\CatalogSearch\Controller\Result\Index $subject,
        $result
    ) {
        if ((bool)$this->isPrivateShop() && !$this->getIsLoggedIn()) {
            $this->messageManager->addNotice(__("This shop is private, please login/register to search products."));
            $result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $result->setUrl($this->url->getUrl('customer/account'));
        }
        return $result;
    }

    /**
     * Get Config Value
     *
     * @param string $path
     *
     * @return string
     */
    public function getConfigValue($path)
    {
        $scope = ScopeInterface::SCOPE_STORE;
        $result = trim($this->scopeConfig->getValue($path, $scope));
        return $result;
    }

    /**
     * Return active status
     *
     * @return string
     */
    public function isPrivateShop()
    {
        $active = $this->getConfigValue('private_shop/general/store_private');
        return $active;
    }
    
    /**
     * Return is customer logged in
     *
     * @return bool
     */
    private function getIsLoggedIn()
    {
        return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
    }
}

Spamworldpro Mini