![]() 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/old/vendor/magento/module-catalog-rule/Controller/Adminhtml/Promo/Catalog/ |
<?php /** * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog; use Magento\Backend\App\Action\Context; use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filter\FilterInput; use Magento\Framework\Registry; use Magento\Framework\Stdlib\DateTime\Filter\Date; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; /** * Save action for catalog rule * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Save extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog implements HttpPostActionInterface { /** * @var DataPersistorInterface */ protected $dataPersistor; /** * @var TimezoneInterface */ private $localeDate; /** * @param Context $context * @param Registry $coreRegistry * @param Date $dateFilter * @param DataPersistorInterface $dataPersistor * @param TimezoneInterface $localeDate */ public function __construct( Context $context, Registry $coreRegistry, Date $dateFilter, DataPersistorInterface $dataPersistor, TimezoneInterface $localeDate ) { $this->dataPersistor = $dataPersistor; $this->localeDate = $localeDate; parent::__construct($context, $coreRegistry, $dateFilter); } /** * Execute save action from catalog rule * * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { if ($this->getRequest()->getPostValue()) { /** @var \Magento\CatalogRule\Api\CatalogRuleRepositoryInterface $ruleRepository */ $ruleRepository = $this->_objectManager->get( \Magento\CatalogRule\Api\CatalogRuleRepositoryInterface::class ); /** @var \Magento\CatalogRule\Model\Rule $model */ $model = $this->_objectManager->create(\Magento\CatalogRule\Model\Rule::class); try { $this->_eventManager->dispatch( 'adminhtml_controller_catalogrule_prepare_save', ['request' => $this->getRequest()] ); $data = $this->getRequest()->getPostValue(); if (!$this->getRequest()->getParam('from_date')) { $data['from_date'] = $this->localeDate->formatDate(); } $filterValues = ['from_date' => $this->_dateFilter]; if ($this->getRequest()->getParam('to_date')) { $filterValues['to_date'] = $this->_dateFilter; } $inputFilter = new FilterInput( $filterValues, [], $data ); $data = $inputFilter->getUnescaped(); $id = $this->getRequest()->getParam('rule_id'); if ($id) { $model = $ruleRepository->get($id); } $validateResult = $model->validateData(new \Magento\Framework\DataObject($data)); if ($validateResult !== true) { foreach ($validateResult as $errorMessage) { $this->messageManager->addErrorMessage($errorMessage); } $this->_getSession()->setPageData($data); $this->dataPersistor->set('catalog_rule', $data); $this->_redirect('catalog_rule/*/edit', ['id' => $model->getId()]); return; } if (isset($data['rule'])) { $data['conditions'] = $data['rule']['conditions']; unset($data['rule']); } unset($data['conditions_serialized']); unset($data['actions_serialized']); $model->loadPost($data); $this->_objectManager->get(\Magento\Backend\Model\Session::class)->setPageData($data); $this->dataPersistor->set('catalog_rule', $data); $ruleRepository->save($model); $this->messageManager->addSuccessMessage(__('You saved the rule.')); $this->_objectManager->get(\Magento\Backend\Model\Session::class)->setPageData(false); $this->dataPersistor->clear('catalog_rule'); if ($this->getRequest()->getParam('auto_apply')) { $this->getRequest()->setParam('rule_id', $model->getId()); $this->_forward('applyRules'); } else { if ($model->isRuleBehaviorChanged()) { $this->_objectManager ->create(\Magento\CatalogRule\Model\Flag::class) ->loadSelf() ->setState(1) ->save(); } if ($this->getRequest()->getParam('back')) { $this->_redirect('catalog_rule/*/edit', ['id' => $model->getId()]); return; } $this->_redirect('catalog_rule/*/'); } return; } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addErrorMessage( __('Something went wrong while saving the rule data. Please review the error log.') ); $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); $ruleData = $data ?? $this->getRequest()->getPostValue(); $this->_objectManager->get(\Magento\Backend\Model\Session::class)->setPageData($ruleData); $this->dataPersistor->set('catalog_rule', $ruleData); $this->_redirect('catalog_rule/*/edit', ['id' => $this->getRequest()->getParam('rule_id')]); return; } } $this->_redirect('catalog_rule/*/'); } }