You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2021/09/01 07:56:29 UTC
[ofbiz-framework] branch trunk updated: Improved: Propage product
features from a marketing package (OFBIZ-12077)
This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new 3b593f8 Improved: Propage product features from a marketing package (OFBIZ-12077)
3b593f8 is described below
commit 3b593f8eda4497708e4c88c70819f4004805e1f2
Author: Nicolas Malin <ni...@nereide.fr>
AuthorDate: Wed Sep 1 09:54:43 2021 +0200
Improved: Propage product features from a marketing package (OFBIZ-12077)
When you create a product as a marketing package, you attempt when you ship this product to have the same constraint as you ship each product that compose it separately.
Marketing Package | Composed product | Product Feature
GIFT_PACKAGE | |
1 | GIZMO_HEAVY | (WEIGHT) HEAVY_SIZE
2 | GIZMO_TINY |
On this example if I ordered a GIFT_PACKAGE, during the order process, currently you never see that you ordered a product with a feature HEAVY_SIZE, feature that can have some consequence for select a shipping method.
So when we need to analyze the features linked to a product, if the product is a marketing package, we propage the search to all products that compose it
---
.../apache/ofbiz/order/order/OrderReadHelper.java | 8 ++----
.../ofbiz/order/shoppingcart/ShoppingCartItem.java | 12 +--------
.../ofbiz/product/product/ProductWorker.java | 31 ++++++++++++++++++++++
3 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java
index 7f2c885..8549ec0 100644
--- a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java
+++ b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java
@@ -1016,12 +1016,8 @@ public class OrderReadHelper {
List<GenericValue> featureAppls = null;
if (item.get("productId") != null) {
try {
- featureAppls = item.getDelegator().findByAnd("ProductFeatureAppl",
- UtilMisc.toMap("productId", item.getString("productId")), null, true);
- List<EntityExpr> filterExprs = UtilMisc.toList(EntityCondition.makeCondition("productFeatureApplTypeId",
- EntityOperator.EQUALS, "STANDARD_FEATURE"));
- filterExprs.add(EntityCondition.makeCondition("productFeatureApplTypeId", EntityOperator.EQUALS, "REQUIRED_FEATURE"));
- featureAppls = EntityUtil.filterByOr(featureAppls, filterExprs);
+ featureAppls = ProductWorker.getProductFeaturesApplIncludeMarketingPackage(
+ item.getRelatedOne("Product", true));
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get ProductFeatureAppl for item : " + item, MODULE);
}
diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
index adf029b..3ba990b 100644
--- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
+++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
@@ -2695,17 +2695,7 @@ public class ShoppingCartItem implements java.io.Serializable {
Map<String, BigDecimal> featureMap = new HashMap<>();
GenericValue product = this.getProduct();
if (product != null) {
- List<GenericValue> featureAppls = null;
- try {
- featureAppls = product.getRelated("ProductFeatureAppl", null, null, false);
- List<EntityExpr> filterExprs = UtilMisc.toList(EntityCondition.makeCondition("productFeatureApplTypeId",
- EntityOperator.EQUALS, "STANDARD_FEATURE"));
- filterExprs.add(EntityCondition.makeCondition("productFeatureApplTypeId", EntityOperator.EQUALS, "REQUIRED_FEATURE"));
- filterExprs.add(EntityCondition.makeCondition("productFeatureApplTypeId", EntityOperator.EQUALS, "DISTINGUISHING_FEAT"));
- featureAppls = EntityUtil.filterByOr(featureAppls, filterExprs);
- } catch (GenericEntityException e) {
- Debug.logError(e, "Unable to get features from product : " + product.get("productId"), MODULE);
- }
+ List<GenericValue> featureAppls = ProductWorker.getProductFeaturesApplIncludeMarketingPackage(product);
if (featureAppls != null) {
for (GenericValue appl : featureAppls) {
BigDecimal lastQuantity = featureMap.get(appl.getString("productFeatureId"));
diff --git a/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java b/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java
index 359a78c..b10da4a 100644
--- a/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java
+++ b/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java
@@ -41,6 +41,7 @@ import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.condition.EntityCondition;
+import org.apache.ofbiz.entity.condition.EntityOperator;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.entity.util.EntityTypeUtil;
import org.apache.ofbiz.entity.util.EntityUtil;
@@ -416,6 +417,36 @@ public final class ProductWorker {
return features;
}
+ public static List<GenericValue> getProductFeaturesApplIncludeMarketingPackage(GenericValue product) {
+ Delegator delegator = product.getDelegator();
+ if (product != null) {
+ try {
+ List<String> productIds = UtilMisc.toList(product.getString("productId"));
+
+ // For marketing package, resolve each features contains in the package
+ if (EntityTypeUtil.hasParentType(delegator, "ProductType",
+ "productTypeId", product.getString("productTypeId"), "parentTypeId", "MARKETING_PKG_PICK")) {
+ productIds.addAll(EntityQuery.use(delegator).from("ProductAndAssocTo")
+ .where("productId", product.get("productId"),
+ "productAssocTypeId", "PRODUCT_COMPONENT")
+ .filterByDate()
+ .cache()
+ .getFieldList("productIdTo"));
+ }
+ return EntityQuery.use(delegator).from("ProductFeatureAppl")
+ .where(EntityCondition.makeCondition("productId", EntityOperator.IN, productIds),
+ EntityCondition.makeCondition("productFeatureApplTypeId", EntityOperator.IN,
+ UtilMisc.toList("REQUIRED_FEATURE", "DISTINGUISHING_FEAT", "STANDARD_FEATURE")))
+ .filterByDate()
+ .cache()
+ .queryList();
+ } catch (GenericEntityException e) {
+ Debug.logError(e, "Unable to get features from product : " + product.get("productId"), MODULE);
+ }
+ }
+ return null;
+ }
+
public static String getProductVirtualVariantMethod(Delegator delegator, String productId) {
GenericValue product = null;
try {