Skip to content

Commit 043c38b

Browse files
ENGCOM-4215: Entered data missing when entering the wrong date for from, to in cart rule #20895
- Merge Pull Request #20895 from cedcommerce/magento2:2.3-develop-adityayadav - Merged commits: 1. 3da7c76 2. d697ea6 3. 8faf8e9 4. e5abf95 5. 811a7bf 6. 89a5728 7. 1a69d43 8. bc92929
2 parents 602647d + bc92929 commit 043c38b

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Save.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
88

99
use Magento\Framework\App\Action\HttpPostActionInterface;
10-
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1110
use Magento\Framework\App\Request\DataPersistorInterface;
11+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1212

1313
/**
1414
* SalesRule save controller
@@ -84,12 +84,8 @@ public function execute()
8484
$data
8585
);
8686
$data = $inputFilter->getUnescaped();
87-
$id = $this->getRequest()->getParam('rule_id');
88-
if ($id) {
89-
$model->load($id);
90-
if ($id != $model->getId()) {
91-
throw new \Magento\Framework\Exception\LocalizedException(__('The wrong rule is specified.'));
92-
}
87+
if (!$this->checkRuleExists($model)) {
88+
throw new \Magento\Framework\Exception\LocalizedException(__('The wrong rule is specified.'));
9389
}
9490

9591
$session = $this->_objectManager->get(\Magento\Backend\Model\Session::class);
@@ -159,4 +155,22 @@ public function execute()
159155
}
160156
$this->_redirect('sales_rule/*/');
161157
}
158+
159+
/**
160+
* Check if Cart Price Rule with provided id exists.
161+
*
162+
* @param \Magento\SalesRule\Model\Rule $model
163+
* @return bool
164+
*/
165+
private function checkRuleExists(\Magento\SalesRule\Model\Rule $model): bool
166+
{
167+
$id = $this->getRequest()->getParam('rule_id');
168+
if ($id) {
169+
$model->load($id);
170+
if ($model->getId() != $id) {
171+
return false;
172+
}
173+
}
174+
return true;
175+
}
162176
}

app/code/Magento/SalesRule/Model/Rule/DataProvider.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
namespace Magento\SalesRule\Model\Rule;
77

8+
use Magento\Framework\App\Request\DataPersistorInterface;
89
use Magento\SalesRule\Model\ResourceModel\Rule\Collection;
910
use Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory;
1011
use Magento\SalesRule\Model\Rule;
11-
use Magento\Framework\App\Request\DataPersistorInterface;
1212

1313
/**
1414
* Class DataProvider
@@ -36,7 +36,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
3636
* @var \Magento\SalesRule\Model\Rule\Metadata\ValueProvider
3737
*/
3838
protected $metadataValueProvider;
39-
39+
4040
/**
4141
* @var DataPersistorInterface
4242
*/
@@ -51,9 +51,9 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
5151
* @param CollectionFactory $collectionFactory
5252
* @param \Magento\Framework\Registry $registry
5353
* @param Metadata\ValueProvider $metadataValueProvider
54-
* @param DataPersistorInterface $dataPersistor
5554
* @param array $meta
5655
* @param array $data
56+
* @param DataPersistorInterface $dataPersistor
5757
*/
5858
public function __construct(
5959
$name,
@@ -62,9 +62,9 @@ public function __construct(
6262
CollectionFactory $collectionFactory,
6363
\Magento\Framework\Registry $registry,
6464
\Magento\SalesRule\Model\Rule\Metadata\ValueProvider $metadataValueProvider,
65-
DataPersistorInterface $dataPersistor = null,
6665
array $meta = [],
67-
array $data = []
66+
array $data = [],
67+
DataPersistorInterface $dataPersistor = null
6868
) {
6969
$this->collection = $collectionFactory->create();
7070
$this->coreRegistry = $registry;
@@ -88,7 +88,7 @@ protected function getMetadataValues()
8888
}
8989

9090
/**
91-
* {@inheritdoc}
91+
* @inheritdoc
9292
*/
9393
public function getData()
9494
{

0 commit comments

Comments
 (0)