![]() 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/Plugin/ |
<?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\Plugin; use Magento\Framework\App\State; use Magento\Framework\App\RequestInterface; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Framework\UrlInterface as UrlInterface; /** * Class CategoryPlugin * Webkul\PrivateShop\Model\Plugin */ class CategoryPlugin { /** * @var State */ private $state; /** * @var RequestInterface */ private $request; /** * @var \Magento\Framework\Serialize\Serializer\Json */ protected $jsonSerializer; /** * @var UrlInterface */ protected $urlInterface; /** * @param State $state * @param RequestInterface $request * @param \Magento\Framework\Serialize\Serializer\Json $jsonSerializer * @param UrlInterface $urlInterface */ public function __construct( State $state, RequestInterface $request, \Magento\Framework\Serialize\Serializer\Json $jsonSerializer, UrlInterface $urlInterface ) { $this->state = $state; $this->request = $request; $this->jsonSerializer = $jsonSerializer; $this->urlInterface = $urlInterface; } /** * This Function Execute before Magento Core Save Method * * @param CategoryInterface $subject * @return array */ public function beforeSave(CategoryInterface $subject) { $currentUrl = $this->urlInterface->getCurrentUrl(); if ($this->state->getAreaCode() == 'adminhtml' && is_array($subject->getData('category_private_group')) && strpos($currentUrl, '/catalog/product/save/') === false ) { $groups = $this->jsonSerializer->serialize($subject->getData('category_private_group')); $subject->setData('category_private_group', $groups); } elseif (strpos($currentUrl, '/catalog/product/save/') === false) { $subject->setData('category_private_group', ''); } return $subject; } }