Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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