mux Posted July 1, 2013 Share Posted July 1, 2013 (edited) Hi, Can anybody help me to hide the out of stock products in categories and featured products in prestashop 1.5.4.1 ? I have searched so much but I do not get better solution of it. Here is below link of my site where I want .... http://purmoservice....egory&id_lang=1 Thanks, Mux Edited July 1, 2013 by mux (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 1, 2013 Share Posted July 1, 2013 you can achieve this with mysql triggers, read this tutorial: disabling the out of stock products or with module seo 301 redirection (it has option to disable out of stock products and redirect to selected category) 4 Link to comment Share on other sites More sharing options...
mux Posted July 1, 2013 Author Share Posted July 1, 2013 (edited) you can achieve this with mysql triggers, read this tutorial: disabling the out of stock products I read this tutorial already but problem is that there is no trigger option in phpmyadmin and I even told my hosting server provider please upgrade it and in response from them is, they will upgrade after August, So please guide me another way Edited July 1, 2013 by mux (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 1, 2013 Share Posted July 1, 2013 if you've got possiblity to run cron jobs, you can run one with php script with code mentioned in the tutorial: 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); run this script (for example) for every 10 minutes or as often as you like Link to comment Share on other sites More sharing options...
mux Posted July 1, 2013 Author Share Posted July 1, 2013 if you've got possiblity to run cron jobs, you can run one with php script with code mentioned in the tutorial: 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); run this script (for example) for every 10 minutes or as often as you like I do not have option of cron jobs in my hosting, can I get any help/guidness in coding structure? such as in classes/category.php or classes/Product.php Thanks. Link to comment Share on other sites More sharing options...
vekia Posted July 1, 2013 Share Posted July 1, 2013 no cron jobs, no triggers :| what hosting you use? well, in this case, if you haven't got access to the features that i mentioned above you should edit core of the prestashop, there is no other way to achieve what you expect. unfortunately Link to comment Share on other sites More sharing options...
mux Posted July 1, 2013 Author Share Posted July 1, 2013 no cron jobs, no triggers :| what hosting you use? well, in this case, if you haven't got access to the features that i mentioned above you should edit core of the prestashop, there is no other way to achieve what you expect. unfortunately Thanks vekia, Yes you are right, I should edit the core files of it. Link to comment Share on other sites More sharing options...
Microame Posted August 1, 2013 Share Posted August 1, 2013 Hi Vekia, I have followed your instructions and created a trigger, as per http://mypresta.eu/en/art/tips-and-tricks/how-to-disable-out-of-stock-product.html. Do I have to do something else? Still unavailable items are visible. Link to comment Share on other sites More sharing options...
swsindonesia Posted August 1, 2013 Share Posted August 1, 2013 Another way to do this without touching the database is by modifying the tpl for product listing, and home featured module by skipping product with empty stock. Use the same {if} statement used for determine "add to cart" button (between enabled or not). Link to comment Share on other sites More sharing options...
Microame Posted August 1, 2013 Share Posted August 1, 2013 Hi swsindonesia, Could you please explain bit more about your suggestion. Regards Link to comment Share on other sites More sharing options...
vekia Posted August 1, 2013 Share Posted August 1, 2013 swissindonesia but then product list will have "empty boxes" it mean that the products will not be excluded from the counter. in addition - without "deactivating" the item - there is still possibility to order the product, for example from product page, or from simple modified form. in my opinion it is necessary to "disable" the product. the question is: why the method provided above doesnt work Microame, what PS version you're using? 1 Link to comment Share on other sites More sharing options...
Microame Posted August 1, 2013 Share Posted August 1, 2013 Hi Vekia, I am using 1.5.4.1 Link to comment Share on other sites More sharing options...
vekia Posted August 1, 2013 Share Posted August 1, 2013 so, i've got question: trigger exist in your triggers page in phpmyadmin? can you show how it looks like? Link to comment Share on other sites More sharing options...
swsindonesia Posted August 2, 2013 Share Posted August 2, 2013 Yupp I guess the tpl trick will require more effort than setting up a database trigger can you just go to your PHPmyAdmin, go to SQL editing window and execute the command there ? CREATE trigger ... on ... AS ... ... Link to comment Share on other sites More sharing options...
vekia Posted August 2, 2013 Share Posted August 2, 2013 i just wondering why the trigger doesn't work, as i understood - trigger exist, but doesnt work for his store ... Link to comment Share on other sites More sharing options...
Microame Posted August 2, 2013 Share Posted August 2, 2013 Hi Vekia, Please see the images of my trigger. Link to comment Share on other sites More sharing options...
vekia Posted August 2, 2013 Share Posted August 2, 2013 can you for test purposes manually change the quantity in the ps_stock_available table? (in phpmyadmin) then check the products active field in the ps_products table 1 Link to comment Share on other sites More sharing options...
PascalVG Posted August 2, 2013 Share Posted August 2, 2013 Not sure if it is important, but there's a white space in the trigger name just after 'change': change _active_after_update , instead of: change_active_after_update My 2 cents, pascal Link to comment Share on other sites More sharing options...
Microame Posted August 2, 2013 Share Posted August 2, 2013 Hi Pascal, yes there was a white space, but it is only a name. But still I have changed the white space but no change. Hi Vekia, Changed the quantity manually and in the cart it shows zero quntity and add to cart button is disabled. Still the product is visible. Link to comment Share on other sites More sharing options...
Microame Posted August 2, 2013 Share Posted August 2, 2013 Hi Vekia, Another thing I noticed is, even though the add to cart button has deactivated, in my back office the quantity has not changed. Link to comment Share on other sites More sharing options...
jemmeli Posted August 2, 2013 Share Posted August 2, 2013 maybe you can do this by comment some code in category.tpl file in the theme folder Link to comment Share on other sites More sharing options...
vekia Posted August 2, 2013 Share Posted August 2, 2013 it's really really weird, when you order something, in which table quantity field is affected? ps_stock_available or ps_products_shop ? Link to comment Share on other sites More sharing options...
Microame Posted August 3, 2013 Share Posted August 3, 2013 Hi Vekia, In ps_products_shop there is no quality field. There is only minimal quantity which stays 1 for all the products. Link to comment Share on other sites More sharing options...
vekia Posted August 3, 2013 Share Posted August 3, 2013 and what about ps_product table? Link to comment Share on other sites More sharing options...
Microame Posted August 3, 2013 Share Posted August 3, 2013 In ps_product there is a quantity attribute but it show 0 quantity even though there is 18 available, minimal quantity shows 1. Link to comment Share on other sites More sharing options...
vekia Posted August 3, 2013 Share Posted August 3, 2013 okay, so everything looks fine. your quantities are stored in the correct tabe: ps_stock_available now the question is why the trigger doesn't work are you sure, that your hoster allows you to use triggers in the mysql? Link to comment Share on other sites More sharing options...
Microame Posted August 3, 2013 Share Posted August 3, 2013 Well, that is a good question. They have allowed me to create one, so I guess they allow to use, but how do i confirm that? Link to comment Share on other sites More sharing options...
MysysRo Posted August 3, 2013 Share Posted August 3, 2013 (edited) Just use an override for Category class - is this way - is just one line of code Copy the attached Category.php in override/classes/ and let me know if is ok Regards Modification: in function getProducts just put .' AND IFNULL(stock.quantity, 0) > 0 ' before .' GROUP BY product_shop.id_product'; Category.php Edited August 3, 2013 by MysysRo (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted August 3, 2013 Share Posted August 3, 2013 Hi MySys, Yesterday I played with the exact same idea, but somehow it doesn't 'see' the file in the override/classes folder. Even the change in the original /classes/Category.php seemed not be seen, as if there's another overriding file in play. Did you try it out and did it work for you when added to override/classes?? Curious... pascal Link to comment Share on other sites More sharing options...
MysysRo Posted August 3, 2013 Share Posted August 3, 2013 Hi PascalVG On my 1.5.4.1 instance is working, just try the attached file from my post But indeed is something strange with override, I can not override HookCore - it doesn't 'see' the modifications - I was forced to change the original /classes/Hook.php Link to comment Share on other sites More sharing options...
vekia Posted August 3, 2013 Share Posted August 3, 2013 i tested solution and it works 8) but unfortunately, product page will be still visible, in other - not related to the Category class pages too Link to comment Share on other sites More sharing options...
MysysRo Posted August 3, 2013 Share Posted August 3, 2013 I initially posted only solution for the home - like solving method complete solution must take into account: getPricesDrop; getNewProducts ... Please upload the attached file into override/classes/ Best regards, Mihai Category.php Product.php 1 Link to comment Share on other sites More sharing options...
nitin900 Posted September 12, 2013 Share Posted September 12, 2013 can you for test purposes manually change the quantity in the ps_stock_available table? (in phpmyadmin) then check the products active field in the ps_products table Hii Vekia after create trigger rule...out of stock product show... plese give any suggetion about it... Thanks in advance Link to comment Share on other sites More sharing options...
vekia Posted September 12, 2013 Share Posted September 12, 2013 Hii Vekia after create trigger rule...out of stock product show... plese give any suggetion about it... Thanks in advance i need little more informations like: what ps version are you sure that your hoster allow to use triggers? after trigger creation, does trigger appear on trigger list? you use advanced stock management? are you sure that you use correct table names? (especially prefix) Link to comment Share on other sites More sharing options...
nitin900 Posted September 12, 2013 Share Posted September 12, 2013 i need little more informations like: what ps version are you sure that your hoster allow to use triggers? after trigger creation, does trigger appear on trigger list? you use advanced stock management? are you sure that you use correct table names? (especially prefix) 1.5.4.1 version yeah yes appear trigger in trigger list i check use in stock advanced management system.. yeah table name is correct.. plz help me.. Link to comment Share on other sites More sharing options...
lafondadebaco Posted September 27, 2013 Share Posted September 27, 2013 Hi everybody! I've been looking around for a solution for this issue, and since PS version 1.5, it's so easy to deal with this kind of things. That's why I've created this simple module that use the hook to disable the product after it's sold. http://www.prestashop.com/forums/topic/278029-free-module-hide-disable-products-when-they-are-out-of-stock/ Regards for all! Link to comment Share on other sites More sharing options...
spider17 Posted October 12, 2013 Share Posted October 12, 2013 the best way i found is to add this code in each product loop: {if $product.quantity > 0} {/if} so the old code is {foreach from=$new_products item='product' name='newProducts'} .......... {/foreach} become: {foreach from=$new_products item='product' name='newProducts'} {if $product.quantity > 0} ................ {/if} {/foreach} enjoy Link to comment Share on other sites More sharing options...
El Patron Posted October 12, 2013 Share Posted October 12, 2013 the best way i found is to add this code in each product loop: {if $product.quantity > 0} {/if} so the old code is {foreach from=$new_products item='product' name='newProducts'} .......... {/foreach} become: {foreach from=$new_products item='product' name='newProducts'} {if $product.quantity > 0} ................ {/if} {/foreach} enjoy This does not work for products that allowed to be ordered when out of stock. Link to comment Share on other sites More sharing options...
vekia Posted October 12, 2013 Share Posted October 12, 2013 i replied also in other topic related to this case, here is what i think about it: hello but for example, your store displays 10 products in category page (you can define how many products you want to display in BO) script make query to database and get 10 products, for example - 9 of them have got quantity = 0. you will see only 1 product on page then. it will looks weirdy especially when you will have additional pages (pagination) one page with 1 product, several other pages with more / less products displayed... Link to comment Share on other sites More sharing options...
spider17 Posted October 12, 2013 Share Posted October 12, 2013 (edited) EL PATRON: if you want to allow product to be ordred when out of stock, so you dont have to hide them. Verika: maybe you are right, i can't test it cause i dont have many products in a same category. Edited October 12, 2013 by spider17 (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted October 13, 2013 Share Posted October 13, 2013 Spider, Maybe you want to allow the "allow out-of-stock orders" on a per-product basis, so El Patron has a point there. N.B. I once made a trigger based version (in it's basic form it also didn't check for allow-out-of-stock, but can be added if needed). If anyone's interested... Link to comment Share on other sites More sharing options...
El Patron Posted October 13, 2013 Share Posted October 13, 2013 pascal...that would be great if you could provide the trigger with checks for out of stock rule. Vekia could add to his tutorial trigger. I've seen loads of 'half' complete solutions on this subject. None of which work totally.... in my world..if either works totally or it fails completely, there are no half solutions to running a professional shop. Link to comment Share on other sites More sharing options...
PascalVG Posted October 14, 2013 Share Posted October 14, 2013 Hi El Patron, all, El patron, you asked for a trigger based version taking into account the allow out-of-stock ordering of individual products. You can do something like this: Create a trigger in the ps_stock_available: Trigger name: change_active_allow_oos Table: ps_stock_available Time: after Event: Update Definition: BEGINDECLARE SHOPWIDEOOS TINYINT(1) DEFAULT 0;SET SHOPWIDEOOS = (SELECT CAST(`value` AS SIGNED) AS num FROM `ps_configuration` WHERE `name` = 'PS_ORDER_OUT_OF_STOCK' limit 1); UPDATE ps_product_shop SET active=1 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity>0);UPDATE ps_product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity<=0 AND (out_of_stock =0 OR (out_of_stock = 2 AND SHOPWIDEOOS = 0)));END Explanation: Step 1: (Purple): declare a local integer variable called SHOPWIDEOOS inside the trigger, with default value 0 Step 2: (Green) Get the current 'shop wide' value that defines if out of stock products can be ordered. This value comes from the ps_configuration file. You set this value in Back office, in Preferences->Products: When Checked, this allows for products to be ordered when out of stock BUT ONLY IF the product has the allow out of stock setting is set to "default' (internal value of this option = 2) (Of course you can also define per product if the product can be ordered or not, in the same menu. Then choose Deny (internal value = 0) or Allow (internal value = 1) instead of Default. We take care of that in step 4) So we get this value and put it in the variable SHOPWIDEOOS (i.e. Shop Wide Out Of Stock) we defined in Step 1. Step 3: (blue): Nothing special here. We check if the value of quantity is more than 0. if so, we activate the product. Step 4: (Red) Here is the trick happening, we check if a product quantity becomes 0 or less. We then de-activate the product IF: - Product has a value of Deny for allow out of stock ordering - or Product has a value of Default, and the shop wide value is set to Deny (unchecked). That does the trick. Have fun playing with it! pascal. N.B. When developing the trigger, I came across something weird. First I had Step 3 and 4 swapped, and for some obscure reason, It didn't trigger the de-activate. Activate worked as normal. Swapping Step 3 and 4 did the trick. Don't ask me why..... 1 Link to comment Share on other sites More sharing options...
ambitos Posted November 28, 2013 Share Posted November 28, 2013 I think the correct code for the trigger is this DELIMITER $$ CREATE /*[DEFINER = { user | CURRENT_USER }]*/ TRIGGER `change_active_after_update` AFTER UPDATE ON `ps_stock_available` FOR EACH ROW BEGIN UPDATE ps_product_shop SET active = IF(NEW.quantity <= 0,0,1) WHERE id_product = OLD.id_product; END$$ DELIMITER ; Link to comment Share on other sites More sharing options...
spott Posted January 15, 2014 Share Posted January 15, 2014 I initially posted only solution for the home - like solving method complete solution must take into account: getPricesDrop; getNewProducts ... Please upload the attached file into override/classes/ Best regards, Mihai In some reason Your hack doesn't work. But I like the idea and I need similar solution. As I have external stock management, what sends stock info to presta I want to hide these products, what’s are out of stock. But without pagination problem. I can't turn products off - as next day I can have again it in stock back and I want to manually turn it on. Link to comment Share on other sites More sharing options...
dbeezer99 Posted January 28, 2014 Share Posted January 28, 2014 you can achieve this with mysql triggers, read this tutorial: disabling the out of stock products I followed these direction carefully and successfully added the trigger but products with zero stock still visable. Im using PS 1.5.6.1 Link to comment Share on other sites More sharing options...
dbeezer99 Posted January 28, 2014 Share Posted January 28, 2014 Oh i forgot screen shots: http://prntscr.com/2n8v4y http://prntscr.com/2n8tqv Link to comment Share on other sites More sharing options...
businessphoneandcom Posted April 15, 2014 Share Posted April 15, 2014 if you've got possiblity to run cron jobs, you can run one with php script with code mentioned in the tutorial: 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); run this script (for example) for every 10 minutes or as often as you like Hello, I create this file but i have message error Parse error: syntax error, unexpected T_STRING in /home/www/outofstock.php on line 3 Look my file please : outofstock.php thank you very much Link to comment Share on other sites More sharing options...
vekia Posted April 15, 2014 Share Posted April 15, 2014 Hello, I create this file but i have message error Parse error: syntax error, unexpected T_STRING in /home/www/outofstock.php on line 3 Look my file please : outofstock.php thank you very much in fact: 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); it's not a php code, this is a mysql query (two queries) you ahve to run these queries in your database manager software like phpmyadmin. Link to comment Share on other sites More sharing options...
businessphoneandcom Posted April 15, 2014 Share Posted April 15, 2014 (edited) in fact: 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); it's not a php code, this is a mysql query (two queries) you ahve to run these queries in your database manager software like phpmyadmin. Yes but in one of your post you talk about this : if you've got possiblity to run cron jobs, you can run one with php script with code mentioned in the tutorial: 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); run this script (for example) for every 10 minutes or as often as you like So can you tell me how to create cron file. Because my webhost a cronweb so I can put my file in the root of my site and give him instruction eg www.phoneandcom.com / outofstock.php because I haven't trigger button best regards businessphoneandcom Edited April 15, 2014 by businessphoneandcom (see edit history) Link to comment Share on other sites More sharing options...
businessphoneandcom Posted April 16, 2014 Share Posted April 16, 2014 in fact: 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); it's not a php code, this is a mysql query (two queries) you ahve to run these queries in your database manager software like phpmyadmin. Hello, Thank you for your reply. I would like to create this famous file to interact with my database in php. How do I create this php file that will run me these two queries: UPDATE ps_product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity=0); and UPDATE ps_product_shop SET active=1 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity>0); I know I need a code for my sql connection and so I can integrate it into the php file but otherwise could if you can create this file for me to use these two applications that would be nice. I'll just have to put this file in the root of my ftp and set up a task Webcron in my hosting such http://www.phoneandcom.com/my_file.php Thank you in advance Businessphoneandcom http://ww.phoneandcom.com Link to comment Share on other sites More sharing options...
krisives Posted April 16, 2014 Share Posted April 16, 2014 Just curious as I saw this thread pop up, does 1.6 support hiding out of stock products? Link to comment Share on other sites More sharing options...
vekia Posted April 16, 2014 Share Posted April 16, 2014 Businessphoneandcom http://ww.phoneandcom.com you have to include to this php, this file: config.inc.php, for exmaple with code: require_once("config/config.inc.php"); then you will be able to use Db::staticfunction functions, it mean that you will be able to use prestashop core code to run own sql queries 1 Link to comment Share on other sites More sharing options...
businessphoneandcom Posted April 17, 2014 Share Posted April 17, 2014 you have to include to this php, this file: config.inc.php, for exmaple with code: require_once("config/config.inc.php"); then you will be able to use Db::staticfunction functions, it mean that you will be able to use prestashop core code to run own sql queries Hello, I try to make a php file, but without success when I type in my firefox explore www / phoneandcom.com / test_sql it gives me errors: Warning: require_once(../config/config.inc.php) [function.require-once]: failed to open stream: No such file or directory in /home/www/test_sql.php on line 3 Fatal error: require_once() [function.require]: Failed opening required '../config/config.inc.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/www/test_sql.php on line 3 look at the file I created here: test_sql.php Can you please help me fix this file ? Businessphoneandcom Link to comment Share on other sites More sharing options...
businessphoneandcom Posted April 17, 2014 Share Posted April 17, 2014 (edited) you have to include to this php, this file: config.inc.php, for exmaple with code: require_once("config/config.inc.php"); then you will be able to use Db::staticfunction functions, it mean that you will be able to use prestashop core code to run own sql queries Hello, I create this file whith your recommandation : test_requete.php But is the same problem: errors in my url then I tape www.phoneandcom.com/test_requete.php: Parse error: syntax error, unexpected T_VARIABLE in /home/www/test_requete.php on line 10 Can you help me to fix the problem please Businessphoneandcom Edited April 17, 2014 by businessphoneandcom (see edit history) Link to comment Share on other sites More sharing options...
businessphoneandcom Posted April 17, 2014 Share Posted April 17, 2014 you have to include to this php, this file: config.inc.php, for exmaple with code: require_once("config/config.inc.php"); then you will be able to use Db::staticfunction functions, it mean that you will be able to use prestashop core code to run own sql queries Hello, I'm telling I finally managed to create the famous PHP file to be placed in Webcron task with your help and my Google searches. yes "Google is your friend" as they say in France. Here is the PHP code for this file to place where you want in your ftp and set Webcron task on your host. Biensur replace the database name, password etc ... with your own login: <?php $link = mysql_connect('db_name_server', 'db_user', 'password'); if (!$link) { die('No connection possible: ' . mysql_error()); } mysql_select_db('db_name'); mysql_query('UPDATE ps_1product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_1stock_available WHERE quantity=0)'); mysql_query('UPDATE ps_1product_shop SET active=1 WHERE id_product IN (SELECT id_product FROM ps_1stock_available WHERE quantity>0)'); ?> Thank you a lot [sOLVED] Link to comment Share on other sites More sharing options...
kacti Posted July 2, 2014 Share Posted July 2, 2014 (edited) Hi El Patron, all, El patron, you asked for a trigger based version taking into account the allow out-of-stock ordering of individual products. You can do something like this: Create a trigger in the ps_stock_available: Trigger name: change_active_allow_oos Table: ps_stock_available Time: after Event: Update Definition: BEGIN DECLARE SHOPWIDEOOS TINYINT(1) DEFAULT 0; SET SHOPWIDEOOS = (SELECT CAST(`value` AS SIGNED) AS num FROM `ps_configuration` WHERE `name` = 'PS_ORDER_OUT_OF_STOCK' limit 1); UPDATE ps_product_shop SET active=1 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity>0); UPDATE ps_product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity<=0 AND (out_of_stock =0 OR (out_of_stock = 2 AND SHOPWIDEOOS = 0))); END Explanation: Step 1: (Purple): declare a local integer variable called SHOPWIDEOOS inside the trigger, with default value 0 Step 2: (Green) Get the current 'shop wide' value that defines if out of stock products can be ordered. This value comes from the ps_configuration file. You set this value in Back office, in Preferences->Products: allow ordering out of stock products.jpg When Checked, this allows for products to be ordered when out of stock BUT ONLY IF the product has the allow out of stock setting is set to "default' (internal value of this option = 2) per product allow out of stock.jpg (Of course you can also define per product if the product can be ordered or not, in the same menu. Then choose Deny (internal value = 0) or Allow (internal value = 1) instead of Default. We take care of that in step 4) So we get this value and put it in the variable SHOPWIDEOOS (i.e. Shop Wide Out Of Stock) we defined in Step 1. Step 3: (blue): Nothing special here. We check if the value of quantity is more than 0. if so, we activate the product. Step 4: (Red) Here is the trick happening, we check if a product quantity becomes 0 or less. We then de-activate the product IF: - Product has a value of Deny for allow out of stock ordering - or Product has a value of Default, and the shop wide value is set to Deny (unchecked). That does the trick. Have fun playing with it! pascal. N.B. When developing the trigger, I came across something weird. First I had Step 3 and 4 swapped, and for some obscure reason, It didn't trigger the de-activate. Activate worked as normal. Swapping Step 3 and 4 did the trick. Don't ask me why..... Hi I'm trying to enable Prestashop to hide out of stock products EXCEPT those that can be ordered when out of stock and those that currently have stock. My settings Prestashop version: 1.6.0.8 Products | Products Stock | Allow ordering of out-of-stock products: NO I have a few products configured Quantities | When out of stock: Allow Orders (the vast majority are set to Default) I am using “Advanced Stock Management” and “specify available quantities manually” I have am using vekia’s “How to automatically disable out of stock products in PrestaShop” trigger (excellent triggerJ). This is working 100%. I have tried to use pascal’s trigger to display products that can be ordered when out of stock. But I am receiving the following error – picture attached https://www.dropbox.com/s/x2avfgpa4os79j3/change_active_allow_oosERROR.png Can both vekia’s and pascal’s triggers work together? Is there one trigger that hides out of stock items except those that have been enabled to be ordered when out of stock? Thanks for any help or input… https://www.dropbox.com/s/51plut62ea7zu8n/change_active_allow_oos.png Edited July 2, 2014 by kacti (see edit history) Link to comment Share on other sites More sharing options...
Eolia Posted July 17, 2014 Share Posted July 17, 2014 See here: http://www.prestashop.com/forums/topic/344050-free-update-elements-display-only-active-products-categories/ Hope it will be usefull Link to comment Share on other sites More sharing options...
garyjj127 Posted February 10, 2015 Share Posted February 10, 2015 I've tried this with a view to changing the visibility of the product, instead of whether it's active, as I wanted to keep the pages on the server to prevent problems with search engines. I changed SET active=1 to SET visibility="both" And SET active=0 to SET visibility="none" Seems to work pretty well! Link to comment Share on other sites More sharing options...
garyjj127 Posted February 10, 2015 Share Posted February 10, 2015 I spoke to soon! There's actually a pretty big problem with this code (including the original): A product is set to deny orders if out of stock. This product is available in sizes small, medium, large, x large. The size large sells out. The ENTIRE item is deactivated! Is there a way to keep the item active if the TOTAL inventory is 1 or more? Link to comment Share on other sites More sharing options...
AZC Posted November 9, 2015 Share Posted November 9, 2015 Hi, I created the trigger and it worked to hide all the unavailable products. However it did not show the product again when it was in stock. Instead the product then became unactive and i had to reenable it. Now I removed the trigger and all the out of stock products are not showing. How do I make them visible again? Thanks Link to comment Share on other sites More sharing options...
Eolia Posted November 9, 2015 Share Posted November 9, 2015 Hi, I created the trigger and it worked to hide all the unavailable products. However it did not show the product again when it was in stock. Instead the product then became unactive and i had to reenable it. Now I removed the trigger and all the out of stock products are not showing. How do I make them visible again? Thanks See here: http://www.prestasho...cts-categories/ Hope it will be usefull 1 Link to comment Share on other sites More sharing options...
AZC Posted November 9, 2015 Share Posted November 9, 2015 See here: http://www.prestasho...cts-categories/ Hope it will be usefull Perfect. thanks Link to comment Share on other sites More sharing options...
FlowMVMT Posted April 27, 2016 Share Posted April 27, 2016 Perfect. thanks It says I do not have permission to see that link... any idea on why? Link to comment Share on other sites More sharing options...
Eolia Posted April 27, 2016 Share Posted April 27, 2016 Because this module update is not free. It is available here http://eoliashop.com/modules-prestashop/Prestashop15-16/updateelements Link to comment Share on other sites More sharing options...
vishalsingh119 Posted July 8, 2016 Share Posted July 8, 2016 can you for test purposes manually change the quantity in the ps_stock_available table? (in phpmyadmin) then check the products active field in the ps_products table i also use the same trigger for hide the ended stock item,but after that product showing with message" product is out of stock" Link to comment Share on other sites More sharing options...
vishalsingh119 Posted July 11, 2016 Share Posted July 11, 2016 Hi, if tried all option and still facing issue.so you try this. no need to change any mysql or php file,directly download the psf checkout module.its free available .download it and install it. Link to comment Share on other sites More sharing options...
tony_mik Posted October 26, 2016 Share Posted October 26, 2016 Hi guys. I wouldn't use mysql modifying because the PS tables are complicated and they have various links. You can easily use the classes PS already has. For example, you can use a query to give you the products with certain amount of stock, like: $sql = 'SELECT id_product FROM '._DB_PREFIX_.'product WHERE quantity = 0'; $id_product = (int)Db::getInstance()->getValue($sql); This will give you the array $id_product array, then simply use a foreach to go through it and update the products as needed. Disabling product it's a bad practice because you will lose your links and Google will penalize you. Better to make the product not visible (but keep the link active) and also, you can hide or show the price. I go like this: function update($single_product_id){ $product = new Product($single_product_id); $product->available_for_order = 0; $product->visibility = none; $product->show_price = 0; $product->save(); } This will also get indexed in Prestashop so you will not be affected by cache or search indexation. It is quick and painless and you can play with it as you see fit. Link to comment Share on other sites More sharing options...
OUengineer Posted July 26, 2017 Share Posted July 26, 2017 Hi guys. I wouldn't use mysql modifying because the PS tables are complicated and they have various links. You can easily use the classes PS already has. For example, you can use a query to give you the products with certain amount of stock, like: $sql = 'SELECT id_product FROM '._DB_PREFIX_.'product WHERE quantity = 0'; $id_product = (int)Db::getInstance()->getValue($sql); This will give you the array $id_product array, then simply use a foreach to go through it and update the products as needed. Disabling product it's a bad practice because you will lose your links and Google will penalize you. Better to make the product not visible (but keep the link active) and also, you can hide or show the price. I go like this: function update($single_product_id){ $product = new Product($single_product_id); $product->available_for_order = 0; $product->visibility = none; $product->show_price = 0; $product->save(); } This will also get indexed in Prestashop so you will not be affected by cache or search indexation. It is quick and painless and you can play with it as you see fit. Hello tony, I have tried your function but I am receiving this error: Prestashop version: 1.6.1.11 This page isn’t workingsitename is currently unable to handle this request. HTTP ERROR 500 Link to comment Share on other sites More sharing options...
tony_mik Posted July 26, 2017 Share Posted July 26, 2017 Hello tony, I have tried your function but I am receiving this error: Prestashop version: 1.6.1.11 This page isn’t workingsitename is currently unable to handle this request. HTTP ERROR 500 Well, you must include certain files in order to be able to access the functions. I use something like this: include_once '../config/config.inc.php'; include(dirname(__FILE__).'/init.php'); ini_set('display_errors',1); error_reporting(E_ALL & ~E_NOTICE); $defaultLanguage = new Language((int)(Configuration::get('PS_LANG_DEFAULT'))); $languages = Language::getLanguages(); $lang_id = $defaultLanguage->id; Link to comment Share on other sites More sharing options...
OUengineer Posted July 26, 2017 Share Posted July 26, 2017 Thank you tony_mik, Question, all of this should be included in classes/product.php ? I am novice Link to comment Share on other sites More sharing options...
tony_mik Posted August 3, 2017 Share Posted August 3, 2017 Thank you tony_mik, Question, all of this should be included in classes/product.php ? I am novice No, you have to create a .php file and run it from the servers console. This action will update the value of all products in database. 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