Вопрос

A client is using Magento 2.1.3 with the Porto theme. The homepage of that site has a div which has tabs of different categories with the most bought items. Per category it loads a block in the following way:

{{block class="Smartwave\Filterproducts\Block\Home\BestsellersList"
 name="nachtmode_product" category_id="5" product_count="4"
 column_count="4" move_actions="1" aspect_ratio="0" image_width="250"
 image_height="250" template="grid.phtml"}}

It makes use of a BestSellersList.php. Its primary function is returning a $collection, which has the products that are relevant. What it does, just before returning is a query on the DB in the following way (ive tried to separate the parts for an easy read):

        $collection->getSelect()
->joinLeft(['soi' => $connection>getTableName('sales_order_item')], 'soi.product_id = e.entity_id', ['SUM(soi.qty_ordered) AS ordered_qty'])
            
->join(['order' => $connection->getTableName('sales_order')], "order.entity_id = soi.order_id",['order.state'])
            
**->join(['quantity'=> $connection->getTableName('cataloginventory_stock_item')], "quantity.product_id = e.entity_id")**
            
->where("order.state <> 'canceled' and soi.parent_item_id IS NULL AND soi.product_id IS NOT NULL AND **quantity.is_in_stock = 1"**)
            
->group('soi.product_id')
            
->order('ordered_qty DESC')
            
->limit($count);

The bold parts are what I have added so I can also filter if a product is in stock, which almost works (at least for simple products).

Here is the problem: The items shown on the frontpage are mostly configurable products. Somehow these products are always in stock (so 1 instead of 0), even when their child products have a quantity of 0 and are marked as out of stock.

So my questions:

  1. Does Magento not mark a parent product as out of stock when their child products are 0 and out of stock? Or is there a specific setting for this?

  2. If the above is not available, does anyone have a good addition to the query above OR has a good approach on how I can also make sure the configurable products that are out of stock are not shown on the frontpage?

I thank you kindly for any helpful responses!

Нет правильного решения

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top