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

[CoreBundle] surcharge is possible to be more than item value #2192

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
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
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