Skip to content

Commit

Permalink
catalog: product features: Fixed and improved adding product features…
Browse files Browse the repository at this point in the history
… with type and idCode.

* Product Feature Types dropdown gets populated with the types that got product features with codes (the rest are omitted).
* The codes get automatically populated on selection via ajax.
* Handling errors properly.

https://gitlab.ilscipio.com/scipio-dev/dev/scipioce-dev/issues/829
  • Loading branch information
minifreak committed Feb 8, 2019
1 parent 9aa1f74 commit d02ddbd
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 7 deletions.
6 changes: 6 additions & 0 deletions applications/product/config/ProductErrorUiLabels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,12 @@
<value xml:lang="zh">产品特征类型标识必须只包含字符、下划线和数字。请重新输入</value>
<value xml:lang="zh-TW">產品特色類型識別必須只包含字元、下劃線和數字.請重新輸入</value>
</property>
<property key="ProductFeatureTypeAndIdCodeNotFound">
<value xml:lang="de">Die Kombination zwischen Produkt-Feature-Typ-ID und Code-ID wurde nicht gefunden.</value>
<value xml:lang="en">The combination between Product Feature Type Id and Code Id could not be found.</value>
<value xml:lang="fr">La combinaison entre l'identifiant de type de fonctionnalité du produit et l'identifiant de code est introuvable.</value>
<value xml:lang="it">Non è stato possibile trovare la combinazione tra ID tipo di prodotto e ID codice.</value>
</property>
<property key="ProductFieldEmpty">
<value xml:lang="de">Bitte füllen Sie zunächst das Produktfeld</value>
<value xml:lang="en">Please, fill the product field before</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ code package.
<set field="callingMethodName" value="applyFeatureToProductFromTypeAndCode"/>
<set field="checkAction" value="CREATE"/>
<call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>


<check-errors/>

<!-- find the ProductFeatures by type and id code -->
Expand All @@ -20,6 +22,14 @@ code package.
<field-map field-name="idCode" from-field="parameters.idCode"/>
</entity-and>

<!-- <log message="productFeatureTypeId =======> ${parameters.productFeatureTypeId}" level="always"/>
<log message="productFeatures =======> ${productFeatures}" level="always"/> -->
<if-empty field="productFeatures">
<add-error><fail-property resource="ProductUiLabels" property="ProductFeatureTypeAndIdCodeNotFound"/></add-error>
</if-empty>

<check-errors/>

<iterate list="productFeatures" entry="productFeature">
<set-service-fields service-name="applyFeatureToProduct" map="parameters" to-map="applyFeatureContext"/>
<set field="applyFeatureContext.productFeatureId" from-field="productFeature.productFeatureId"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1231,4 +1231,23 @@ public static String addProductTags (HttpServletRequest request, HttpServletResp
}
return "success";
}

public static String findProductFeatureTypesAndCodes(HttpServletRequest request, HttpServletResponse response) {
Delegator delegator = (Delegator) request.getAttribute("delegator");
String productFeatureTypeId = request.getParameter("productFeatureTypeId");

if (UtilValidate.isNotEmpty(productFeatureTypeId)) {
try {
List<EntityCondition> condition = UtilMisc.newList();
condition.add(EntityCondition.makeCondition("productFeatureTypeId", EntityOperator.EQUALS, productFeatureTypeId));
condition.add(EntityCondition.makeCondition("idCode", EntityOperator.NOT_EQUAL, null));

List<GenericValue> productFeatureCodes = EntityQuery.use(delegator).from("ProductFeature").where(condition).queryList();
request.setAttribute("productFeatureCodes", productFeatureCodes);
} catch (GenericEntityException e) {
Debug.logError(e.getMessage(), module);
}
}
return "success";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
* under the License.
*/

import org.ofbiz.base.util.Debug
import org.ofbiz.base.util.UtilMisc
import org.ofbiz.base.util.UtilValidate
import org.ofbiz.entity.condition.*;
import org.ofbiz.entity.model.DynamicViewEntity
import org.ofbiz.entity.model.ModelKeyMap

context.productFeatureAndAppls = from("ProductFeatureAndAppl").where("productId", productId).orderBy("sequenceNum", "productFeatureApplTypeId", "productFeatureTypeId", "description").queryList();

Expand All @@ -27,4 +32,24 @@ context.productFeatureApplTypes = from("ProductFeatureApplType").orderBy("descri

context.productFeatureGroups = from("ProductFeatureGroup").orderBy("description").queryList();

context.productFeatureTypes = from("ProductFeatureType").orderBy("description").queryList();
// SCIPIO (2019-08-02): Filtering by idCode not null in order to expose only the ones with idCodes and avoid confusion
DynamicViewEntity dve = new DynamicViewEntity();
dve.addMemberEntity("PFT", "ProductFeatureType");
dve.addMemberEntity("PF", "ProductFeature");
//dve.addAliasAll("PFT", null, null);
dve.addAlias("PF", "idCode", "idCode", null, null, false, "count");
dve.addAlias("PFT", "productFeatureTypeId", null, null, true, true, null);
dve.addViewLink("PF", "PFT", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("productFeatureTypeId", "productFeatureTypeId")));

// FIXME: I don't like filtering like this (PF.ID_CODE) but that's the only way I could make it working.
// Looks like we have a bug that includes the function inside the where clause when it should just use the col name.
eli = from(dve).where(EntityCondition.makeCondition("PF.ID_CODE", EntityOperator.NOT_EQUAL, null)).cursorScrollInsensitive().queryIterator();
productFeatureTypes = [];
if (UtilValidate.isNotEmpty(eli)) {
while (productFeatureAndCode = eli.next()) {
productFeatureTypes.add(delegator.findOne("ProductFeatureType", UtilMisc.toMap("productFeatureTypeId", productFeatureAndCode.productFeatureTypeId), true));
// Debug.log("productFeatureAndCode[" + productFeatureAndCode.productFeatureTypeId + "]: " + productFeatureAndCode.idCode);
}
eli.close();
}
context.productFeatureTypes = productFeatureTypes;
7 changes: 7 additions & 0 deletions applications/product/webapp/catalog/WEB-INF/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,13 @@ code package.
<response name="success" type="view" value="EditProductFeatures"/>
<response name="error" type="view" value="EditProductFeatures"/>
</request-map>
<!-- SCIPIO (2019-08-02): Returns the feature codes available for a given ProductFeatureType in json format -->
<request-map uri="FindProductFeatureTypesAndCodes">
<security https="true" auth="true"/>
<event type="java" path="org.ofbiz.product.product.ProductEvents" invoke="findProductFeatureTypesAndCodes"/>
<response name="success" type="request" value="json"/>
<response name="error" type="request" value="json"/>
</request-map>
<request-map uri="createProductFeatureApplAttr">
<security https="true" auth="true"/>
<event type="service" path="" invoke="createProductFeatureApplAttr"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,40 @@ code package.
<form method="post" action="<@pageUrl>ApplyFeatureToProductFromTypeAndCode</@pageUrl>" name="addFeatureByTypeIdCode">
<input type="hidden" name="productId" value="${productId}"/>

<@script>
$(window).load(function() {
$("select[name=productFeatureTypeId]").change(function() {
$.ajax ({
url: '<@pageUrl>FindProductFeatureTypesAndCodes</@pageUrl>',
type: "POST",
async: true,
data: {"productFeatureTypeId" : this.value},
success: function(data) {
if (data.productFeatureCodes) {
$('select[name=idCode]').html('');
for (code in data.productFeatureCodes) {
productFeature = data.productFeatureCodes[code];
$('select[name=idCode]').append('<option value="' + productFeature.idCode + '">' + productFeature.idCode + ' [' + productFeature.description + ']</option>')
}
}
}
});
});
});
</@script>

<@field type="select" label=uiLabelMap.ProductFeatureType size=1 name="productFeatureTypeId">
<#list productFeatureTypes as productFeatureType>
<option value="${(productFeatureType.productFeatureTypeId)!}">${(productFeatureType.get("description",locale))!} </option>
</#list>
<option value="">--</option>
<#list productFeatureTypes as productFeatureType>
<option value="${(productFeatureType.productFeatureTypeId)!}">${(productFeatureType.get("description",locale))!} </option>
</#list>
</@field>

<@field type="input" label=uiLabelMap.CommonIdCode size=10 name="idCode" value="" />


<#-- @field type="input" label=uiLabelMap.CommonIdCode size=10 name="idCode" value="" / -->
<@field type="select" label=uiLabelMap.CommonIdCode name="idCode">
<option value="">--</option>
</@field>

<@field type="select" label=uiLabelMap.ProductFeatureApplicationType size=1 name="productFeatureApplTypeId">
<#list productFeatureApplTypes as productFeatureApplType>
<option value="${(productFeatureApplType.productFeatureApplTypeId)!}"
Expand Down

0 comments on commit d02ddbd

Please sign in to comment.