Jump to content

Disable Item When Out Of Stock


Recommended Posts

  • 2 weeks later...

I have clicked No to Display unavailable product attributes on product page: in the Preferences > Products section and am hoping that this is the right one for disabling items out of stock, I haven't had any yet so can't say if it works or not.

Link to comment
Share on other sites

To automatically disable the products once they go out of stock is not an easy thing to do. It would be easier to just leave the products enabled and simply hide them from the product lists. To do this, edit changes lines 418-419 of classes/Category.php (in Prestashop v1.2.5) from:

WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').'
'.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : '');



to:

WHERE p.`quantity` > 0 AND cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').'
'.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : '');



This will hide out-of-stock products when you click on a category, but they'll still appear in search results and on some other pages. To remove them from the search results, change line 148 of classes/Search.php from:

$whereArray[] = ' p.id_product '.($word[0] == '-' ? 'NOT' : '').' IN (



to:

$whereArray[] = ' p.`quantity` > 0 AND p.id_product '.($word[0] == '-' ? 'NOT' : '').' IN (



To remove the out-of-stock products from the best sellers list, change lines 72 and 114 of classes/ProductSales.php (in Prestashop v1.2.5) to:

from:

WHERE p.`active` = 1



to:

WHERE p.`active` = 1 AND p.`quantity` > 0



To remove the out-of-stock products from the specials list, change line 1048 of classes/Product.php (in Prestashop v1.2.5) from:

AND p.`active` = 1



to:

AND p.`active` = 1 AND p.`quantity` > 0



I haven't tested this code, but it should work. There may be other places that also need to be changed.

Link to comment
Share on other sites

  • 3 months later...

Is this still an issue in the latest version?

On Zen-Cart which I used before, I could set so that if someone buy the product will be automatically disabled and not showing in the shop. This is good when selling unique items, which I do. Because if it is sold then it is gone and not really will be more added later.

Hmm.. maybe meanwhile I will change the text out of stock to sold simply..
But I am hoping for this auto-disable to be added to the new version of Presta because it is bothersome to manually disable items when it is sold.

Link to comment
Share on other sites

  • 3 months later...

Hi - the text is slightly different in 1.3.2 so I just searched for any SQL WHERE terms relating to the product and added the qty > 0.

Unfortunately this above code does not seem to work with the "Manufacurers" block. It still shows out of stock items for manufacturers. I'm very much new to PrestaShop so would anyone know which file I would need to work on?

Thanks in advance!

Stephen.

Link to comment
Share on other sites

Thats right steve_c, it´s not included in 1.4. I have looked at 5-6 other e-commerce software and Prestashop is the ONLY one that dont have this function! It may seem like an smal thing, but to hide out-of-stock products is essential in many business models.

Here are feature request for this: (But I doubt Prestashop-team ever read them...)
http://www.prestashop.com/bug_tracker/view/not_display_a_product_out_of_stock/

Link to comment
Share on other sites

I have used CS-Cart for a couple of years. It´s a great system but it lacks many country specific modules/integration that would make my work more easy. The module-system is Prestashops strength.
I dont like to hack to much, it make it so harder to upgrade to a newer version + i´m not a coder... ;)

Link to comment
Share on other sites

Hi Daniel can you tell me exactly how you did this?

On a side note to any developers reading - I've received in total about 10 complaints within 2 weeks from customers saying that the shop is very confusing because half of the products are no longer in stock (in New products, manufacturers link etc). I really think this is an issue that needs looking at if possible...

Link to comment
Share on other sites

just edited classes/product.php
replace

LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
       WHERE p.`active` = 1
       AND p.`date_add` > DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)



with

LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
       WHERE p.`active` = 1
       AND p.`quantity` > 0
       AND p.`date_add` > DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)



in the getNewProducts function.

Link to comment
Share on other sites

  • 4 months later...
Thats right steve_c, it´s not included in 1.4. I have looked at 5-6 other e-commerce software and Prestashop is the ONLY one that dont have this function! It may seem like an smal thing, but to hide out-of-stock products is essential in many business models.

Here are feature request for this: (But I doubt Prestashop-team ever read them...)
http://www.prestashop.com/bug_tracker/view/not_display_a_product_out_of_stock/


Hi Danman,
I mistakenly assumed Prestashop had this function when I started developing a new clients site, so now I'll have to resort to hacking the code, which I'm not confident about doing..

I've added a comment to your feature request and hoping it may help jog the Prestashop team into action :)
Link to comment
Share on other sites

  • 2 months later...
What about, a button with next command?

UPDATE ps_product
SET active = 0
WHERE quantity = 0

EDIT: Oh, sorry, this is not automatic... :)

Regards.


i like this approach...
if you add this line at the place where the stock gets changed, this would work automatically!
is that classes/StockMvt.php ? or somewhere else?
Link to comment
Share on other sites

  • 1 month later...

just edited classes/product.php <br/>replace <br/>

LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)<br/>        WHERE p.`active` = 1<br/>        AND p.`date_add` > DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)

<br/><br/>with<br/>

LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)<br/>        WHERE p.`active` = 1<br/>        AND p.`quantity` > 0<br/>        AND p.`date_add` > DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)

<br/><br/>in the getNewProducts function.

 

works perfectly, thanks.

Link to comment
Share on other sites

  • 5 weeks later...

hi there,

 

I'm facing similar challenges to hide Out of Stock items. I tried the workaround suggested to include "AND p.`quantity` > 0' into products.php but it doesn't seem to be working. I noticed that the code is different in PS 1.4. Can anyone please help me out?

 

 	 LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
       WHERE p.`active` = 1
       AND p.`quantity` > 0
       AND DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get(

Link to comment
Share on other sites

  • 4 weeks later...

I have hidden all my out of stock products in 1.4.4 by including the following condition in product-list.tpl:

 

{if ($product.allow_oosp || $product.quantity > 0)}

 

 

However, if I wanted to show some out of stock products while hiding others, you can include instead:

 

{if isset($product.available_for_order) && $product.available_for_order}

 

This is more manual, but for each product in the backend, you can just uncheck the box on the right side for "available for order".

 

Both won't disable the product pages but hides them in category list to prevent 404 errors during search engine crawl.

 

 

Insert code after

{foreach from=$products item=product name=products}

  • Like 1
Link to comment
Share on other sites

Actually the code above hides them from being seen, but they actually still there just not taking space, eg. (10 products shown, but only see 8 because 2 are out of stock.)

 

@rocky thanks to the modification you proposed! I managed to get it working for categories on Prestashop 1.4.4 by changing

 

 

WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').'
'.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : '');

 

to

 

 

WHERE cp.`id_category` = '.(int)($this->id).($active ? ' AND p.`active` = 1' : '').'

'.($id_supplier ? 'AND p.id_supplier = '.(int)($id_supplier) : ''));

 

 

However, it seems that the Search.php code is a lot different in 1.4.4 and I couldn't find anywhere anything that resembles the fix you suggested. Can you share your thoughts on how to hide out of stock products in 1.4?

 

Thanks, rocky!

Link to comment
Share on other sites

  • 4 weeks later...

as posts by 'angora' disappeared and with it the solution i used, i put the solution here again:

 

 

make a file called "ProductSale.php" in /override/classes/ with following code:

<?php
class ProductSale extends ProductSaleCore
{
    //  called for each product contained within an order, when an order's status is marked 'logable' (aka verified/paid)
    static public function addProductSale($product_id, $qty = 1)
    {
		    $goober = Db::getInstance()->Execute('
				    INSERT INTO '._DB_PREFIX_.'product_sale
				    (`id_product`, `quantity`, `sale_nbr`, `date_upd`)
				    VALUES ('.(int)($product_id).', '.(float)($qty).', 1, NOW())
				    ON DUPLICATE KEY UPDATE `quantity` = `quantity` + '.(float)($qty).', `sale_nbr` = `sale_nbr` + 1, `date_upd` = NOW()'
			 );
		    // check remaining product quantity subsequent to the sale transaction and, if sold out, set product.active=0 (aka disabled/draft, does not display in catalog)
		    $smurf = Db::getInstance()->getValue('SELECT `quantity` from `'._DB_PREFIX_.'product` WHERE `id_product` = '.(int)$product_id);
		    if ($smurf <= 0 )
		    {
				  Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'product` SET `active` ='. (int)0 .' WHERE `id_product` = '.(int)$product_id);
		    }
		    return $goober;
    }
}
?>

 

that worked for me on 1.4

  • Like 1
Link to comment
Share on other sites

mr10, thank you for the posting.

 

I only made a file "productsale.php" and put it in /override/classes/ that's all ??

 

I test it with an order, product quantity = 0 but the product is still active.

So for me it is not working. I use 1.4.5.1.

 

Have somebody an idea, how to get it work in 1.4.5.1

Link to comment
Share on other sites

don't know if it matters, but did you use capitals? ProductSale.php (not productsale.php)

i have tried it back then and it worked on 1.4.1, but do not use it anymore, because the client did not want this feature anymore, so i do not know if it is still the complete solution, sorry...

Link to comment
Share on other sites

  • 1 month later...

I'm having the same issue. I am using Store Manager to update the product quantity to "0" and it showed up the "Notify me when available"

 

However, I am still able to add a product to stock and check-out. Also, it still shows it's available. I checked the back-office product page, and it shows the combination attributes still "1" I believe this is what's causing the product still be labeled as available yet unavailable. Anyway where if the product quantity is set to zero that the product will be unavailable to add to cart?

Link to comment
Share on other sites

  • 1 month later...

as posts by 'angora' disappeared and with it the solution i used, i put the solution here again:

 

 

make a file called "ProductSale.php" in /override/classes/ with following code:

<?php
class ProductSale extends ProductSaleCore
{
	//  called for each product contained within an order, when an order's status is marked 'logable' (aka verified/paid)
	static public function addProductSale($product_id, $qty = 1)
	{
			$goober = Db::getInstance()->Execute('
					INSERT INTO '._DB_PREFIX_.'product_sale
					(`id_product`, `quantity`, `sale_nbr`, `date_upd`)
					VALUES ('.(int)($product_id).', '.(float)($qty).', 1, NOW())
					ON DUPLICATE KEY UPDATE `quantity` = `quantity` + '.(float)($qty).', `sale_nbr` = `sale_nbr` + 1, `date_upd` = NOW()'
			 );
			// check remaining product quantity subsequent to the sale transaction and, if sold out, set product.active=0 (aka disabled/draft, does not display in catalog)
			$smurf = Db::getInstance()->getValue('SELECT `quantity` from `'._DB_PREFIX_.'product` WHERE `id_product` = '.(int)$product_id);
			if ($smurf <= 0 )
			{
				  Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'product` SET `active` ='. (int)0 .' WHERE `id_product` = '.(int)$product_id);
			}
			return $goober;
	}
}
?>

 

that worked for me on 1.4

 

THANK YOU! works for me in PS 1.4.6.2

 

Note: it only works when a customer buy the last product, not when you change the quantity to 0 manually.

Link to comment
Share on other sites

  • 6 months later...

Is there something else what I have to do ?

 

Only put the file in /override/classes

 

Please is there anybody who can help me. I need it for my webshop.

 

 

I know that it is been a while, but maybe someone will need it :)

 

It works only when customer buy last product, then payment must be accepted and product must be sent.

When all this condiotion are checked, product is disable.

 

It works for me in PS 1.4.4.1

Edited by jakoushirou (see edit history)
Link to comment
Share on other sites

  • 1 month later...
I know that it is been a while, but maybe someone will need it :) It works only when customer buy last product, then payment must be accepted and product must be sent. When all this condiotion are checked, product is disable. It works for me in PS 1.4.4.1

Works in 1.4.9 with same conditions (payment accepted and product shipped)

Thank you for the tip!!

 

DimaM

Link to comment
Share on other sites

  • 10 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...