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: 33
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: 8647
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: 33
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: 8647
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

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

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

Post by DNK » 08 Aug 2025, 04:37

I added your piece of code. But unfortunately, nothing changed.
Image

Code: Select all

<?php

namespace App\Providers;

use Illuminate\Validation\Rules\Password;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Schema;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Password::defaults(function () {
            $rule = Password::min( 8 );
            return $this->app->isProduction() ? $rule->mixedCase()->uncompromised() : $rule;
        });


        // for multi-locale/site setups
        \Illuminate\Auth\Notifications\ResetPassword::createUrlUsing(function($notifiable, $token) {
            return url(airoute('password.reset', [
                'email' => $notifiable->getEmailForPasswordReset(),
                'token' => $token,
            ], false));
        });


        // for multi-locale/site setups
        \Illuminate\Auth\Notifications\VerifyEmail::$createUrlCallback = function($notifiable) {
            $time = Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60));
            $params = [
                'id' => $notifiable->getKey(),
                'hash' => sha1($notifiable->getEmailForVerification()),
            ];

            if( config( 'app.shop_multilocale' ) ) {
                $params['locale'] = Request::route( 'locale', Request::input( 'locale', app()->getLocale() ) );
            }

            if( config( 'app.shop_multishop' ) || config( 'app.shop_registration' ) ) {
                $params['site'] = Request::route( 'site', Request::input( 'site', config( 'shop.mshop.locale.site', 'default' ) ) );
            }

            return URL::temporarySignedRoute('verification.verify', $time, $params);
        };


        // Aimeos admin check for backend
        \Illuminate\Support\Facades\Gate::define('admin', function($user, $class, $roles) {
            if( isset( $user->superuser ) && $user->superuser ) {
                return true;
            }
            return app( '\Aimeos\Shop\Base\Support' )->checkUserGroup( $user, $roles );
        });


        // Aimeos context for icon and logo in all Blade templates
        View::composer('*', function ( $view ) {
            try {
                $view->with( 'aimeossite', app( 'aimeos.context' )->get()->locale()->getSiteItem() );
            } catch( \Exception $e ) {
                $view->with( 'aimeossite', \Aimeos\MShop::create( app( 'aimeos.context' )->get( false ), 'locale/site' )->create() );
            }
        });


        // resolve CMS pages sharing same route as categories and products
        \Aimeos\Shop\Controller\ResolveController::register( 'cms', function( $context, $path ) {
            return $this->cms( $context, $path );
        });

        Schema::defaultStringLength(191);

        \Aimeos\Client\Html\Catalog\Lists\Standard::macro('conditions', function($cntl, $view) {
            $cntl->sort('-product.instock');
        });
    }
}
Aimeos 2024.10.3 + Laravel 11, PHP 8.2, MySql8.0, Nginx, Ubuntu 22.04.5 LTS

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

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

Post by aimeos » 08 Aug 2025, 08:58

Is the product.instock property set correctly when you import products?
It's not updated automatically at the moment because it would be costly to update it for each ordered product when the stock level changes.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

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

Post by DNK » 12 Aug 2025, 13:17

No, we did not import. We manually added products.

Out of stock:
Image

In stock:
Image

Did I set it up correctly?
Aimeos 2024.10.3 + Laravel 11, PHP 8.2, MySql8.0, Nginx, Ubuntu 22.04.5 LTS

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

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

Post by aimeos » 12 Aug 2025, 19:20

Unfortunately, this is the only product property that can be only set in a product import because it's meant for ERP systems informing Aimeos about products that are not available any more.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

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

Post by DNK » 14 Aug 2025, 07:35

So it turns out that there is absolutely no way to filter by availability in stock?
Aimeos 2024.10.3 + Laravel 11, PHP 8.2, MySql8.0, Nginx, Ubuntu 22.04.5 LTS

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

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

Post by aimeos » 14 Aug 2025, 07:38

Like said, you can sort/filter by stock when using product.instock property if you import products by CSV or XML.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply