I have an e-commerce site (based on magento2) with products on it that need to be available between certain dates. I have saved the specific start and end dates in a mysql db but now need to trigger the enabling/disabling of a product when the time is reached. How can I have a live link between the two without setting up a cron job that runs every second to edit the status?
"I need a CRON every second" for a MySQL problem means your actually need a VIEW
(or eventually a TRIGGER
for heaviest cases).
Assuming you have product.startDate
and product.endDate
columns, along with a product.isEnabled
. Then create the following VIEW
:
CREATE VIEW `productView` AS SELECT
startDate AS startDate,
endDate AS endDate,
(isEnabled AND NOW() BETWEEN startDate AND endDate) AS isEnabled
FROM product
And use this VIEW
in your code ( SELECT p.isEnaled FROM productView
). In case you cannot update the PHP using code, just rename the table (for productTable
) and use product
AS the view's name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.