Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 83b0692

Browse files
authored
Merge pull request #4778 from magento-tango/MC-19873
MC-19873: [Sample Data Function Test] Sample data test failed with Incorrect final price
2 parents 9372a0f + 6d7daa4 commit 83b0692

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Save.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Registry;
1313
use Magento\Framework\Stdlib\DateTime\Filter\Date;
1414
use Magento\Framework\App\Request\DataPersistorInterface;
15+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1516

1617
/**
1718
* Save action for catalog rule
@@ -25,19 +26,27 @@ class Save extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog imple
2526
*/
2627
protected $dataPersistor;
2728

29+
/**
30+
* @var TimezoneInterface
31+
*/
32+
private $localeDate;
33+
2834
/**
2935
* @param Context $context
3036
* @param Registry $coreRegistry
3137
* @param Date $dateFilter
3238
* @param DataPersistorInterface $dataPersistor
39+
* @param TimezoneInterface $localeDate
3340
*/
3441
public function __construct(
3542
Context $context,
3643
Registry $coreRegistry,
3744
Date $dateFilter,
38-
DataPersistorInterface $dataPersistor
45+
DataPersistorInterface $dataPersistor,
46+
TimezoneInterface $localeDate
3947
) {
4048
$this->dataPersistor = $dataPersistor;
49+
$this->localeDate = $localeDate;
4150
parent::__construct($context, $coreRegistry, $dateFilter);
4251
}
4352

@@ -46,16 +55,15 @@ public function __construct(
4655
*
4756
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void
4857
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
58+
* @SuppressWarnings(PHPMD.NPathComplexity)
4959
*/
5060
public function execute()
5161
{
5262
if ($this->getRequest()->getPostValue()) {
53-
5463
/** @var \Magento\CatalogRule\Api\CatalogRuleRepositoryInterface $ruleRepository */
5564
$ruleRepository = $this->_objectManager->get(
5665
\Magento\CatalogRule\Api\CatalogRuleRepositoryInterface::class
5766
);
58-
5967
/** @var \Magento\CatalogRule\Model\Rule $model */
6068
$model = $this->_objectManager->create(\Magento\CatalogRule\Model\Rule::class);
6169

@@ -65,7 +73,9 @@ public function execute()
6573
['request' => $this->getRequest()]
6674
);
6775
$data = $this->getRequest()->getPostValue();
68-
76+
if (!$this->getRequest()->getParam('from_date')) {
77+
$data['from_date'] = $this->localeDate->formatDate();
78+
}
6979
$filterValues = ['from_date' => $this->_dateFilter];
7080
if ($this->getRequest()->getParam('to_date')) {
7181
$filterValues['to_date'] = $this->_dateFilter;

app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProduct.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
101101
$scopeTz = new \DateTimeZone(
102102
$this->localeDate->getConfigTimezone(ScopeInterface::SCOPE_WEBSITE, $websiteId)
103103
);
104-
$fromTime = (new \DateTime($rule->getFromDate(), $scopeTz))->getTimestamp();
104+
$fromTime = $rule->getFromDate()
105+
? (new \DateTime($rule->getFromDate(), $scopeTz))->getTimestamp()
106+
: 0;
105107
$toTime = $rule->getToDate()
106108
? (new \DateTime($rule->getToDate(), $scopeTz))->getTimestamp() + IndexBuilder::SECONDS_IN_DAY - 1
107109
: 0;

0 commit comments

Comments
 (0)