Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Ecommerce] Discounts shouldn't be negative
  • Loading branch information
brusch committed Jan 17, 2022
1 parent d8377fc commit 7011922
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Expand Up @@ -91,9 +91,17 @@ public function fromJSON($string)
{
$json = json_decode($string);
if ($json->amount) {
if($json->amount < 0) {
throw new \Exception('Only positive numbers and 0 are valid values for absolute discounts');
}

$this->setAmount($json->amount);
}
if ($json->percent) {
if($json->percent < 0) {
throw new \Exception('Only positive numbers and 0 are valid values for % discounts');
}

$this->setPercent($json->percent);
}

Expand Down
Expand Up @@ -75,9 +75,17 @@ public function fromJSON($string)
{
$json = json_decode($string);
if ($json->amount) {
if($json->amount < 0) {
throw new \Exception('Only positive numbers and 0 are valid values for absolute discounts');
}

$this->setAmount($json->amount);
}
if ($json->percent) {
if($json->percent < 0) {
throw new \Exception('Only positive numbers and 0 are valid values for % discounts');
}

$this->setPercent($json->percent);
}

Expand Down
Expand Up @@ -1408,13 +1408,16 @@ pimcore.bundle.EcommerceFramework.pricing.actions = {
fieldLabel: t("bundle_ecommerce_pricing_config_action_cart_discount_amount"),
name: "amount",
width: 200,
value: data.amount
value: data.amount,
minValue: 0
}, {
xtype: "numberfield",
fieldLabel: t("bundle_ecommerce_pricing_config_action_cart_discount_percent"),
name: "percent",
width: 200,
value: data.percent
value: data.percent,
maxValue: 100,
minValue: 0
}
]
});
Expand Down Expand Up @@ -1460,13 +1463,16 @@ pimcore.bundle.EcommerceFramework.pricing.actions = {
fieldLabel: t("bundle_ecommerce_pricing_config_action_product_discount_amount"),
name: "amount",
width: 200,
value: data.amount
value: data.amount,
minValue: 0
}, {
xtype: "numberfield",
fieldLabel: t("bundle_ecommerce_pricing_config_action_product_discount_percent"),
name: "percent",
width: 200,
value: data.percent
value: data.percent,
maxValue: 100,
minValue: 0
}
]
});
Expand Down

0 comments on commit 7011922

Please sign in to comment.