[OFBiz] SVN: r7503 - in trunk/applications: order/src/org/ofbiz/order/shoppingcart product/src/org/ofbiz/product/category
jonesde@svn.ofbiz.org
jonesde at svn.ofbiz.org
Wed May 3 09:56:29 CDT 2006
Author: jonesde
Date: 2006-05-03 09:56:05 -0500 (Wed, 03 May 2006)
New Revision: 7503
Modified:
trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java
Log:
Small preformance improvements to use pk cache in is product in category method; added method to ShoppingCart to get all cart items for products in a specific category
Modified: trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
===================================================================
--- trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java 2006-05-03 13:23:56 UTC (rev 7502)
+++ trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java 2006-05-03 14:56:05 UTC (rev 7503)
@@ -60,6 +60,7 @@
import org.ofbiz.order.shoppingcart.product.ProductPromoWorker;
import org.ofbiz.order.shoppingcart.shipping.ShippingEstimateWrapper;
import org.ofbiz.order.shoppinglist.ShoppingListEvents;
+import org.ofbiz.product.category.CategoryWorker;
import org.ofbiz.product.config.ProductConfigWrapper;
import org.ofbiz.product.store.ProductStoreWorker;
import org.ofbiz.service.LocalDispatcher;
@@ -107,7 +108,7 @@
private boolean orderTermSet = false;
private List orderTerms = new LinkedList();
- private List cartLines = new LinkedList();
+ private List cartLines = FastList.newInstance();
private Map itemGroupByNumberMap = FastMap.newInstance();
protected long nextGroupNumber = 1;
private List paymentInfo = new LinkedList();
@@ -543,13 +544,13 @@
/** Get all ShoppingCartItems from the cart object with the given productId. */
public List findAllCartItems(String productId) {
- if (productId == null) return new LinkedList(this.cartLines);
- List itemsToReturn = new LinkedList();
+ if (productId == null) return this.items();
+ List itemsToReturn = FastList.newInstance();
// Check for existing cart item.
- for (int i = 0; i < this.cartLines.size(); i++) {
- ShoppingCartItem cartItem = (ShoppingCartItem) cartLines.get(i);
-
+ Iterator cartItemIter = this.cartLines.iterator();
+ while (cartItemIter.hasNext()) {
+ ShoppingCartItem cartItem = (ShoppingCartItem) cartItemIter.next();
if (productId.equals(cartItem.getProductId())) {
itemsToReturn.add(cartItem);
}
@@ -557,6 +558,27 @@
return itemsToReturn;
}
+ /** Get all ShoppingCartItems from the cart object with the given productCategoryId */
+ public List findAllCartItemsInCategory(String productCategoryId) {
+ if (productCategoryId == null) return this.items();
+
+ GenericDelegator delegator = this.getDelegator();
+ List itemsToReturn = FastList.newInstance();
+ try {
+ // Check for existing cart item.
+ Iterator cartItemIter = this.cartLines.iterator();
+ while (cartItemIter.hasNext()) {
+ ShoppingCartItem cartItem = (ShoppingCartItem) cartItemIter.next();
+ if (CategoryWorker.isProductInCategory(delegator, cartItem.getProductId(), productCategoryId)) {
+ itemsToReturn.add(cartItem);
+ }
+ }
+ } catch (GenericEntityException e) {
+ Debug.logError(e, "Error getting cart items that are in a category: " + e.toString(), module);
+ }
+ return itemsToReturn;
+ }
+
/** Remove quantity 0 ShoppingCartItems from the cart object. */
public void removeEmptyCartItems() {
// Check for existing cart item.
@@ -652,7 +674,9 @@
/** Returns a Collection of items in the cart object. */
public List items() {
- return cartLines;
+ List result = FastList.newInstance();
+ result.addAll(cartLines);
+ return result;
}
/** Returns an iterator of cart items. */
Modified: trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java
===================================================================
--- trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java 2006-05-03 13:23:56 UTC (rev 7502)
+++ trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java 2006-05-03 14:56:05 UTC (rev 7503)
@@ -391,7 +391,7 @@
UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId)), true);
if (productCategoryMembers == null || productCategoryMembers.size() == 0) {
//before giving up see if this is a variant product, and if so look up the virtual product and check it...
- GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));
+ GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
List productAssocs = ProductWorker.getVariantVirtualAssocs(product);
//this does take into account that a product could be a variant of multiple products, but this shouldn't ever really happen...
if (productAssocs != null && productAssocs.size() > 0) {
More information about the Svn
mailing list