Skip to content

Commit

Permalink
set correct remaining available discount amount when applying fixed p…
Browse files Browse the repository at this point in the history
…rice cart rules to bundle products
  • Loading branch information
sky-hub committed Nov 26, 2020
1 parent 26acabe commit d56db5b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ public function calculate($rule, $item, $qty)
$address,
$baseRuleTotals
) : $baseRuleTotals;
$availableDiscountAmount = $this->cartFixedDiscountHelper
$maximumItemDiscount = $this->cartFixedDiscountHelper
->getDiscountAmount(
$ruleDiscount,
$qty,
$baseItemPrice,
$baseRuleTotals,
$discountType
);
$quoteAmount = $this->priceCurrency->convert($availableDiscountAmount, $store);
$baseDiscountAmount = min($baseItemPrice * $qty, $availableDiscountAmount);
$quoteAmount = $this->priceCurrency->convert($maximumItemDiscount, $store);
$baseDiscountAmount = min($baseItemPrice * $qty, $maximumItemDiscount);
$this->deltaPriceRound->reset($discountType);
} else {
$baseRuleTotals = $shippingMethod ?
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@
<entity name="SalesRuleNoCouponWithFixedDiscount" extends="ApiCartRule">
<data key="simple_action">by_fixed</data>
</entity>
<entity name="SalesRuleNoCouponWithFixedDiscountWholeCart" extends="ApiCartRule">
<data key="simple_action">cart_fixed</data>
</entity>
<entity name="ActiveSalesRuleWithPercentPriceDiscountCoupon">
<data key="name" unique="suffix">Cart Price Rule with Specific Coupon</data>
<data key="description">Description for Cart Price Rule</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontAssertFixedCartDiscountAmountForBundleProductTest">
<annotations>
<features value="SalesRule"/>
<stories value="Fixed Amount Cart Price Rule"/>
<title value="Checking Fixed Amount Cart Price Rule is correctly applied to bundle products"/>
<description value="Checking Fixed Amount Cart Price Rule is correctly applied to bundle products"/>
<severity value="AVERAGE"/>
<group value="SalesRule"/>
</annotations>
<before>
<createData entity="SalesRuleNoCouponWithFixedDiscountWholeCart" stepKey="createSalesRule"/>
<actionGroup ref="AdminCreateApiDynamicBundleProductAllOptionTypesActionGroup" stepKey="createBundleProduct"/>
</before>
<after>
<deleteData createDataKey="createSalesRule" stepKey="deleteSalesRule"/>
<deleteData createDataKey="createBundleProductCreateBundleProduct" stepKey="deleteBundleProduct"/>
<deleteData createDataKey="simpleProduct1CreateBundleProduct" stepKey="deleteSimpleProduct1"/>
</after>
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
<argument name="productUrl" value="$$createBundleProductCreateBundleProduct.custom_attributes[url_key]$$"/>
</actionGroup>
<click selector="{{StorefrontBundledSection.addToCart}}" stepKey="clickCustomize"/>
<selectOption selector="{{StorefrontBundledSection.dropDownOptionOneProducts('Drop-down Option')}}" userInput="$$simpleProduct2CreateBundleProduct.sku$$ +$$$simpleProduct2CreateBundleProduct.price$$.00" stepKey="selectOption0Product1"/>
<seeOptionIsSelected selector="{{StorefrontBundledSection.dropDownOptionOneProducts('Drop-down Option')}}" userInput="$$simpleProduct2CreateBundleProduct.sku$$ +$$$simpleProduct2CreateBundleProduct.price$$.00" stepKey="checkOption0Product1"/>
<checkOption selector="{{StorefrontBundledSection.radioButtonOptionTwoProducts('Radio Buttons Option', '1')}}" stepKey="selectOption1Product0"/>
<seeCheckboxIsChecked selector="{{StorefrontBundledSection.radioButtonOptionTwoProducts('Radio Buttons Option', '1')}}" stepKey="checkOption1Product0"/>
<checkOption selector="{{StorefrontBundledSection.checkboxOptionThreeProducts('Checkbox Option', '1')}}" stepKey="selectOption2Product0"/>
<seeCheckboxIsChecked selector="{{StorefrontBundledSection.checkboxOptionThreeProducts('Checkbox Option', '1')}}" stepKey="checkOption2Product0"/>
<checkOption selector="{{StorefrontBundledSection.checkboxOptionThreeProducts('Checkbox Option', '2')}}" stepKey="selectOption2Product1"/>
<seeCheckboxIsChecked selector="{{StorefrontBundledSection.checkboxOptionThreeProducts('Checkbox Option', '1')}}" stepKey="checkOption2Product1"/>
<actionGroup ref="StorefrontEnterProductQuantityAndAddToTheCartActionGroup" stepKey="enterProductQuantityAndAddToTheCart">
<argument name="quantity" value="1"/>
</actionGroup>
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openShoppingCartPage"/>
<actionGroup ref="StorefrontCheckCartActionGroup" stepKey="cartAssert" after="openShoppingCartPage">
<argument name="subtotal" value="60.00"/>
<argument name="shipping" value="5.00"/>
<argument name="shippingMethod" value="Flat Rate - Fixed"/>
<argument name="total" value="15.00"/>
</actionGroup>
</test>
</tests>

0 comments on commit d56db5b

Please sign in to comment.