![]() 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/Controller/Adminhtml/PrivateGroup/ |
<?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\Controller\Adminhtml\PrivateGroup; use Magento\Framework\Exception\LocalizedException; class Save extends \Magento\Backend\App\Action { /** * Authorization level of a basic admin session * * @see _isAllowed() */ public const ADMIN_RESOURCE = 'Webkul_PrivateShop::save'; /** * @var \Magento\Framework\App\Request\DataPersistorInterface */ protected $dataPersistor; /** * @var \Webkul\PrivateShop\Model\PrivateGroup */ protected $groupFactory; /** * @var \Webkul\PrivateShop\Api\PrivateGroupRepositoryInterface */ protected $privateGroupRepository; /** * * @param \Magento\Backend\App\Action\Context $context * @param \Webkul\PrivateShop\Model\PrivateGroupFactory $groupFactory * @param \Webkul\PrivateShop\Api\PrivateGroupRepositoryInterface $privateGroupRepository * @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor */ public function __construct( \Magento\Backend\App\Action\Context $context, \Webkul\PrivateShop\Model\PrivateGroupFactory $groupFactory, \Webkul\PrivateShop\Api\PrivateGroupRepositoryInterface $privateGroupRepository, \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor ) { $this->dataPersistor = $dataPersistor; $this->groupFactory = $groupFactory; $this->privateGroupRepository = $privateGroupRepository; parent::__construct($context); } /** * Save action * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPostValue(); $privateGroupCollection = $this->groupFactory->create()->getCollection()->addFieldToFilter( ['group_name'], [ ['eq' => trim($data['group_name'])] ] )->addFieldToFilter(['store_id'], [['eq' => trim($data['store_id'])] ])->addFieldToFilter(['status'], [['eq' => trim($data['status'])]])->count(); if ($privateGroupCollection > 0) { $this->messageManager->addErrorMessage(__('This Group Name Already Exists.')); return $resultRedirect->setPath('*/*/'); } if ($data) { $data['group_name'] = strip_tags(trim($data['group_name'])); $id = $this->getRequest()->getParam('entity_id'); $model = $this->groupFactory->create()->load($id); if (!$model->getId() && $id) { $this->messageManager->addErrorMessage(__('This group no longer exists.')); return $resultRedirect->setPath('*/*/'); } $model->setGroupName($data['group_name']); $model->setStatus($data['status']); $model->setStoreId($data['store_id']); try { $this->privateGroupRepository->save($model); $this->messageManager->addSuccessMessage(__('You saved the group.')); $this->dataPersistor->clear('privategroup'); if ($this->getRequest()->getParam('back')) { return $resultRedirect->setPath('*/*/edit', ['entity_id' => $model->getId()]); } return $resultRedirect->setPath('*/*/'); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the group.')); } $this->dataPersistor->set('privategroup', $data); return $resultRedirect->setPath('*/*/edit', ['entity_id' => $this->getRequest()->getParam('entity_id')]); } return $resultRedirect->setPath('*/*/'); } }