0

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?

1

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>
1
  • Wow thanks! weird, but i couldn't seem to find anything about this online or on the magento docs? Did i look in the wrong place or maybe didn't search the right words? And maybe i had to look further into the code.. Thank you for this clear answer! – Bram Hammer Jun 2 '20 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.