Skip to content

Commit 8c227d5

Browse files
authored
Merge pull request #2852 from magento-honey-badgers/MAGETWO-90971
[honey] MAGETWO-90971: Error is returned when customer checks out with multiple addresses
2 parents 2b85232 + f333f36 commit 8c227d5

File tree

6 files changed

+210
-97
lines changed

6 files changed

+210
-97
lines changed

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutShippingMethodsSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
<element name="shippingMethodRow" type="text" selector=".form.methods-shipping table tbody tr"/>
1515
<element name="checkShippingMethodByName" type="radio" selector="//div[@id='checkout-shipping-method-load']//td[contains(., '{{var1}}')]/..//input" parameterized="true"/>
1616
<element name="shippingMethodRowByName" type="text" selector="//div[@id='checkout-shipping-method-load']//td[contains(., '{{var1}}')]/.." parameterized="true"/>
17+
<element name="shipHereButton" type="button" selector="//button[contains(@class, 'action-select-shipping-item')]/parent::div/following-sibling::div/button[contains(@class, 'action-select-shipping-item')]"/>
18+
<element name="shippingMethodLoader" type="button" selector="//div[contains(@class, 'checkout-shipping-method')]/following-sibling::div[contains(@class, 'loading-mask')]"/>
1719
</section>
1820
</sections>

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerCheckoutTest.xml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,109 @@
8282
<click stepKey="s102" selector="{{AdminEditCustomerInformationSection.orders}}"/>
8383
<see stepKey="s103" selector="{{AdminEditCustomerOrdersSection.orderGrid}}" userInput="$$simpleuscustomer.firstname$$ $$simpleuscustomer.lastname$$" />
8484
</test>
85+
<test name="StorefrontCustomerCheckoutTestWithMultipleAddressesAndTaxRates">
86+
<annotations>
87+
<title value="Customer Checkout with multiple addresses and tax rates"/>
88+
<description value="Should be able to place an order as a customer with multiple addresses and tax rates."/>
89+
<testCaseId value="MAGETWO-93109"/>
90+
</annotations>
91+
<before>
92+
<createData entity="SimpleSubCategory" stepKey="simplecategory"/>
93+
<createData entity="SimpleProduct" stepKey="simpleproduct1">
94+
<requiredEntity createDataKey="simplecategory"/>
95+
</createData>
96+
<createData entity="Simple_US_Customer_Multiple_Addresses" stepKey="multiple_address_customer"/>
97+
98+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
99+
100+
<!-- Go to tax rule page -->
101+
<amOnPage url="{{AdminTaxRuleGridPage.url}}" stepKey="goToTaxRulePage"/>
102+
<waitForPageLoad stepKey="waitForTaxRatePage"/>
103+
<click stepKey="addNewTaxRate" selector="{{AdminGridMainControls.add}}"/>
104+
<fillField stepKey="fillRuleName" selector="{{AdminTaxRulesSection.ruleName}}" userInput="SampleRule"/>
105+
106+
<!-- Add NY and CA tax rules -->
107+
<actionGroup ref="addNewTaxRateNoZip" stepKey="addNYTaxRate">
108+
<argument name="taxCode" value="SimpleTaxNY"/>
109+
</actionGroup>
110+
111+
<actionGroup ref="addNewTaxRateNoZip" stepKey="addCATaxRate">
112+
<argument name="taxCode" value="SimpleTaxCA"/>
113+
</actionGroup>
114+
115+
<click stepKey="clickSave" selector="{{AdminStoresMainActionsSection.saveButton}}"/>
116+
</before>
117+
<after>
118+
<!-- Go to the tax rule page and delete the row we created-->
119+
<amOnPage url="{{AdminTaxRuleGridPage.url}}" stepKey="goToTaxRulesPage"/>
120+
<waitForPageLoad stepKey="waitForRulesPage"/>
121+
<actionGroup ref="deleteEntitySecondaryGrid" stepKey="deleteRule">
122+
<argument name="name" value="SampleRule"/>
123+
<argument name="searchInput" value="{{AdminSecondaryGridSection.taxIdentifierSearch}}"/>
124+
</actionGroup>
125+
126+
<!-- Go to the tax rate page -->
127+
<amOnPage url="{{AdminTaxRateGridPage.url}}" stepKey="goToTaxRatesPage"/>
128+
<waitForPageLoad stepKey="waitForRatesPage"/>
129+
<!-- Delete the two tax rates that were created -->
130+
<actionGroup ref="deleteEntitySecondaryGrid" stepKey="deleteNYRate">
131+
<argument name="name" value="{{SimpleTaxNY.state}}-{{SimpleTaxNY.rate}}"/>
132+
<argument name="searchInput" value="{{AdminSecondaryGridSection.taxIdentifierSearch}}"/>
133+
</actionGroup>
134+
135+
<actionGroup ref="deleteEntitySecondaryGrid" stepKey="deleteCARate">
136+
<argument name="name" value="{{SimpleTaxCA.state}}-{{SimpleTaxCA.rate}}"/>
137+
<argument name="searchInput" value="{{AdminSecondaryGridSection.taxIdentifierSearch}}"/>
138+
</actionGroup>
139+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
140+
<deleteData createDataKey="simpleproduct1" stepKey="deleteProduct1"/>
141+
<deleteData createDataKey="simplecategory" stepKey="deleteCategory"/>
142+
<deleteData createDataKey="multiple_address_customer" stepKey="deleteCustomer"/>
143+
</after>
144+
145+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLogin">
146+
<argument name="Customer" value="$$multiple_address_customer$$" />
147+
</actionGroup>
148+
149+
<amOnPage url="{{StorefrontCategoryPage.url($$simplecategory.name$$)}}" stepKey="onCategoryPage1"/>
150+
<waitForPageLoad stepKey="waitForCatalogPageLoad1"/>
151+
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverProduct1"/>
152+
<click selector="{{StorefrontCategoryMainSection.AddToCartBtn}}" stepKey="addToCart1"/>
153+
<waitForElementVisible selector="{{StorefrontCategoryMainSection.SuccessMsg}}" time="30" stepKey="waitForProductAdded1"/>
154+
<see selector="{{StorefrontCategoryMainSection.SuccessMsg}}" userInput="You added $$simpleproduct1.name$$ to your shopping cart." stepKey="seeAddedToCartMessage1"/>
155+
<see selector="{{StorefrontMinicartSection.quantity}}" userInput="1" stepKey="seeCartQuantity1"/>
156+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart1" />
157+
158+
<click stepKey="selectFirstShippingMethod1" selector="{{CheckoutShippingMethodsSection.firstShippingMethod}}"/>
159+
<waitForElement stepKey="waitForShippingMethodSelect1" selector="{{CheckoutShippingMethodsSection.next}}" time="30"/>
160+
<click stepKey="clickNextOnShippingMethodLoad1" selector="{{CheckoutShippingMethodsSection.next}}" />
161+
<waitForPageLoad stepKey="waitForPaymentLoad1"/>
162+
<waitForElement stepKey="waitForPlaceOrderButton1" selector="{{CheckoutPaymentSection.placeOrder}}" time="30" />
163+
<see stepKey="seeBillingAddressIsCorrect1" selector="{{CheckoutPaymentSection.billingAddress}}" userInput="{{US_Address_NY.street[0]}}" />
164+
<click stepKey="clickPlaceOrderButton1" selector="{{CheckoutPaymentSection.placeOrder}}" />
165+
<waitForPageLoad stepKey="waitForOrderSuccessPage1"/>
166+
<see stepKey="seeSuccessMessage1" selector="{{CheckoutSuccessMainSection.success}}" userInput="Your order number is:" />
167+
168+
<amOnPage url="{{StorefrontCategoryPage.url($$simplecategory.name$$)}}" stepKey="onCategoryPage2"/>
169+
<waitForPageLoad stepKey="waitForCatalogPageLoad2"/>
170+
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverProduct2"/>
171+
<click selector="{{StorefrontCategoryMainSection.AddToCartBtn}}" stepKey="addToCart2"/>
172+
<waitForElementVisible selector="{{StorefrontCategoryMainSection.SuccessMsg}}" time="30" stepKey="waitForProductAdded2"/>
173+
<see selector="{{StorefrontCategoryMainSection.SuccessMsg}}" userInput="You added $$simpleproduct1.name$$ to your shopping cart." stepKey="seeAddedToCartMessage2"/>
174+
<see selector="{{StorefrontMinicartSection.quantity}}" userInput="1" stepKey="seeCartQuantity2"/>
175+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart2" />
176+
177+
<click stepKey="changeShippingAddress" selector="{{CheckoutShippingMethodsSection.shipHereButton}}"/>
178+
<waitForElementVisible stepKey="waitForShippingMethodLoaderVisible" selector="{{CheckoutShippingMethodsSection.shippingMethodLoader}}" time="30"/>
179+
<waitForElementNotVisible stepKey="waitForShippingMethodLoaderNotVisible" selector="{{CheckoutShippingMethodsSection.shippingMethodLoader}}" time="30"/>
180+
<click stepKey="selectFirstShippingMethod2" selector="{{CheckoutShippingMethodsSection.firstShippingMethod}}"/>
181+
<waitForElement stepKey="waitForShippingMethodSelect2" selector="{{CheckoutShippingMethodsSection.next}}" time="30"/>
182+
<click stepKey="clickNextOnShippingMethodLoad2" selector="{{CheckoutShippingMethodsSection.next}}" />
183+
<waitForPageLoad stepKey="waitForPaymentLoad2"/>
184+
<waitForElement stepKey="waitForPlaceOrderButton2" selector="{{CheckoutPaymentSection.placeOrder}}" time="30" />
185+
<see stepKey="seeBillingAddressIsCorrect2" selector="{{CheckoutPaymentSection.billingAddress}}" userInput="{{UK_Not_Default_Address.street[0]}}" />
186+
<click stepKey="clickPlaceOrderButton2" selector="{{CheckoutPaymentSection.placeOrder}}" />
187+
<waitForPageLoad stepKey="waitForOrderSuccessPage2"/>
188+
<see stepKey="seeSuccessMessage2" selector="{{CheckoutSuccessMainSection.success}}" userInput="Your order number is:" />
189+
</test>
85190
</tests>

app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,16 @@
9393
<data key="country_id">GB</data>
9494
<data key="telephone">512-345-6789</data>
9595
</entity>
96+
<entity name="UK_Not_Default_Address" type="address">
97+
<data key="firstname">Jane</data>
98+
<data key="lastname">Doe</data>
99+
<data key="company">Magento</data>
100+
<array key="street">
101+
<item>172, Westminster Bridge Rd</item>
102+
</array>
103+
<data key="city">London</data>
104+
<data key="postcode">SE1 7RW</data>
105+
<data key="country_id">GB</data>
106+
<data key="telephone">444-44-444-44</data>
107+
</entity>
96108
</entities>

app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@
4545
<data key="website_id">0</data>
4646
<requiredEntity type="address">US_Address_TX</requiredEntity>
4747
</entity>
48+
<entity name="Simple_US_Customer_Multiple_Addresses" type="customer">
49+
<data key="group_id">0</data>
50+
<data key="default_billing">true</data>
51+
<data key="default_shipping">true</data>
52+
<data key="email" unique="prefix">[email protected]</data>
53+
<data key="firstname">John</data>
54+
<data key="lastname">Doe</data>
55+
<data key="fullname">John Doe</data>
56+
<data key="password">pwdTest123!</data>
57+
<data key="store_id">0</data>
58+
<data key="website_id">0</data>
59+
<requiredEntity type="address">US_Address_NY</requiredEntity>
60+
<requiredEntity type="address">UK_Not_Default_Address</requiredEntity>
61+
</entity>
4862
<entity name="Simple_US_Customer_NY" type="customer">
4963
<data key="group_id">0</data>
5064
<data key="default_billing">true</data>

app/code/Magento/Tax/Model/Plugin/OrderSave.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Tax\Model\Plugin;
99

10+
use Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxExtension;
11+
1012
class OrderSave
1113
{
1214
/**
@@ -79,8 +81,9 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
7981
foreach ($taxesForItems as $taxesArray) {
8082
foreach ($taxesArray['applied_taxes'] as $rates) {
8183
if (isset($rates['extension_attributes'])) {
82-
/** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $taxRates */
83-
$taxRates = $rates['extension_attributes']->getRates();
84+
$taxRates = $rates['extension_attributes'] instanceof OrderTaxDetailsAppliedTaxExtension
85+
? $rates['extension_attributes']->getRates()
86+
: $rates['extension_attributes']['rates'];
8487
if (is_array($taxRates)) {
8588
if (count($taxRates) == 1) {
8689
$ratesIdQuoteItemId[$rates['id']][] = [
@@ -124,8 +127,9 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
124127
foreach ($taxes as $row) {
125128
$id = $row['id'];
126129
if (isset($row['extension_attributes'])) {
127-
/** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $taxRates */
128-
$taxRates = $row['extension_attributes']->getRates();
130+
$taxRates = $row['extension_attributes'] instanceof OrderTaxDetailsAppliedTaxExtension
131+
? $row['extension_attributes']->getRates()
132+
: $row['extension_attributes']['rates'];
129133
if (is_array($taxRates)) {
130134
foreach ($taxRates as $tax) {
131135
if ($row['percent'] == null) {

0 commit comments

Comments
 (0)