Paulo Nacif Posted July 3, 2013 Share Posted July 3, 2013 As create in my module? What hooks? When put cod php? Link to comment Share on other sites More sharing options...
Enrique Gómez Posted July 3, 2013 Share Posted July 3, 2013 (edited) The easiest way is triggers http://mypresta.eu/e...ck-product.html CREATE TRIGGER change_active_after_update AFTER UPDATE ON ps_stock_available FOR EACH ROW BEGIN UPDATE ps_product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity=0); UPDATE ps_product_shop SET active=1 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity>0); END For the 30 days modify the condiction of the WHERE CREATE TRIGGER `change_active_after_update` AFTER UPDATE ON `ps_stock_available` FOR EACH ROW BEGIN UPDATE ps_product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity=0) AND DATEDIFF(NOW(),date_upd)>30; UPDATE ps_product_shop SET active=1 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity>0); END Edited July 3, 2013 by egomezpe (see edit history) 1 Link to comment Share on other sites More sharing options...
vekia Posted July 3, 2013 Share Posted July 3, 2013 that's right, beautiful code i tested it for products older than 1 day and disabled it properly one question: you want to remove or disable? this is main question i think in this case Link to comment Share on other sites More sharing options...
Enrique Gómez Posted July 3, 2013 Share Posted July 3, 2013 that's right, beautiful code i tested it for products older than 1 day and disabled it properly Nice tutorials on your page Vekia, by the way, it's possible to subscribe via RSS to your articles? Thanks Link to comment Share on other sites More sharing options...
Paulo Nacif Posted July 4, 2013 Author Share Posted July 4, 2013 Good, but Erro in line 4 '' .... Link to comment Share on other sites More sharing options...
vekia Posted July 4, 2013 Share Posted July 4, 2013 Good, but Erro in line 4 '' .... what you mean? please paste here whole error code that you've got. it will be really helpfull Link to comment Share on other sites More sharing options...
Enrique Gómez Posted July 4, 2013 Share Posted July 4, 2013 It depends on the tool you use for inserting the trigger In phpmyadmin you have to specify the delim (I've used |) Link to comment Share on other sites More sharing options...
Paulo Nacif Posted July 6, 2013 Author Share Posted July 6, 2013 Link to comment Share on other sites More sharing options...
Enrique Gómez Posted July 6, 2013 Share Posted July 6, 2013 (edited) Use this with the delimiter DELIMITER $$ CREATE TRIGGER `change_active_after_update` AFTER UPDATE ON `ps_stock_available` FOR EACH ROW BEGIN UPDATE ps_product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity=0) AND DATEDIFF(NOW(),date_upd)>30; UPDATE ps_product_shop SET active=1 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity>0); END $$ /* Reset the delimiter back to ";" */ DELIMITER ; Edited July 6, 2013 by egomezpe (see edit history) Link to comment Share on other sites More sharing options...
Paulo Nacif Posted July 7, 2013 Author Share Posted July 7, 2013 Use this with the delimiter DELIMITER $$ CREATE TRIGGER `change_active_after_update` AFTER UPDATE ON `ps_stock_available` FOR EACH ROW BEGIN UPDATE ps_product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity=0) AND DATEDIFF(NOW(),date_upd)>30; UPDATE ps_product_shop SET active=1 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity>0); END $$ /* Reset the delimiter back to ";" */ DELIMITER ; Thanks, was perfect Link to comment Share on other sites More sharing options...
Vosteen Posted March 7, 2016 Share Posted March 7, 2016 Hope it's okay to dig out this old thread, but it seems very useful to me. Two question: - Do I have to create two triggers (Auto deactivate and auto delete), or can I do in one step? - What's the smarter move: auto deleting or just auto deactivating an old product? I mean, what if a a customer looks at an old order? Or will statistics be effected somehow? Link to comment Share on other sites More sharing options...
Inter Svetainė Posted October 15, 2020 Share Posted October 15, 2020 It is always advisable not to delete an item that is no longer in trade. Just because the buyer can always see previous orders and view purchased goods in his ORDERS account. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now