Question

I got a weird issue i can't see to find the reason behind it.
When i update product with a special_price and the special_from_date is NULL (empty) it updates the special_from_date to today.. And i can't seem to find why..

Is this a common bug? (i don't think so) but i also can't seem to find the root of the problem. thanks in advance!

And for a short workaround how can i safely disable special_from_date or just don't let it update?

Was it helpful?

Solution

It's not a bug, it's a feature :-)

The "magic" happens in the observer Magento\Catalog\Observer\SetSpecialPriceStartDate which is executed in the event catalog_product_save_beforeand does exactly what you are describing:

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

You can disable this observer if you don't want that to happen. Just add the following code into an events.xml file into your module:

<event name="catalog_product_save_before">
    <observer name="set_special_price_start_date" disabled="true" />
</event>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top