Skip to content

Commit

Permalink
Merge pull request #4779 from magento-tango/MC-19862
Browse files Browse the repository at this point in the history
MC-19862: [Function Test] MC-148 Magento\FunctionalTestingFramework.functional.ApplyCatalogPriceRuleByProductAttributeTest
  • Loading branch information
dhorytskyi authored Sep 16, 2019
2 parents 262876b + 5c013cd commit fbd08fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\Filter\Date;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;

/**
* Save action for catalog rule
Expand All @@ -25,19 +26,27 @@ class Save extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog imple
*/
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
DataPersistorInterface $dataPersistor,
TimezoneInterface $localeDate
) {
$this->dataPersistor = $dataPersistor;
$this->localeDate = $localeDate;
parent::__construct($context, $coreRegistry, $dateFilter);
}

Expand All @@ -46,16 +55,15 @@ public function __construct(
*
* @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);

Expand All @@ -65,7 +73,9 @@ public function execute()
['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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
$scopeTz = new \DateTimeZone(
$this->localeDate->getConfigTimezone(ScopeInterface::SCOPE_WEBSITE, $websiteId)
);
$fromTime = (new \DateTime($rule->getFromDate(), $scopeTz))->getTimestamp();
$fromTime = $rule->getFromDate()
? (new \DateTime($rule->getFromDate(), $scopeTz))->getTimestamp()
: 0;
$toTime = $rule->getToDate()
? (new \DateTime($rule->getToDate(), $scopeTz))->getTimestamp() + IndexBuilder::SECONDS_IN_DAY - 1
: 0;
Expand Down

0 comments on commit fbd08fc

Please sign in to comment.