Jump to content
brownd92

Show only products in stock

Recommended Posts

This question was asked so many times and no one offered a solution so here is a basic simple one that i think works fine with 1.6 :

 

P.S : This solution doesnt work With products randomized

Step 1 : go to Modules/homefeatured/homefeatured.php  -  Look for  : 

 

if (Configuration::get('HOME_FEATURED_RANDOMIZE'))
HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), null, null, false, true, true, ($nb ? $nb : 8));
else
HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');
}
 
Replace with : 
 
if (Configuration::get('HOME_FEATURED_RANDOMIZE'))
HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'quantity', 'DESC', false, true, true, ($nb ? $nb : 8));
else
HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'quantity','DESC');
}
 
 
Step 2 : Go to Product-list.tpl  - At the end of the <li class="ajax_block_product..............  before you close the li add this code : style="{if $page_name=='index' && $product.quantity < 1 }display:none{/if}"
 
Ex : <li class="ajax_block_product.LONGBLALALALALA" style="{if $page_name=='index' && $product.quantity < 1 }display:none{/if}">
 
 
And Voila ! you'll get Only in stock products in home featured
 
 
 
EXTRA : 
 
 
Basicaly what it does is show product list ordered by Quantity
so it first shows Products that are in stock and at the end it adds the products that arent . And all i do is hide these products at the end and it doesnt not affect the order of products nor the Css style...
 
 
 
EXTRA 2 : 
 
If you want to do the same thing on Category pages all you have to do is  :
 
STEP 3 : go to controllers/front/CategoryController.php  -  Look for  :
 
if (!$hookExecuted)
{
$this->context->smarty->assign('categoryNameComplement', '');
$this->nbProducts = $this->category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
}
 
 
Replace with : 
 
if (!$hookExecuted)
{
$this->context->smarty->assign('categoryNameComplement', '');
$this->nbProducts = $this->category->getProducts(null, null, null, 'quantity', 'DESC', true);
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, 'quantity', 'DESC');
}
 
REPLACE STEP 2 WITH THIS ONE  :  Go to Product-list.tpl  - At the end of the <li class="ajax_block_product..............  before you close the li add this code : style="{if $product.quantity < 1 }display:none{/if}"
 
Ex : <li class="ajax_block_product.LONGBLALALALALA" style="{if $page_name=='index' && $product.quantity < 1 }display:none{/if}">
 
 
AND VOILA 2
 
 
 
 
forgive my english :P hope this helps
 
 
Edited by Htiti Chihab Eddine (see edit history)

Share this post


Link to post
Share on other sites

In \classes\Category.php change

WHERE product_shop.`id_shop` = '.(int)$context->shop->id.'

to

WHERE stock.`quantity` > 0 AND product_shop.`id_shop` = '.(int)$context->shop->id.'

Share this post


Link to post
Share on other sites

anyone reading this should consider the seo implications which I suppose are only relevant if the product never comes back into stock.  if it does then what are the implications?

anyone can write a hack/module to do 'something' but that does not mean it's always a good idea.

happy selling

Share this post


Link to post
Share on other sites

Our test of 6 months showed that the 90-99% of on-line buyer wants only products ready on stock, so showing products with no stock is only counterproductive.

Share this post


Link to post
Share on other sites
4 hours ago, MaxV2019 said:

Our test of 6 months showed that the 90-99% of on-line buyer wants only products ready on stock, so showing products with no stock is only counterproductive.

well granted we don't want to be shown 'out of stock' products unless it supports capability to notify us but if you have products that come and go out of stock what then is your  answer on hiding temporarily out of stock item and organic seo.

again it's easy to blanket justify to do something but I challenge that it's not a good idea unless that product has 1) really long restock delay 2) is never going to be sold again, in either case the 404 should be handled elegant.

There is difference between low end shops that implement something that 'can be done' but is not always perfectly thought out.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More