Skip to content

Commit e97a673

Browse files
committed
MAGETWO-60958: [Backport] Incorrect province code sent on Checkout to UPS #6564 - for 2.1
- MAGETWO-70727: [GitHub] Shipping method randomly dissapear when page refreshed for 2.1 #7497
1 parent 0987a02 commit e97a673

File tree

10 files changed

+315
-8
lines changed

10 files changed

+315
-8
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ define(
4444
addressData.region.region_code = region['code'];
4545
addressData.region.region = region['name'];
4646
}
47+
} else if (
48+
!addressData.region_id
49+
&& countryData()[addressData.country_id]
50+
&& countryData()[addressData.country_id]['regions']
51+
) {
52+
addressData.region.region_code = '';
53+
addressData.region.region = '';
4754
}
4855
delete addressData.region_id;
4956

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ define(
177177
address;
178178

179179
if (this.validateAddressData(addressFlat)) {
180-
addressFlat = $.extend(true, {}, quote.shippingAddress(), addressFlat);
180+
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
181181
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
182182
selectShippingAddress(address);
183183
}

app/code/Magento/Ups/Model/Carrier.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,13 @@ protected function _getXmlQuotes()
739739
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
740740
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (bool)$this->getConfigFlag('mode_xml'));
741741
$xmlResponse = curl_exec($ch);
742-
743-
$debugData['result'] = $xmlResponse;
744-
$this->_setCachedQuotes($xmlRequest, $xmlResponse);
742+
if ($xmlResponse !== false) {
743+
$debugData['result'] = $xmlResponse;
744+
$this->_setCachedQuotes($xmlRequest, $xmlResponse);
745+
} else {
746+
$debugData['result'] = ['error' => curl_error($ch)];
747+
}
748+
curl_close($ch);
745749
} catch (\Exception $e) {
746750
$debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
747751
$xmlResponse = '';
@@ -1002,7 +1006,11 @@ protected function _getXmlTracking($trackings)
10021006
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
10031007
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
10041008
$xmlResponse = curl_exec($ch);
1005-
$debugData['result'] = $xmlResponse;
1009+
if ($xmlResponse !== false) {
1010+
$debugData['result'] = $xmlResponse;
1011+
} else {
1012+
$debugData['result'] = ['error' => curl_error($ch)];
1013+
}
10061014
curl_close($ch);
10071015
} catch (\Exception $e) {
10081016
$debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/Method.php

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ class Method extends Block
4242
*/
4343
protected $blockWaitElement = '._block-content-loading';
4444

45+
/**
46+
* Shipping method row locator.
47+
*
48+
* @var string
49+
*/
50+
private $shippingMethodRow = '#checkout-step-shipping_method tbody tr.row';
51+
52+
/**
53+
* Shipping error row locator.
54+
*
55+
* @var string
56+
*/
57+
private $shippingError = '#checkout-step-shipping_method tbody tr.row-error';
58+
4559
/**
4660
* Select shipping method.
4761
*
@@ -50,10 +64,9 @@ class Method extends Block
5064
*/
5165
public function selectShippingMethod(array $method)
5266
{
53-
// Code under test uses JavaScript setTimeout at this point as well.
54-
sleep(3);
67+
$this->waitForShippingRates();
68+
5569
$selector = sprintf($this->shippingMethod, $method['shipping_method'], $method['shipping_service']);
56-
$this->waitForElementNotVisible($this->blockWaitElement);
5770
$this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->click();
5871
}
5972

@@ -74,4 +87,62 @@ function () use ($browser, $selector) {
7487
}
7588
);
7689
}
90+
91+
/**
92+
* Wait until shipping rates will appear.
93+
*
94+
* @return void
95+
*/
96+
public function waitForShippingRates()
97+
{
98+
// Code under test uses JavaScript setTimeout at this point as well.
99+
sleep(3);
100+
$this->waitForElementNotVisible($this->blockWaitElement);
101+
}
102+
103+
/**
104+
* Return available shipping methods with prices.
105+
*
106+
* @return array
107+
*/
108+
public function getAvailableMethods()
109+
{
110+
$this->waitForShippingRates();
111+
$methods = $this->_rootElement->getElements($this->shippingMethodRow);
112+
$result = [];
113+
foreach ($methods as $method) {
114+
$methodName = trim($method->find('td.col-method:not(:first-child)')->getText());
115+
$methodPrice = trim($method->find('td.col-price')->getText());
116+
$methodPrice = $this->escapeCurrency($methodPrice);
117+
118+
$result[$methodName] = $methodPrice;
119+
}
120+
121+
return $result;
122+
}
123+
124+
/**
125+
* Is shipping rates estimation error present.
126+
*
127+
* @return bool
128+
*/
129+
public function isErrorPresent()
130+
{
131+
$this->waitForShippingRates();
132+
133+
return $this->_rootElement->find($this->shippingError)->isVisible();
134+
}
135+
136+
/**
137+
* Escape currency in price.
138+
*
139+
* @param string $price
140+
* @return string|null
141+
*/
142+
private function escapeCurrency($price)
143+
{
144+
preg_match("/^\\D*\\s*([\\d,\\.]+)\\s*\\D*$/", $price, $matches);
145+
146+
return (isset($matches[1])) ? $matches[1] : null;
147+
}
77148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\Constraint;
8+
9+
use Magento\Checkout\Test\Page\CheckoutOnepage;
10+
use Magento\Checkout\Test\TestStep\FillShippingAddressStep;
11+
use Magento\Mtf\Client\BrowserInterface;
12+
use Magento\Mtf\Constraint\AbstractConstraint;
13+
use Magento\Mtf\Fixture\FixtureFactory;
14+
use Magento\Mtf\TestStep\TestStepFactory;
15+
16+
/**
17+
* Asserts that shipping methods are present on checkout page after address modification.
18+
*/
19+
class AssertShippingMethodsSuccessEstimateAfterAddressEdit extends AbstractConstraint
20+
{
21+
/**
22+
* Asserts that shipping methods are present on checkout page after address modification.
23+
*
24+
* @param CheckoutOnepage $checkoutOnepage
25+
* @param TestStepFactory $testStepFactory
26+
* @param FixtureFactory $fixtureFactory
27+
* @param BrowserInterface $browser
28+
* @param array $editAddressData
29+
* @return void
30+
*/
31+
public function processAssert(
32+
CheckoutOnepage $checkoutOnepage,
33+
TestStepFactory $testStepFactory,
34+
FixtureFactory $fixtureFactory,
35+
BrowserInterface $browser,
36+
array $editAddressData = []
37+
) {
38+
if ($this->shouldOpenCheckout($checkoutOnepage, $browser)) {
39+
$checkoutOnepage->open();
40+
}
41+
42+
if (!empty ($editAddressData)) {
43+
44+
$address = $fixtureFactory->createByCode('address', ['data' => $editAddressData]);
45+
$testStepFactory->create(
46+
FillShippingAddressStep::class,
47+
[
48+
'checkoutOnepage' => $checkoutOnepage,
49+
'shippingAddress' => $address
50+
]
51+
)->run();
52+
53+
\PHPUnit_Framework_Assert::assertFalse(
54+
$checkoutOnepage->getShippingMethodBlock()->isErrorPresent(),
55+
'Shipping estimation error is present.'
56+
);
57+
58+
$methods = $checkoutOnepage->getShippingMethodBlock()->getAvailableMethods();
59+
\PHPUnit_Framework_Assert::assertNotEmpty(
60+
$methods,
61+
'No shipping methods are present.'
62+
);
63+
}
64+
}
65+
66+
/**
67+
* Should open checkout page or not.
68+
*
69+
* @param CheckoutOnepage $checkoutOnepage
70+
* @param BrowserInterface $browser
71+
* @return bool
72+
*/
73+
private function shouldOpenCheckout(CheckoutOnepage $checkoutOnepage, BrowserInterface $browser)
74+
{
75+
$result = true;
76+
77+
foreach (['checkout/', $checkoutOnepage::MCA] as $path) {
78+
$length = strlen($path);
79+
if (substr($browser->getUrl(), -$length) === $path) {
80+
$result = false;
81+
break;
82+
}
83+
}
84+
85+
return $result;
86+
}
87+
88+
/**
89+
* Returns a string representation of the object.
90+
*
91+
* @return string
92+
*/
93+
public function toString()
94+
{
95+
return "Shipping methods are present on checkout page after address modification.";
96+
}
97+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\TestCase;
8+
9+
use Magento\Mtf\TestCase\Scenario;
10+
11+
/**
12+
* Preconditions:
13+
* 1. Configure shipping method according dataset.
14+
* 2. Create product(-s)
15+
*
16+
* Steps:
17+
* 1. Go to Frontend.
18+
* 2. Add product(-s) to the cart.
19+
* 3. Proceed to Checkout.
20+
* 4. Fill shipping address according to dataset.
21+
* 5. Wait until shipping methods will appear.
22+
* 6. Perform assertions.
23+
*
24+
* @group One_Page_Checkout_(CS)
25+
* @ZephyrId MAGETWO-71002
26+
*/
27+
class OnePageEstimateShippingMethodsTest extends Scenario
28+
{
29+
/**
30+
* Runs test.
31+
*
32+
* @return void
33+
*/
34+
public function test()
35+
{
36+
$this->executeScenario();
37+
}
38+
}

dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/FillShippingAddressStep.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function run()
5151
{
5252
if ($this->shippingAddress) {
5353
$this->checkoutOnepage->getShippingBlock()->fill($this->shippingAddress);
54+
$this->checkoutOnepage->getShippingMethodBlock()->waitForShippingRates();
5455
}
5556
}
5657
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\TestStep;
8+
9+
use Magento\Checkout\Test\Page\CheckoutOnepage;
10+
use Magento\Mtf\TestStep\TestStepInterface;
11+
12+
/**
13+
* Resolve shipping methods from checkout page.
14+
*/
15+
class ResolveShippingMethodsStep implements TestStepInterface
16+
{
17+
/**
18+
* Checkout view page.
19+
*
20+
* @var CheckoutOnepage
21+
*/
22+
private $checkoutOnepage;
23+
24+
/**
25+
* Open checkout page or not.
26+
*
27+
* @var bool
28+
*/
29+
private $openPage = false;
30+
31+
/**
32+
* @param CheckoutOnepage $checkoutOnepage
33+
* @param bool $openPage
34+
*/
35+
public function __construct(CheckoutOnepage $checkoutOnepage, $openPage = false)
36+
{
37+
$this->checkoutOnepage = $checkoutOnepage;
38+
$this->openPage = $openPage;
39+
}
40+
41+
/**
42+
* Run step flow.
43+
*
44+
* @return array
45+
*/
46+
public function run()
47+
{
48+
if ($this->openPage) {
49+
$this->checkoutOnepage->open();
50+
}
51+
52+
$methods = $this->checkoutOnepage->getShippingMethodBlock()->getAvailableMethods();
53+
return ['shippingMethods' => $methods];
54+
}
55+
}

dev/tests/functional/tests/app/Magento/Checkout/Test/etc/testcase.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@
2828
<step name="addProductsToTheCart" module="Magento_Checkout" next="removeProductsFromTheCart" />
2929
<step name="removeProductsFromTheCart" module="Magento_Checkout" />
3030
</scenario>
31+
<scenario name="OnePageEstimateShippingMethodsTest" firstStep="setupConfiguration">
32+
<step name="setupConfiguration" module="Magento_Config" next="createProducts" />
33+
<step name="createProducts" module="Magento_Catalog" next="addProductsToTheCart" />
34+
<step name="addProductsToTheCart" module="Magento_Checkout" next="proceedToCheckout" />
35+
<step name="proceedToCheckout" module="Magento_Checkout" next="fillShippingAddress" />
36+
<step name="fillShippingAddress" module="Magento_Checkout" next="resolveShippingMethods" />
37+
<step name="resolveShippingMethods" module="Magento_Checkout" />
38+
</scenario>
3139
</config>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Checkout\Test\TestCase\OnePageEstimateShippingMethodsTest" summary="Estimate shipping methods at checkout" ticketId="MAGETWO-71002">
10+
<variation name="OnePageEstimateShippingMethodsTestUpsVariation" ticketId="MAGETWO-71003">
11+
<data name="products" xsi:type="string">catalogProductSimple::default</data>
12+
<data name="shippingAddress/dataset" xsi:type="string">US_address_1_without_email</data>
13+
<data name="editAddressData" xsi:type="array">
14+
<item name="city" xsi:type="string">Birmingham</item>
15+
<item name="region_id" xsi:type="string">Alabama</item>
16+
<item name="postcode" xsi:type="string">35201</item>
17+
</data>
18+
<data name="configData" xsi:type="string">ups, shipping_origin_US_CA</data>
19+
<constraint name="Magento\Checkout\Test\Constraint\AssertShippingMethodsSuccessEstimateAfterAddressEdit" />
20+
</variation>
21+
</testCase>
22+
</config>

0 commit comments

Comments
 (0)