Simple1 Posted July 13, 2009 Share Posted July 13, 2009 hey guys,is there a way that my products will automaticaly hide when they are out of stock/unavailable?please help,Thanks in advance Link to comment Share on other sites More sharing options...
SlaplatserP Posted November 4, 2009 Share Posted November 4, 2009 I second that question:Is it there and are we overlooking it? Does anybody know an existing module or script that already does this?We have a few thousand products out of stock that can quickly change to in-stock status.It is more easy to import them all at once and have them Automatically hidden.I wish for a per product flag "Auto hide when out of stock" 0/1 That would be ideal since it leaves the option to allow certain crucial products to still be displayed (and ordered) even when out of stock Link to comment Share on other sites More sharing options...
aleonzzz Posted November 16, 2009 Share Posted November 16, 2009 Hi there.I haven't had time to make this a module yet (nor have I fully tested), but you can make it so that when an order is placed, the system removes the attribute when out of stock and then sets the product to inactive when all stock is gone.To do this edit file: /classes/Product.phpedit the function on line 1283 (updateQuantity) - replace default with the following public static function updateQuantity($product) { if (!is_array($product)) die (Tools::displayError()); $result = Db::getInstance()->getRow(' SELECT `quantity` FROM `'._DB_PREFIX_.($product['id_product_attribute'] ? 'product_attribute' : 'product').'` WHERE `id_product` = '.intval($product['id_product']).($product['id_product_attribute'] ? ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : '')); //need to know stock level of product as a whole $prodresult = Db::getInstance()->getRow('SELECT `quantity` FROM `'._DB_PREFIX_. 'product` WHERE `id_product` = '.intval($product['id_product'])); if (!Configuration::get('PS_STOCK_MANAGEMENT')) return true; if (self::isAvailableWhenOutOfStock($product['out_of_stock']) AND intval($result['quantity']) == 0) return -1; if ($result['quantity'] <= $product['quantity']) { /* original code Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.($product['id_product_attribute'] ? ' product_attribute' : 'product').'` SET `quantity` = 0 WHERE id_product = '.intval($product['id_product']).($product['id_product_attribute'] ? ' AND id_product_attribute = '.intval($product['id_product_attribute']) : ''));*/ // alan mod - removes attribute if quantity = 0 or deactivates product if all sold if($product['id_product_attribute']) { //product_attribute return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_. 'product_attribute` WHERE id_product = '.intval($product['id_product']).' AND id_product_attribute = '.intval($product['id_product_attribute'])); if($prodresult['quantity']<=1) { return Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'product` SET `quantity` = 0, `active` = 0 WHERE id_product = '.intval($product['id_product'])); } } else { //product return Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'product` SET `quantity` = 0, `active` = 0 WHERE id_product = '.intval($product['id_product'])); } if ($result['quantity'] <= $product['quantity']){ return false; } //allows status to be changed only if truly out of stock (sorry I am such a prestanoob) } return Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'product'.($product['id_product_attribute'] ? '_attribute' : '').'` SET `quantity` = `quantity`-'.intval($product['quantity']).' WHERE `id_product` = '.intval($product['id_product']). ($product['id_product_attribute'] ? ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : '')); } Hope it helps someone. Link to comment Share on other sites More sharing options...
sm3004 Posted January 31, 2010 Share Posted January 31, 2010 Has anyone tested this?Does it work? Link to comment Share on other sites More sharing options...
Shaun Posted January 31, 2010 Share Posted January 31, 2010 Unless I'm missing something, I believe you guys are looking for the BO --> Preferences --> Products page that will allow you to manage stock? Link to comment Share on other sites More sharing options...
sm3004 Posted February 2, 2010 Share Posted February 2, 2010 Unless I'm missing something, I believe you guys are looking for the BO --> Preferences --> Products page that will allow you to manage stock? You are, indeed, missing something. The option in the back office ("Allow ordering out-of-stock product:") only allows you to hide the add to cart button if the items are no longer in stock.They are still displayed on the website, even though you can't order them.I want to automatically set the status of the product to unavailable if the item is sold out. That means the product is still viewable in the back office (so I don't have to re-enter the item if the stock gets replenished), but not viewable on the site itself.Right now, i have to search for out of stock items and click the green checkmark under status so they don't show up for customers to see. Link to comment Share on other sites More sharing options...
sm3004 Posted February 3, 2010 Share Posted February 3, 2010 well, tested it and it doesn't work properly... too bad. Link to comment Share on other sites More sharing options...
sm3004 Posted February 3, 2010 Share Posted February 3, 2010 Seriously, is there NOONE out there smart enough to take the partially working code from above and make it work? I am not good enough in PHP to do it unfortunately and I can't be the only one with this issue.I only need code that will remove the product from the website once it is sold out (e.g. set the product status to unavailable once overall stock reaches ZERO), I have set the back office product options to not display out of stock attributes.F##king internet explorer breaks my product page if an item is sold out, so i need to manually remove it.every other f&%king browser works, except IE, big f*%king surprise... wish the world would finally use their brain and ditch IE. IE is like a car company that decides to start installing the break pedal on the passenger side of a car, just because they feel like it... DIE IE DIE... Link to comment Share on other sites More sharing options...
fallenleader Posted April 22, 2010 Share Posted April 22, 2010 maybe this will help, i've yet to tryhttp://www.prestashop.com/forums/viewthread/37027/configuring___using_prestashop/disable_out_of_stock_products Link to comment Share on other sites More sharing options...
AMBER Posted November 24, 2010 Share Posted November 24, 2010 Yeah I wonder why I.E does that too.. Still no one can help??? Is this very difficult for a programmer. Maybe.... Cos very difficult question in other thread is also answered already. Link to comment Share on other sites More sharing options...
xrichardt Posted July 25, 2011 Share Posted July 25, 2011 The post above by aleonzzz is now obsolete and it made me think about a new solution – – the code bellow sets 'active' atribute of a product to 0 (effectively making it disabled from cataloque) at the time new order is placed as soon as the quantity drops bellow 1 ... (obvously it requires to have Stock Management ON) (works with Prestashop 1.4.2.5; not yet fully tested – I'm new to Prestashop ...) File: Classes/PaymentModule, line 183, add section marked /* disable product when quantity bellow one */ if ($id_order_state != _PS_OS_CANCELED_ AND $id_order_state != _PS_OS_ERROR_) { if (Product::updateQuantity($product, (int)$order->id)) $product['stock_quantity'] -= $product['cart_quantity']; /* disable product when quantity bellow one */ if ($product['stock_quantity'] < 1) { $query2 = 'UPDATE `'._DB_PREFIX_.'product` SET `active`=0 WHERE `id_product`='.$product['id_product']; $db->Execute($query2); } if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) $outOfStock = true; Link to comment Share on other sites More sharing options...
davish Posted September 25, 2012 Share Posted September 25, 2012 Thanks for this! It seems to work fine for me with version 1.4.7. 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