Skip to content

Commit

Permalink
[Bug]: Add mandatory check on pricing rule conditions (#123)
Browse files Browse the repository at this point in the history
* add mandatory check on pricing rule conditions

* add the name of the field that is mandatory in the alert

* since translation key is plural, making it an array and join with comma, actually this field is mandatory

* since translation key is plural, making it an array and join with comma, actually these fields are mandatory
  • Loading branch information
kingjia90 authored Sep 12, 2023
1 parent fc27237 commit 9da9d4a
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/Resources/public/js/pricing/config/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pimcore.bundle.EcommerceFramework.pricing.config.item = Class.create({
*/
save: function () {
var saveData = {};

var missingMandatoryFields = [];
// general settings
saveData["settings"] = this.settingsForm.getForm().getFieldValues();

Expand All @@ -362,27 +362,37 @@ pimcore.bundle.EcommerceFramework.pricing.config.item = Class.create({
var item = conditions[i].items.getAt(c);

try {
let value = null;
// workaround for pimcore.object.tags.objects
if(item.reference)
{
condition[ item.reference.getName() ] = item.reference.getValue();
value = item.reference.getValue();
condition[ item.reference.getName() ] = value;
}
else if(item.form)
{
condition[ item.name ] = item.getForm().getFieldValues();
value = item.form.getFieldValues();
condition[ item.name ] = value;
}
else if(item.xtype === 'datefield')
{
condition[ item.name ] = item.getSubmitValue();
value = item.getSubmitValue();
condition[ item.name ] = value;
}
else
{
condition[ item.getName() ] = item.getValue();
value = item.getValue();
condition[ item.getName() ] = value;

}

if (item.mandatory && (!value)){
missingMandatoryFields.push(item.fieldLabel);
}
} catch (e){}

}

condition['type'] = conditions[i].type;

// get the operator (AND, OR, AND_NOT)
Expand All @@ -404,6 +414,13 @@ pimcore.bundle.EcommerceFramework.pricing.config.item = Class.create({

conditionsData.push(condition);
}

if (missingMandatoryFields.length > 0){
Ext.MessageBox.alert(t("error"), t("mandatory_field_empty") + ': ' + missingMandatoryFields.join(', '));
return false;
}


saveData["conditions"] = conditionsData;

// get defined actions
Expand Down Expand Up @@ -892,6 +909,7 @@ pimcore.bundle.EcommerceFramework.pricing.conditions = {
xtype: "numberfield",
fieldLabel: t("bundle_ecommerce_pricing_config_condition_cart_amount"),
name: "limit",
mandatory: true,
width: 300,
value: data.limit
}]
Expand Down Expand Up @@ -934,6 +952,7 @@ pimcore.bundle.EcommerceFramework.pricing.conditions = {
fieldLabel: t("bundle_ecommerce_pricing_config_condition_sold_count"),
name: "count",
width: 300,
mandatory: true,
value: data.count
}],
});
Expand Down Expand Up @@ -975,6 +994,7 @@ pimcore.bundle.EcommerceFramework.pricing.conditions = {
fieldLabel: t("amount"),
name: "amount",
width: 300,
mandatory: true,
value: data.amount
}],
});
Expand Down Expand Up @@ -1012,6 +1032,7 @@ pimcore.bundle.EcommerceFramework.pricing.conditions = {
fieldLabel: 'IP',
name: "ip",
width: 300,
mandatory: true,
value: data.ip
}]
});
Expand Down

0 comments on commit 9da9d4a

Please sign in to comment.