What is the easiest way to update value of attribute in Magento 2 on a daily basis?

418 Views Asked by At

I have three different delivery dates in my store and I want the user to choose from any of them (effects the price) on the (configurable) product page. I need these three to hold three different values:

4 days from now = "2017-09-04"

7 days from now = "2017-09-07"

10 days from now ="2017-09-10"

The Attribute 146 holds all three and presents the options to the customer in a dropdown menu. When the user makes his choice the product price changes. My problem is that I dont want to update the values manually every day so I am looking for a way to automatize. First I tried to do it in configurable.phtml and change the value every time the page gets loaded. I am trying to use this line of code to be able to do it but I am having difficulties making it work.

<?php $this->action->updateAttributes([$product->getId()], ['deliverydate' > $newValue], $storeId); ?>

Now I am thinking of maybe I should set up a cron job to do it every night? What do you think? Any suggestions?

0

There are 0 best solutions below