Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Add mandatory check on pricing rule conditions #123

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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