Skip to content

Commit

Permalink
Merge pull request #2192 from dpfaffenbauer/issues/2180
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer authored Jan 30, 2023
2 parents 657e157 + 6188171 commit 19f2100
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion features/domain/cart/rules/surcharge_amount_action.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@domain @cart
Feature: Adding a new cart rule
In order to give the customer discounts
In order to give the customer surcharge
based on the cart, we add a new rule

Background:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@domain @cart
Feature: Adding a new cart rule
In order to give the customer surcharge
based on the cart, we add a new rule
the surcharge is allowed to be more than the items total

Background:
Given the site operates on a store in "Austria"
And the site has a currency "Euro" with iso "EUR"
And I am in country "Austria"
And the site has a tax rate "AT" with "20%" rate
And the site has a tax rule group "AT"
And the tax rule group has a tax rule for country "Austria" with tax rate "AT"
And the site has a product "Shoe" priced at 10000
And the product has the tax rule group "AT"
And I add the product "Shoe" to my cart

Scenario: Add a new surcharge rule with 500 euro for all products
Given adding a cart price rule named "surcharge"
And the cart rule is active
And the cart rule is a voucher rule with code "asdf"
And the cart rule has a action surcharge with 500 in currency "EUR" off
And I apply the voucher code "asdf" to my cart
Then the cart discount should be "60000" including tax
Then the cart discount should be "50000" excluding tax
Then the cart total tax should be "12000"
Then the cart item taxes should be "12000"
Then the cart total should be "60000" excluding tax
Then the cart total should be "72000" including tax
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
{% if discountPrice > 0 %}
<span class="price-old">{{ currency.convertAndFormat(retailPrice) }}</span>
{% endif %}
{% if discount > 0 %}
{% if discount < 0 %}
<span class="price-discount">(-{{ currency.convertAndFormat(discount) }})</span>
{% endif %}
{% endif %}
</td>
<td class="text-right cart-item-total-price" {{ coreshop_test_html_attribute('cart-item-total-price', item.name) }}>
{% if item.discount != 0 %}
<s>({{ currency.convertAndFormat(item.discount) }})</s>
{% if item.discount < 0 %}
<span>({{ currency.convertAndFormat(item.discount) }})</span>
{% endif %}
{{ currency.convertAndFormat(item.total) }}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<td class="text-center"></td>
<td class="text-right" colspan="2">
{% if priceRule.discount != 0 %}
{{ currency.convertAndFormat(priceRule.discount(true)) }}
{{ currency.convertAndFormat(priceRule.discount(true)) }} ({{ currency.convertAndFormat(priceRule.discount(false)) }})
{% endif %}
</td>
<td colspan="1" class="text-left cart-sub-total">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function applySurcharge(OrderInterface $cart, PriceRuleItemInterface $car
protected function apply(OrderInterface $cart, PriceRuleItemInterface $cartPriceRuleItem, int $discount, $withTax = false, $positive = false): void
{
$context = $this->cartContextResolver->resolveCartContext($cart);

$totalAmount = [];
$totalDiscountPossible = 0;

Expand All @@ -64,7 +63,10 @@ protected function apply(OrderInterface $cart, PriceRuleItemInterface $cartPrice
$totalDiscountPossible += $item->getTotal($withTax);
}

$discount = min($discount, $totalDiscountPossible);
//Don't apply less than the cart is worth
if (!$positive) {
$discount = min($discount, $totalDiscountPossible);
}

if (0 === $discount) {
return;
Expand Down

0 comments on commit 19f2100

Please sign in to comment.