Author: jleroux
Date: Thu Nov 8 15:02:13 2018 New Revision: 1846156 URL: http://svn.apache.org/viewvc?rev=1846156&view=rev Log: Fixed: CatalogServices #createProductCategoryAttribute doesn't check for existing attributes (OFBIZ-10327) This method just crashes, if there is an attribute which has the same name as the one the user is trying to create. There should be a check for existing attributes and a clean return, no exception throwing. Thanks: Dennis Balkir for report and Benjamin Jugl for patch Modified: ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy Modified: ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml?rev=1846156&r1=1846155&r2=1846156&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml Thu Nov 8 15:02:13 2018 @@ -14691,6 +14691,10 @@ <value xml:lang="zh">没ææ¾å°åç±»ââåç±»æ è¯</value> <value xml:lang="zh-TW">æ²ææ¾å°åé¡èå¥</value> </property> + <property key="ProductCategoryAttrAlreadyExists"> + <value xml:lang="de">Eine Attribut mit diesem Namen existiert bereits für die Produktgruppe mit dieser ID.</value> + <value xml:lang="en">There already is an attribute with this name for a group with this ID.</value> + </property> <property key="ProductCategoryNoVariants"> <value xml:lang="de">Keine Produkte mit den gewünschten Eigenschaften gefunden.</value> <value xml:lang="en">No products which fit your requirements were found.</value> Modified: ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy?rev=1846156&r1=1846155&r2=1846156&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy Thu Nov 8 15:02:13 2018 @@ -28,6 +28,7 @@ import org.apache.ofbiz.base.util.UtilVa 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.condition.EntityConditionBuilder import org.apache.ofbiz.entity.util.EntityUtil import org.apache.ofbiz.service.ModelService import org.apache.ofbiz.service.ServiceUtil @@ -595,12 +596,24 @@ def duplicateProductCategory() { * Create an attribute for a product category */ def createProductCategoryAttribute() { + def resourceDescription = parameters.resourceDescription ?: "createProductCategoryAttribute" if (!(security.hasEntityPermission("CATALOG", "_CREATE", parameters.userLogin))) { return error(UtilProperties.getMessage("ProductUiLabels", "ProductCatalogCreatePermissionError", [resourceDescription: resourceDescription], parameters.locale)) } - + + // check if the new attribute-name is unique to the product-category-id + exprBldr = new EntityConditionBuilder() + condition = exprBldr.AND() { + EQUALS(productCategoryId: parameters.productCategoryId) + EQUALS(attrName: parameters.attrName) + } + List existingData = from('ProductCategoryAttribute').where(condition).queryList() + if (existingData) { + return error(UtilProperties.getMessage("ProductUiLabels", "ProductCategoryAttrAlreadyExists", + [resourceDescription: resourceDescription], parameters.locale)) + } GenericValue newEntity = makeValue("ProductCategoryAttribute", parameters) newEntity.create() return success() |
Free forum by Nabble | Edit this page |