This is an automated email from the ASF dual-hosted git repository.

mridulpathak 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 2cc834f9e6 Fixed: Regressions in CategoryServicesScript.groovy 
introduced by the mini-lang conversion (OFBIZ-13659)
2cc834f9e6 is described below

commit 2cc834f9e6a2bc32365b6bb68f2320d62f86a619
Author: Mridul Pathak <[email protected]>
AuthorDate: Thu Oct 8 17:19:37 2026 +0530

    Fixed: Regressions in CategoryServicesScript.groovy introduced by the 
mini-lang conversion (OFBIZ-13659)
    
    The Groovy conversion of CategoryServices.xml changed the behaviour of 
several services. Restore the mini-lang behaviour:
    
    - copyCategoryProductMembers: set productCategoryId of the copied members 
from productCategoryIdTo (the assignment was reversed, so nothing was copied 
and productCategoryIdTo was overwritten), and apply validDate when filtering 
members and rollups
    - copyCategoryEntities: apply validDate when filtering the entities to copy
    - createProductInCategory: iterate productFeatureIdByType with Map.Entry 
(the Map-typed loop variable threw a GroovyCastException), create the default 
price and average cost also when they are zero, and look the product up by the 
created productId when marking it virtual
    - createProductCategoryLink: keep the fields supplied by the caller 
(linkSeqId, fromDate and the non-PK fields) and only generate linkSeqId when 
none is given
    - addProductCategoryToCategories: check the permission against 
parameters.categories instead of the literal string
    - checkCategoryPermissionWithViewPurchaseAllow: use the existing 
CommonCallingMethodPermissionError label with named arguments for both 
permissions
---
 .../product/category/CategoryServicesScript.groovy | 29 +++++++++++-----------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git 
a/applications/product/src/main/groovy/org/apache/ofbiz/product/product/category/CategoryServicesScript.groovy
 
b/applications/product/src/main/groovy/org/apache/ofbiz/product/product/category/CategoryServicesScript.groovy
index 63275044ab..2c40f0ec5c 100644
--- 
a/applications/product/src/main/groovy/org/apache/ofbiz/product/product/category/CategoryServicesScript.groovy
+++ 
b/applications/product/src/main/groovy/org/apache/ofbiz/product/product/category/CategoryServicesScript.groovy
@@ -226,7 +226,7 @@ Map addProductCategoryToCategories() {
         }
     } else {
         // note the the user must be associated with the parent category with 
the role limited permission
-        Map res = 
checkCategoryRelatedPermission('addProductCategoryToCategories', 'CREATE', 
'parameters.categories', null)
+        Map res = 
checkCategoryRelatedPermission('addProductCategoryToCategories', 'CREATE', 
parameters.categories, null)
         if (!ServiceUtil.isSuccess(res)) {
             return res
         }
@@ -287,7 +287,7 @@ Map copyCategoryProductMembers() {
 
     EntityQuery query = 
from('ProductCategoryMember').where('productCategoryId', 
parameters.productCategoryId)
     if (parameters.validDate) {
-        query.filterByDate()
+        query.filterByDate(parameters.validDate)
     }
     List productCategoryMembers = query.queryList()
 
@@ -295,7 +295,7 @@ Map copyCategoryProductMembers() {
     List pcmsToStore = []
     for (GenericValue productCategoryMember : productCategoryMembers) {
         GenericValue newProductCategoryMember = productCategoryMember.clone()
-        parameters.productCategoryIdTo = 
newProductCategoryMember.productCategoryId
+        newProductCategoryMember.productCategoryId = 
parameters.productCategoryIdTo
         pcmsToStore.add(newProductCategoryMember)
     }
     delegator.storeAll(pcmsToStore)
@@ -306,7 +306,7 @@ Map copyCategoryProductMembers() {
         query = from('ProductCategoryRollup').where(lookupChildrenMap)
 
         if (parameters.validDate) {
-            query.filterByDate()
+            query.filterByDate(parameters.validDate)
         }
         List productCategoryRollups = query.queryList()
 
@@ -344,7 +344,7 @@ Map duplicateCategoryEntities() {
 void copyCategoryEntities(String entityName, String productCategoryId, String 
productCategoryIdTo, Timestamp validDate) {
     EntityQuery query = from(entityName).where('productCategoryId', 
productCategoryId)
     if (validDate) {
-        query.filterByDate()
+        query.filterByDate(validDate)
     }
     List categoryEntities = query.queryList()
 
@@ -443,7 +443,7 @@ Map createProductInCategory() {
     run service: 'addProductToCategory', with: 
callCreateProductCategoryMemberMap
 
     // create defaultPrice and averageCost ProductPrice
-    if (parameters.defaultPrice) {
+    if (parameters.defaultPrice != null) {
         Map createDefaultPriceMap = [
             productId: productId,
             currencyUomId: parameters.currencyUomId,
@@ -455,7 +455,7 @@ Map createProductInCategory() {
         run service: 'createProductPrice', with: createDefaultPriceMap
     }
 
-    if (parameters.averageCost) {
+    if (parameters.averageCost != null) {
         Map createAverageCostMap = [
             productId: productId,
             currencyUomId: parameters.currencyUomId,
@@ -469,7 +469,7 @@ Map createProductInCategory() {
 
     // create ProductFeatureAppl(s)
     String hasSelectableFeatures = 'N'
-    for (Map entry : parameters.productFeatureIdByType.entrySet()) {
+    for (Map.Entry entry : parameters.productFeatureIdByType.entrySet()) {
         String productFeatureTypeId = entry.getKey()
         String productFeatureId = entry.getValue()
         logInfo("Applying feature [${productFeatureId}] of type 
[${productFeatureTypeId}] to product [${productId}]")
@@ -486,7 +486,7 @@ Map createProductInCategory() {
 
     // set isVirtual based on hasSelectableFeatures
     if (hasSelectableFeatures == 'Y') {
-        update('Product').where(parameters).set([isVirtual: 'Y'])
+        update('Product').where([productId: productId]).set([isVirtual: 'Y'])
     }
     return result
 }
@@ -617,11 +617,10 @@ Map deleteProductCategoryAttribute() {
  * create a ProductCategoryLink
  */
 Map createProductCategoryLink() {
-    GenericValue newEntity = makeValue('ProductCategoryLink')
-    newEntity.productCategoryId = parameters.productCategoryId
+    GenericValue newEntity = makeValue('ProductCategoryLink', parameters)
 
     // don't set the fromDate yet; let's get the seq ID first
-    if (!parameters.linkSeqId) {
+    if (!newEntity.linkSeqId) {
         delegator.setNextSubSeqId(newEntity, 'linkSeqId', 5, 1)
     }
 
@@ -726,14 +725,16 @@ Map checkCategoryPermissionWithViewPurchaseAllow() {
             && !security.hasEntityPermission('CATALOG_VIEW', '_ALLOW', 
parameters.userLogin)) {
             logVerbose('Permission check failed, user does not have 
permission')
             failMessage = UtilProperties.getMessage('CommonUiLabels',
-                    'CommmonCallingMethodPermissionError', [callingMethodName, 
'CATALOG_VIEW_ALLOW'], parameters.locale)
+                    'CommonCallingMethodPermissionError',
+                    [callingMethodName: callingMethodName, permission: 
'CATALOG_VIEW_ALLOW'], parameters.locale)
             hasPermission = false
         }
         if (prodCatalog.purchaseAllowPermReqd == 'Y'
             && !security.hasEntityPermission('CATALOG_PURCHASE', '_ALLOW', 
parameters.userLogin)) {
             logVerbose('Permission check failed, user does not have 
permission')
             failMessage = UtilProperties.getMessage('CommonUiLabels',
-                    'CommonCallingMethodPermissionError', [callingMethodName, 
'CATALOG_PURCHASE_ALLOW'], parameters.locale)
+                    'CommonCallingMethodPermissionError',
+                    [callingMethodName: callingMethodName, permission: 
'CATALOG_PURCHASE_ALLOW'], parameters.locale)
             hasPermission = false
         }
     }

Reply via email to