You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by madppiper <pa...@mutschler.ch> on 2009/01/19 15:56:20 UTC

Re: How to hide empty (no stock) products and empty (no stock) categories?

Sorry for bringing up this old discussion, but I think this is really a neat
feature I would also be interested in. The Disc. - function only works for
the products, but does not work for the category-trees. This becomes a real
problem on my site, since products do not really last long, and it is a bad
user experience to search through empty categories. 

I have already added a function that lists at least the products of the
subcategories to a top level category, but I really think that it would be
alot wiser to simply drop the category from the sidedeepcategory.ftl file,
if no product is available. 

I was thinking about looping through the categories and using the
getProductCategoryAndLimitedMembers function for each in order to find a
solution, but I got a feeling that with an icnreasing number of products
available this would result in a huge unesseary waste of heapspace - not too
mention, that I am rather unsure about whether or not
getProductCategoryAndLimitedMembers already filters the products or not...
-- 
View this message in context: http://www.nabble.com/How-to-hide-empty-%28no-stock%29-products-and-empty-%28no-stock%29-categories--tp5758876p21544605.html
Sent from the OFBiz - User mailing list archive at Nabble.com.


Re: How to hide empty (no stock) products and empty (no stock) categories?

Posted by madppiper <pa...@mutschler.ch>.
Well, a tiny update on my side (just in case that anybody else is interested
in a solution). I did get around with that problem by introducing
view-entities:

I added the following to a entitymodel.xml file of my own: 

	<!-- View Entities for Categories -->
		<view-entity entity-name="ProductsAndInventory"
		package-name="org.brandsparadise.products">
		<description>
			Returns all Products and the coherent Inventory
		</description>
		
		<member-entity entity-alias="products"
entity-name="ProductAndCategoryMember" />
		<member-entity entity-alias="inv" entity-name="InventoryItem" />
		
		<alias-all entity-alias="products" group-by="true">
		</alias-all>	
		<alias entity-alias="inv" name="quantityOnHandTotal"  function="sum"/>
		<alias entity-alias="inv" name="availableToPromiseTotal"  function="sum"/>
		
		
		<view-link entity-alias="products" rel-entity-alias="inv"
rel-optional="true">
			<key-map field-name="productId" />
		</view-link>
		
		
 	  <relation type="one" rel-entity-name="InventoryItem">
        <key-map field-name="productId"/>
      </relation>  
	</view-entity>	


	<!--  -->
		<view-entity entity-name="CategoryAndInventory"
		package-name="org.brandsparadise.products">
		<description>
			Returns all Categories and the coherent Inventory of all products
belonging to the category
		</description>
		
		<member-entity entity-alias="products" entity-name="ProductsAndInventory"
/>
		<member-entity entity-alias="cat" entity-name="ProductCategory" />
		
		<alias-all entity-alias="cat" group-by="true">
		</alias-all>	
		
		<alias entity-alias="products" name="quantityOnHandTotal" 
function="sum"/>
		<alias entity-alias="products" name="availableToPromiseTotal" 
function="sum"/>
		
		<view-link entity-alias="cat" rel-entity-alias="products"
rel-optional="true">
			<key-map field-name="productCategoryId" />
		</view-link>
		
		
 	  <relation type="one" rel-entity-name="ProductsAndInventory">
        <key-map field-name="productCategoryId"/>
      </relation>  
	</view-entity>	


This will give me two tables: one of all products with their available
inventory and the other a list of all categories with all of their available
products... this is good news, because I can now skip through these tables
in the ftl file and simply remove any category or product that doesn't
happen to have any products available...

Of course, as always: feel free to give feedback! I am more than open for
improvements, so ... uhh... cheers :)



-- 
View this message in context: http://www.nabble.com/How-to-hide-empty-%28no-stock%29-products-and-empty-%28no-stock%29-categories--tp5758876p21706845.html
Sent from the OFBiz - User mailing list archive at Nabble.com.


Re: How to hide empty (no stock) products and empty (no stock) categories?

Posted by madppiper <pa...@mutschler.ch>.
Well, I gave this some more thought. My first solution would be to run
through each Product and check whether or not the quantityonhand is
existent. So as for the productsummary screens, which are featured in the
categories, I ran through the categorydetail.groovy page and added: 

[...]
catResult = dispatcher.runSync("getProductCategoryAndLimitedMembers",
andMap);

//run through the products and sort out anything that isn't available
productCategoryMembers = catResult.get("productCategoryMembers");
for(int i = 0; i<productCategoryMembers.size(); i++){
    quantity = dispatcher.runSync("getInventoryAvailableByFacility",
[productId : productCategoryMembers[i].productId, facilityId :
"WebStoreWarehouse", useCache : true]).quantityOnHandTotal;
    //System.out.println(quantity);
    productCategoryMembers[i].put("quantity",quantity);
}
[...]



I noticed that the quantity label is really not all that important (either
that, or i didn't fully grasp the meaning ;) ), so I reused that mapping
field to add the actual qualityathand to any GenericValue. I could then
simply check within the ftl files whether or not quantity equals 0...

But here's the thinker that really got to me: I personally don't think that
this approach is either recommandable nor fast. This may work fine with a
small quantity of products, but should really be a pain if that list
increases... The categorylisting itself is actually a far bigger problem,
since I would want to check for each category, whether or not any of their
subcategories or the category itself has any products with a quantityathand
!= 0. So if I would do it in any way similar to the approach above, I would
be stuck running through the categories, generating huge lists of products
(this would have to be done on the fly also) and calling the above sequence
over and over again - which again leads me to the conclusion, that anything
like this approach is really dangerous with an increasing number of
products...

Of course there is a workaround using entitytables, that I could do. But it
remains curious to me, that nobody ever wanted to achieve anything alike
before me... Wouldn't you agree that it would be only userfriendly to add a
check-mechanism to the categories, that removes the categories from the
screen if no product is available?







-- 
View this message in context: http://www.nabble.com/How-to-hide-empty-%28no-stock%29-products-and-empty-%28no-stock%29-categories--tp5758876p21701987.html
Sent from the OFBiz - User mailing list archive at Nabble.com.


Re: How to hide empty (no stock) products and empty (no stock) categories?

Posted by BJ Freeman <bj...@free-man.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I would tackle it groovy and ftl for catagories and Products detail.
I would in the groovy mark each category as no stock
then in the ftl I would not display the No stock catagories
same for products.
Hope you get the idea, it is kinda sketchy

madppiper sent the following on 1/20/2009 5:10 AM:
> 
> Does anybody have an idea on how to solve this?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJdiN4rP3NbaWWqE4RAobRAKC1hhm0LyCiObUPdtLilW1bPBr7MwCgxnpC
fjT5Q7YaaVKAti3YBVLR7vA=
=GMOJ
-----END PGP SIGNATURE-----

Re: How to hide empty (no stock) products and empty (no stock) categories?

Posted by madppiper <pa...@mutschler.ch>.

Does anybody have an idea on how to solve this?
-- 
View this message in context: http://www.nabble.com/How-to-hide-empty-%28no-stock%29-products-and-empty-%28no-stock%29-categories--tp5758876p21562761.html
Sent from the OFBiz - User mailing list archive at Nabble.com.