Skip to content

Commit

Permalink
ENGCOM-4215: Static test fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Feb 12, 2019
1 parent 1a69d43 commit bc92929
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;

use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;

/**
* SalesRule save controller
Expand Down Expand Up @@ -84,12 +84,8 @@ public function execute()
$data
);
$data = $inputFilter->getUnescaped();
$id = $this->getRequest()->getParam('rule_id');
if ($id) {
$model->load($id);
if ($id != $model->getId()) {
throw new \Magento\Framework\Exception\LocalizedException(__('The wrong rule is specified.'));
}
if (!$this->checkRuleExists($model)) {
throw new \Magento\Framework\Exception\LocalizedException(__('The wrong rule is specified.'));
}

$session = $this->_objectManager->get(\Magento\Backend\Model\Session::class);
Expand Down Expand Up @@ -159,4 +155,22 @@ public function execute()
}
$this->_redirect('sales_rule/*/');
}

/**
* Check if Cart Price Rule with provided id exists.
*
* @param \Magento\SalesRule\Model\Rule $model
* @return bool
*/
private function checkRuleExists(\Magento\SalesRule\Model\Rule $model): bool
{
$id = $this->getRequest()->getParam('rule_id');
if ($id) {
$model->load($id);
if ($model->getId() != $id) {
return false;
}
}
return true;
}
}
12 changes: 6 additions & 6 deletions app/code/Magento/SalesRule/Model/Rule/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/
namespace Magento\SalesRule\Model\Rule;

use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\SalesRule\Model\ResourceModel\Rule\Collection;
use Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory;
use Magento\SalesRule\Model\Rule;
use Magento\Framework\App\Request\DataPersistorInterface;

/**
* Class DataProvider
Expand Down Expand Up @@ -36,7 +36,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
* @var \Magento\SalesRule\Model\Rule\Metadata\ValueProvider
*/
protected $metadataValueProvider;

/**
* @var DataPersistorInterface
*/
Expand All @@ -51,9 +51,9 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
* @param CollectionFactory $collectionFactory
* @param \Magento\Framework\Registry $registry
* @param Metadata\ValueProvider $metadataValueProvider
* @param DataPersistorInterface $dataPersistor
* @param array $meta
* @param array $data
* @param DataPersistorInterface $dataPersistor
*/
public function __construct(
$name,
Expand All @@ -62,9 +62,9 @@ public function __construct(
CollectionFactory $collectionFactory,
\Magento\Framework\Registry $registry,
\Magento\SalesRule\Model\Rule\Metadata\ValueProvider $metadataValueProvider,
DataPersistorInterface $dataPersistor = null,
array $meta = [],
array $data = []
array $data = [],
DataPersistorInterface $dataPersistor = null
) {
$this->collection = $collectionFactory->create();
$this->coreRegistry = $registry;
Expand All @@ -88,7 +88,7 @@ protected function getMetadataValues()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getData()
{
Expand Down

0 comments on commit bc92929

Please sign in to comment.