Stock levels on front-end only take one type of stock into account

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
yeh
Posts: 39
Joined: 27 Jun 2022, 13:26

Stock levels on front-end only take one type of stock into account

Post by yeh » 21 Oct 2022, 09:42

On the front-end of the site, the page makes a separate request to /default/shop/stock to retrieve the stock levels for each item in a selection product.

This data is retrieved from the data method on Aimeos\Client\Html\Catalog\Stock\Standard

However, this function only returns stock of a single type (the standard/default type by default). I see I can set a config setting per site to change which type is selected, but if I have a product with stock type "warehouse-1" > 0, it will not show as being in stock on the frontend unless "Standard" stock is also > 1.

Is there a way to have this function check all available stock types?

yeh
Posts: 39
Joined: 27 Jun 2022, 13:26

Re: Stock levels on front-end only take one type of stock into account

Post by yeh » 21 Oct 2022, 09:47

Just a quick follow-up on this, it looks like the slice() function is restricting the stock returned.

If I remove that, then all stock is found including "warehouse-1"

Code: Select all

$sort = $context->config()->get( 'client/html/catalog/stock/sort', 'stock.type' );
$type = $context->locale()->getSiteItem()->getConfigValue( 'stocktype' );

$view->stockProductIds = $prodIds;
$view->stockItemsByProducts = \Aimeos\Controller\Frontend::create( $context, 'stock' )
    ->product( $prodIds )->type( $type )->sort( $sort )
    /*->slice( 0, count( $prodIds ) )*/
    ->search()
    ->groupBy( 'stock.productid' );

return parent::data( $view, $tags, $expire );
Would there be any harm in overriding this class/method to remove the slice?

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

Re: Stock levels on front-end only take one type of stock into account

Post by aimeos » 21 Oct 2022, 11:11

If you create a pull request, we are happy to merge the fix :-)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

yeh
Posts: 39
Joined: 27 Jun 2022, 13:26

Re: Stock levels on front-end only take one type of stock into account

Post by yeh » 21 Oct 2022, 12:05

Sure, no problem. I have just submitted a pull request now :)

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

Re: Stock levels on front-end only take one type of stock into account

Post by aimeos » 21 Oct 2022, 12:07

Thanks! Now it's merged and also available in 2022.10.x-dev until a new version is tagged.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply