I am just trying to find the defaultPrice of every product
I have written this code delegator = request.getAttribute("delegator"); List products = delegator.findAll("Product"); context.put("products",products); List productlist = FastList.newInstance(); Iterator catalogsItr = products.iterator(); while (catalogsItr.hasNext()) { GenericValue catalog = (GenericValue) catalogsItr.next(); product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId",catalog.getString("productId"))); priceContext = UtilMisc.toMap("product", product); priceMap = dispatcher.runSync("calculateProductPrice", priceContext); } But it is not working ,Please help ASAP |
I tried to understand your code.....however writing new is perhaps easier.....
List productPrices = delegator.findByAnd( "ProductPrice", UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); in productPrices there will be the productId If you want more info from the product you can use the ProductAndPriceView instead... please also note that prices have a valid date.... regards, Hans On Thursday 10 May 2007 12:44, subhasis wrote: > I am just trying to find the defaultPrice of every product > I have written this code > > > delegator = request.getAttribute("delegator"); > List products = delegator.findAll("Product"); > context.put("products",products); > > > List productlist = FastList.newInstance(); > Iterator catalogsItr = products.iterator(); > while (catalogsItr.hasNext()) > { > GenericValue catalog = (GenericValue) catalogsItr.next(); > product = delegator.findByPrimaryKey("Product", > UtilMisc.toMap("productId",catalog.getString("productId"))); > priceContext = UtilMisc.toMap("product", product); > priceMap = dispatcher.runSync("calculateProductPrice", priceContext); > } > > But it is not working ,Please help ASAP http://Antwebsystems.com: Quality OFBiz support with competitive rates. |
In reply to this post by subhasis
Version: the latest one. The trunk version May 9, 2007.
Procedure: I just add a New Securtiy Group. I got an error return. It does create the security group, however, it try to do it twice. |
I have found this issue is only on IE7. My Firefox is normal.
----- Original Message ----- From: "Kane Lo" <[hidden email]> To: <[hidden email]> Sent: Thursday, May 10, 2007 3:03 PM Subject: Minor Bug: Create Security group, the action tried to do twice. > Version: the latest one. The trunk version May 9, 2007. > Procedure: > I just add a New Securtiy Group. I got an error return. It does create > the security group, however, it try to do it twice. > |
In reply to this post by hans_bakker
make sure that you set the price for this product
I didn't found any error in that code ,are you getting any error or it is not getting diaplayed can provide some more information On 5/10/07, Hans Bakker <[hidden email]> wrote: > > I tried to understand your code.....however writing new is perhaps > easier..... > > List productPrices = delegator.findByAnd( > "ProductPrice", UtilMisc.toMap("productPriceTypeId", > "DEFAULT_PRICE")); > > in productPrices there will be the productId > > If you want more info from the product you can use the ProductAndPriceView > instead... > > please also note that prices have a valid date.... > > regards, > Hans > > On Thursday 10 May 2007 12:44, subhasis wrote: > > I am just trying to find the defaultPrice of every product > > I have written this code > > > > > > delegator = request.getAttribute("delegator"); > > List products = delegator.findAll("Product"); > > context.put("products",products); > > > > > > List productlist = FastList.newInstance(); > > Iterator catalogsItr = products.iterator(); > > while (catalogsItr.hasNext()) > > { > > GenericValue catalog = (GenericValue) catalogsItr.next(); > > product = delegator.findByPrimaryKey("Product", > > UtilMisc.toMap("productId",catalog.getString("productId"))); > > priceContext = UtilMisc.toMap("product", product); > > priceMap = dispatcher.runSync("calculateProductPrice", priceContext); > > } > > > > But it is not working ,Please help ASAP > -- > > http://Antwebsystems.com: Quality OFBiz support with competitive rates. > |
Could somebody clarify how one would generate a list of products that additionally also contain the prices?
I myself got: delegator = request.getAttribute("delegator"); products = delegator.findAll("Product"); context.put("products", productPromos); /*Find Prices*/ List productPrices = delegator.findByAnd( "ProductPrice", UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); context.put("priceMap", productPrices); But that, of course, wouldn't print out the correct price of any product... how do i access that data or put them both into relation? |
Administrator
|
You shoud use getRelated. Look into InventoryItemTotals.groovy
Jacques From: "madppiper" <[hidden email]> > > Could somebody clarify how one would generate a list of products that > additionally also contain the prices? > > I myself got: > > delegator = request.getAttribute("delegator"); > products = delegator.findAll("Product"); > > context.put("products", productPromos); > > /*Find Prices*/ > List productPrices = delegator.findByAnd( > "ProductPrice", UtilMisc.toMap("productPriceTypeId", > "DEFAULT_PRICE")); > context.put("priceMap", productPrices); > > > > But that, of course, wouldn't print out the correct price of any product... > how do i access that data or put them both into relation? > -- > View this message in context: http://www.nabble.com/Cannot-Retrive-price-from-ProductPrice-tp10407489p20816146.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > |
Hmm, that does make sense...
and how would you combine both results to one combined resultList? Do I have to use LinkedList for that? |
Administrator
|
I'm not sure what you are looking for. A view could be a solution.
Jacques From: "madppiper" <[hidden email]> > > Hmm, that does make sense... > > and how would you combine both results to one combined resultList? > > > Do I have to use LinkedList for that? > -- > View this message in context: http://www.nabble.com/Cannot-Retrive-price-from-ProductPrice-tp10407489p20830590.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > |
Nah,
but I think I found the answer myself in the UtilMisc,toList function ;) Thx for your support, though ;) |
Alright,
this is driving me insane, and after searching all through the available ofbiz screens and beanshell files, I would really appreciate some help on this. All I want to do is to retrieve a sample of four products (randomly selected) that contains the description, title, price, listprice, productId and brandName, so that I can access the information via ftl later on and display 4 productboxes... I got the first part together just fine: /*Find Products*/ delegator = request.getAttribute("delegator"); products = delegator.findAll("Product"); productShowLimit=4; //now slim it down to promoShowLimit productArrayList = new ArrayList(products); productPromos = null; if (productArrayList.size() > productShowLimit) { productPromos = new ArrayList(productShowLimit); for (i = 0; i < productShowLimit; i++) { randomIndex = Math.round(java.lang.Math.random() * (productArrayList.size() - 1)); productPromos.add(productArrayList.get((int) randomIndex)); } } else { productPromos = productArray; } But I cannot get my head around on how to link this information to the listPrice... getRelatedOne on ProductPrice retrieves all the prices for a certain product: productPrices = null; Iterator p = productPromos.iterator(); while(p.hasNext()){ GenericValue p = (GenericValue) p.next(); prices = p.getRelated("ProductPrice"); System.out.println("Out: "+ prices); } But i cannot combine that information with the previous resultMap (productPromos )... Also, I've read on http://www.opensourcestrategies.com/ofbiz/ofbiz_entity_cookbook.txt that you shouldn't access the product data table directly (which makes sense), and so I can't help but wonder on whether there are easier/already existing ways of what I am trying to accomplish... |
normally you use a view-entity.
this lets you group entities and chose the fields you want then you query the view-entity like any other. Like in Databases, you must have all the relationships satisfied for any row you want to display. Note you can build a view-entity on the fly, but for debug purposes, I use the xml version so I can see the results in the web tools. I like this method of queries using findList and EntityCondition.makeCondition(exprs, EntityOperator.AND you can find examples of this. madppiper sent the following on 12/4/2008 4:02 AM: > Alright, > > this is driving me insane, and after searching all through the available > ofbiz screens and beanshell files, I would really appreciate some help on > this. > > All I want to do is to retrieve a sample of four products (randomly > selected) that contains the description, title, price, listprice, productId > and brandName, so that I can access the information via ftl later on and > display 4 productboxes... > > I got the first part together just fine: > > /*Find Products*/ > delegator = request.getAttribute("delegator"); > products = delegator.findAll("Product"); > productShowLimit=4; > > > > > //now slim it down to promoShowLimit > productArrayList = new ArrayList(products); > > productPromos = null; > if (productArrayList.size() > productShowLimit) { > productPromos = new ArrayList(productShowLimit); > for (i = 0; i < productShowLimit; i++) { > > randomIndex = Math.round(java.lang.Math.random() * > (productArrayList.size() - 1)); > > > > productPromos.add(productArrayList.get((int) randomIndex)); > } > > } else { > productPromos = productArray; > } > > > But I cannot get my head around on how to link this information to the > listPrice... getRelatedOne on ProductPrice retrieves all the prices for a > certain product: > > productPrices = null; > Iterator p = productPromos.iterator(); > while(p.hasNext()){ > GenericValue p = (GenericValue) p.next(); > prices = p.getRelated("ProductPrice"); > System.out.println("Out: "+ prices); > } > > > But i cannot combine that information with the previous resultMap > (productPromos )... Also, I've read on > > http://www.opensourcestrategies.com/ofbiz/ofbiz_entity_cookbook.txt > > that you shouldn't access the product data table directly (which makes > sense), and so I can't help but wonder on whether there are easier/already > existing ways of what I am trying to accomplish... |
In reply to this post by madppiper-2
If you want the current price for the current customer/etc then you should call the calculateProductPrice service for each product. If you want the list price, and query conditions to get it, just look at the code in the ProductSearch class that does sorting and filtering by price. In other words, there are good examples there... I guess you may have become to concerned with getting frustrated to sufficiently open the scope of your search. -David On Dec 4, 2008, at 5:02 AM, madppiper wrote: > > Alright, > > this is driving me insane, and after searching all through the > available > ofbiz screens and beanshell files, I would really appreciate some > help on > this. > > All I want to do is to retrieve a sample of four products (randomly > selected) that contains the description, title, price, listprice, > productId > and brandName, so that I can access the information via ftl later on > and > display 4 productboxes... > > I got the first part together just fine: > > /*Find Products*/ > delegator = request.getAttribute("delegator"); > products = delegator.findAll("Product"); > productShowLimit=4; > > > > > //now slim it down to promoShowLimit > productArrayList = new ArrayList(products); > > productPromos = null; > if (productArrayList.size() > productShowLimit) { > productPromos = new ArrayList(productShowLimit); > for (i = 0; i < productShowLimit; i++) { > > randomIndex = Math.round(java.lang.Math.random() * > (productArrayList.size() - 1)); > > > > productPromos.add(productArrayList.get((int) randomIndex)); > } > > } else { > productPromos = productArray; > } > > > But I cannot get my head around on how to link this information to the > listPrice... getRelatedOne on ProductPrice retrieves all the prices > for a > certain product: > > productPrices = null; > Iterator p = productPromos.iterator(); > while(p.hasNext()){ > GenericValue p = (GenericValue) p.next(); > prices = p.getRelated("ProductPrice"); > System.out.println("Out: "+ prices); > } > > > But i cannot combine that information with the previous resultMap > (productPromos )... Also, I've read on > > http://www.opensourcestrategies.com/ofbiz/ofbiz_entity_cookbook.txt > > that you shouldn't access the product data table directly (which makes > sense), and so I can't help but wonder on whether there are easier/ > already > existing ways of what I am trying to accomplish... > -- > View this message in context: http://www.nabble.com/Cannot-Retrive-price-from-ProductPrice-tp10407489p20832124.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > |
Free forum by Nabble | Edit this page |