Skip to content

Commit

Permalink
ENGCOM-4599: Remove timestap from current date when saving product sp…
Browse files Browse the repository at this point in the history
…ecial price from date #21966
  • Loading branch information
sidolov authored Apr 5, 2019
2 parents b7413f2 + e846299 commit 1d02714
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;

/**
* Set value for Special Price start date
*/
class SetSpecialPriceStartDate implements ObserverInterface
{
/**
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
* @var TimezoneInterface
*/
private $localeDate;

/**
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @codeCoverageIgnore
* @param TimezoneInterface $localeDate
*/
public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate)
public function __construct(TimezoneInterface $localeDate)
{
$this->localeDate = $localeDate;
}

/**
* Set the current date to Special Price From attribute if it empty
* Set the current date to Special Price From attribute if it's empty.
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
Expand All @@ -36,8 +38,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var $product \Magento\Catalog\Model\Product */
$product = $observer->getEvent()->getProduct();
if ($product->getSpecialPrice() && !$product->getSpecialFromDate()) {
$product->setData('special_from_date', $this->localeDate->date());
if ($product->getSpecialPrice() && ! $product->getSpecialFromDate()) {
$product->setData('special_from_date', $this->localeDate->date()->setTime(0, 0));
}

return $this;
Expand Down

0 comments on commit 1d02714

Please sign in to comment.