How to hide products that are out of stock?

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
DNK
Posts: 29
Joined: 27 Feb 2025, 10:50

How to hide products that are out of stock?

Post by DNK » 30 Jul 2025, 12:55

How to hide products that are out of stock?
I am also interested in the possibility of first displaying those that are in stock, and then those that are out of stock
Aimeos 2024.10.3 + Laravel 11, PHP 8.2, MySql8.0, Nginx, Ubuntu 22.04.5 LTS

User avatar
aimeos
Administrator
Posts: 8640
Joined: 01 Jan 1970, 00:00

Re: How to hide products that are out of stock?

Post by aimeos » 31 Jul 2025, 06:53

Stock levels are loaded async by JS due to their volatile nature:
https://github.com/aimeos/ai-client-htm ... er.php#L87

If you know at the time of the import that the product is already out of stock, you can set product.instock=0 and enable the "client/html/catalog/instock" option (set to true or 1).

To dynamically mark or hide variant articles which are out of stock, you have to adapt the JS code in catalog/stock/body.php template and remove the variant articles without stock in the catalog detail page:
https://github.com/aimeos/ai-client-htm ... k/body.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
DNK
Posts: 29
Joined: 27 Feb 2025, 10:50

Re: How to hide products that are out of stock?

Post by DNK » 31 Jul 2025, 10:47

Thank you! That's what I needed.
As for the second point, I probably asked the question incorrectly.
My task is to have the products that are in stock at the top of the product list, and then display the ones that are not in stock after them.
Aimeos 2024.10.3 + Laravel 11, PHP 8.2, MySql8.0, Nginx, Ubuntu 22.04.5 LTS

User avatar
aimeos
Administrator
Posts: 8640
Joined: 01 Jan 1970, 00:00

Re: How to hide products that are out of stock?

Post by aimeos » 31 Jul 2025, 11:13

You need to sort by product.instock and you can use that sorting by adding a macro in \App\Providers\AppServiceProvider::boot():

Code: Select all

\Aimeos\Client\Html\Catalog\Lists\Standard::macro('conditions', function($cntl, $view) {
    $cntl->sort('-product.instock');
});
See here: https://github.com/aimeos/ai-client-htm ... #L420-L447
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply