Jump to content

Show only products in stock


Recommended Posts

  • 2 years later...

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)
Link to comment
Share on other sites

  • 7 months later...
  • 3 years later...
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.

  • Like 1
Link to comment
Share on other sites

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...