Buona giornata Guilio, Thank you for the detailed email. It is much appreciated. I will read the ticket at a more convenient time, and will respond (if I have anything to contribute) there.
Met vriendelijke groet, Pierre Smits *Proud* *contributor** of* Apache OFBiz <https://ofbiz.apache.org/> since 2008 (without privileges) *Apache Directory <https://directory.apache.org>, PMC Member* Apache Incubator <https://incubator.apache.org>, committer Apache Steve <https://steve.apache.org>, committer On Mon, Nov 1, 2021 at 4:08 PM Giulio Speri - MpStyle Srl < giulio.sp...@mpstyle.it> wrote: > Hello everyone, > > I hope you're doing well. > > I write here because I think I faced an issue in the ecommerce listing of > products related to the ProductFacility entity and the filtering of out of > stock products. > > Here's the context: > - an ecommerce site where products are configured as a virtual-variant > relationship. > - a virtual product (parent) has color and size features associated as > selectable, and its variants are all the combinations of colors and sizes. > - in such a configuration InventoryItem records are registered for variant > products (the actual sold products) and not for virtual products. > - the product store is configured to not show out of stock products. > - a record of ProductFacility is created for each product variant where its > lastInventoryCount is automatically updated as soon as availability are > imported/created (through PHYSICAL INVENTORY); > - virtual products are associated to some ProductCategories; > > *Issue*: > Products are not shown in category listing also if they have stock > availability. > > *Issue details:* > Listing of products is done through the screen " > *CatalogScreens.xml#categorydetail*" and the *CategoryDetail.groovy* script > is used to retrieve the list of products to show. > > In the groovy script the service responsible to get the product category > members to show is *getProductCategoryAndLimitedMembers, *which checks and > filters out of stock products (if ProductStore is configured to do so). > > Filtering out of stock products is done using > *ProductWorker.java#filterOutOfStockProducts > *method, that sums up all the lastInventoryCount (in all the facilities) of > each category member and if sum is GT 0 the (virtual) product is kept and > shown in listing. > > The lastInventoryCount field in the table ProductFacility is updated > through the eeca service *setLastInventoryCount* on create/update on entity > InventoryItemDetail. > This service works only on the product on which a stock move is committed > (in my case a specific product variant): it's (virtual) parent is never > considered. > > That behaviour, in addition to the fact that filterOutOfStock method works > on the category members that are the virtual parents, leads to products to > not be shown in listing also if they have stock availability. > > *Possible solutions:* > From my point of view there are two ways to fix this. > > *1)* add the handling of lastInventoryCount on virtual parents to the > service setLastInventoryCount; the lastInventoryCount of the parent should > be the sum of all its variant in the same facility, and each time a variant > is modified, the related parent should be modified too. > > *2)* add the handling of virtual products in the ProductWorker.java# > *filterOutOfStockProducts*: here when a virtual product category member is > processed, all its variants should be retrieved and their > lastInventoryCount added up through all facilities. > Only if the sum of all the variants in all the facilities is GT 0, then we > can keep and show the virtual product. > > *Considerations:* > After a bit of research within the whole OFBiz project (R17.12.06) the > lastInventoryCount field has quite limited direct usage (basically only for > ecommerce scopes). > I think solution 2) is better, because I think that the ProductFacility > entity should not contain record for "virtual" products (products that > physically won't be sold, since you will sell a variant of it; for the same > reason virtual products should not have InventoryItem records associated). > > I think that solution 1) instead is not so clean and forced to adopt > inventory item concepts also for virtual products, that in my opinion it > does not make too much sense. > > > Sorry for the long email, but I tried to retrieve as many details as > possible and I would be very happy to know your thoughts about it. > > I opened an issue in Jira (OFBIZ-12359 > <https://issues.apache.org/jira/browse/OFBIZ-12359>) for this. > > Thanks in advance for your attention and help. > > Giulio > > -- > Giulio Speri > > > *Mp Styl**e Srl* > via Antonio Meucci, 37 > 41019 Limidi di Soliera (MO) > T 059/684916 > M 347/0965506 > > www.mpstyle.it >