I would like to display the out of stock products at the end of my catalog.
This functionality was available in M 1.9 (and maybe before), and for some reason it is not available anymore, not in system configuration nor store configuration options.
Cannot reproduce the issue, "out of stock" products are at the end.
Write more detailed steps to reproduce.
@odubovyk It's actually the issue. Out of stocks products and in-stock products are on mixed together. I want to display out of stock products at the end of the catalog.
Please check here: http://vps307618.ovh.net/chaise-chesterfield
You will see the out of stock products mixed with in stock products.
I believe, current info is not enough, as I've said we need more details of steps to reproduce.
Please see steps to reproduce section in https://github.com/magento/magento2/wiki/Issue-reporting-guidelines.
According to contributor guide, tickets without response for two weeks should be closed.
If this issue still reproducible please feel free to create the new one: format new issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result and specify Magento version.
i think this issue is so important,
the meaning of this issue is this :
Show in stock products first and out of stock products last
i will explain by an example
it happened sometimes that whole products of a category are out of stock, by the only option provided by magento, they all will be hidden, so if a user try to browse site by categories menu, he will just see "no products found!" and say what a stupid shop is this that created some empty categories!
but if the user be able to see the out of stock products, can contact admin for some other products and don't think about the stupidity of the shop anymore :D
this example was just for importance of out of stock products,
but think you are in a category which on it's first page, you have for example 10 in stock products and 10 out of stock products, absolutely a customer which enter a shop, just want to see the in stock products, so they should be listed first, and as I explained the importance of out of stock products, they should be listed at last
so I think the best option is this:
first in stock products be visible and after them out of stock products
is this clear now?
My tested version is 2.1.9
PHP is 7.0.22
with nginx webserver
Shouldn't be opened again?
@MMaKenZi, nope, as far as I can say.
GitHub is intended for bug reports, please use Community Forums for other suggestions like improvements or feature requests.
I left M2 for Prestashop, I think everyone knows the reason why.
It is definitely a bug, not a feature request. I mean who will want to display out of stock products, who cannot be ordered, mixed with in-stock products.
Anyway, a nasty trick I did in the past was to add a "custom field" (don't remember the exact nomination for M2), to each product.
Each product who is in stock gets value 1
Each product who is out of stock gets value 2
Then you can sort the catalog (from the admin) to display products with custom field value == 1 first, and all the others after.
If you have a lot of products, like us in the past (more than 50k), you should then make a CSV import with the field already set and value applied.
Matters of hours, but was working pretty well back in time.
Good luck
Each product who is in stock gets value 1
Each product who is out of stock gets value 2
That sounds like a hack, it is quite easy to achieve desired behavior with custom implementation (since stock information is already in collection, you just need to add additional sorting).
IT IS a feature request in fact, although such feature is quite easy to implement, not sure it would be in-demand in core. Quite often out-of-stock products are simply not displayed (there is an option for this) or backorders are enabled so that stock status does not really matter.
I understand your saying, though I don't agree at all with you.
If a company using SEO as a traffic acquisition way, they HAVE to display out of stock products, doesn't matter if backorders are enabled or not.
Depending on how you are using Magento, it is a BUG or a FEATURE REQUEST.
As far as the impact of the problem is big (and old) enough, this is something that should be corrected.
I will do the code changes and post them here tonight, it might be useful for some people who can't wait for it.
I will do the code changes and post them here tonight, it might be useful for some people who can't wait for it.
Oh, just post a PR so that it can get merged into core (targeting 2.2-develop if it is not breaking BC). We need a PO approval to add features but as you can provide a real-world use case it should not be a problem.
We have the same needs. Any progress with this feature?
Have you had any chance to do that @yofisim ?
Not to create an "Angry Mob" Echo Chamber, but I'd love to see what you've come up with, @yofisim ! I've been hoping to do this exact modification on my instance and am eager to see how it can be achieved.
Hi guys,
unfortunately no, it was more complicated than I expected, and I left Magento to be fairly honest.
But again, I do remember how I tricked this to make it work. Just check my previous comments.
If it is not clear, here is how I achieve it (don't pay attention to the terms I use, as they are probably not the exact name on Magento. Just get the process, than replicate) :
1) I created a "custom attribute" for all my products called stock.
2) Using CSV import, I added to the stock field:
3) Once import is finished, when you are on the catalog product view in the admin, you can customize the sorting of the catalog. Apply the sorting on the custom attribute "stock", with the value ASC (ascending).
4) Done. All your products will be sorted with in-Stock first, and then out of stock, at the end of the catalog.
Hope this helps.
Edit: as @orlangur stated, it is definitely a hack, and I suggest you to find better solutions to manage your products displaying. It was working for me, because I had endless stock on "in-stock products". And when a product is out-of-stock, it was for a long time. Adapt to your situation.
@yofisim thanks for described approach. Yeah, something like that should be possible with a custom implementation on top of collection query instead of an additional attribute like you achieved it.
however, it is not the solution in configurable products, since the configurable products do not carry independent stock.
In my store, if I used that method, all configurables would always be at the end, because when importing the stock, the configurables do not change with stock / without stock
in M1 I used this module that worked to perfection, but I do not find something similar in M2
https://github.com/cgzhang/Rayfox_Catalog
I created something to do this:
https://github.com/bengower/OosBottom
It's loosely based on the Rayfox_Catalog module
alvaialex, unfortunately the extension you cite was not compatible with my 2.2.3 install. It trashed my front end. Oh well, at least I only installed it on a dev environment
Thanks for the suggestion, though.
@bengower your suggested extension does not support while change drop down value in toolbar
In your di.xml add:
<type name="Magento\Catalog\Model\Layer">
<plugin name="orderOutOfStock" type="Vendor\Module\Plugin\Model\Layer" sortOrder="999"/>
</type>
Then your Layer.php:
<?php
/**
* @author JKetelaar
*/
namespace Vendor\Module\Plugin\Model;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
class Layer
{
/**
* @param \Magento\Catalog\Model\Layer $subject
* @param Collection $collection
* @return mixed
*/
public function afterGetProductCollection(\Magento\Catalog\Model\Layer $subject, $collection)
{
$collection->getSelect()->order('is_salable DESC');
return $collection;
}
}
This works both with changing the order in the frontend (as @visahardik mentioned) and with custom modules, such as the Amasty Improved Layered Navigation module.
@JKetelaar using afterGetProductCollection() applied the sort order several times for me, I had better luck with beforePrepareProductCollection() which is called once in getProductCollection and then cached -
/**
* Sort items that are not salable last
*
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
*/
public function beforePrepareProductCollection(
\Magento\Catalog\Model\Layer $layer,
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
) {
// apply sort order
$collection->getSelect()->order('is_salable DESC');
// make sure this sort is first applied to the results
$orderBys = $collection->getSelect()->getPart(\Zend_Db_Select::ORDER);
array_unshift($orderBys, array_pop($orderBys));
$collection->getSelect()->setPart(\Zend_Db_Select::ORDER, $orderBys);
return [$collection];
}
Most helpful comment
We have the same needs. Any progress with this feature?