Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 6820468

Browse files
authored
Merge pull request #3108 from magento-epam/EPAM-PR-5
[epam] MAGETWO-59529: Shipment with shipping label returns a blank result via REST API
2 parents e45aa7e + 7e2d9f0 commit 6820468

File tree

21 files changed

+408
-7
lines changed

21 files changed

+408
-7
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
<field id="destinations" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
235235
<label>Top destinations</label>
236236
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
237+
<can_be_empty>1</can_be_empty>
237238
</field>
238239
</group>
239240
<group id="locale" translate="label" type="text" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">

app/code/Magento/Checkout/Test/Mftf/ActionGroup/CheckoutActionGroup.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,13 @@
145145
<see selector="{{CheckoutSuccessMainSection.success}}" userInput="{{emailYouMessage}}" stepKey="seeEmailYou"/>
146146
</actionGroup>
147147

148+
<!--Verify country options in checkout top destination section-->
149+
<actionGroup name="VerifyTopDestinationsCountry">
150+
<arguments>
151+
<argument name="country" type="string"/>
152+
<argument name="placeNumber"/>
153+
</arguments>
154+
<conditionalClick selector="{{CheckoutCartSummarySection.shippingHeading}}" dependentSelector="{{CheckoutCartSummarySection.country}}" visible="false" stepKey="openShippingDetails"/>
155+
<see selector="{{CheckoutCartSummarySection.countryParameterized('placeNumber')}}" userInput="{{country}}" stepKey="seeCountry"/>
156+
</actionGroup>
148157
</actionGroups>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="Countries" type="countryArray">
12+
<array key="country">
13+
<item>Bahamas</item>
14+
</array>
15+
</entity>
16+
</entities>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<element name="postcode" type="input" selector="input[name='postcode']" timeout="10"/>
2020
<element name="stateProvince" type="select" selector="select[name='region_id']" timeout="10"/>
2121
<element name="country" type="select" selector="select[name='country_id']" timeout="10"/>
22+
<element name="countryParameterized" type="select" selector="select[name='country_id'] > option:nth-child({{var}})" timeout="10" parameterized="true"/>
2223
<element name="estimateShippingAndTax" type="text" selector="#block-shipping-heading" timeout="5"/>
2324
<element name="flatRateShippingMethod" type="radio" selector="#s_method_flatrate_flatrate" timeout="30"/>
2425
</section>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
10+
<test name="CheckoutSpecificDestinationsTest">
11+
<annotations>
12+
<title value="Check that top destinations can be removed after a selection was previously saved"/>
13+
<stories value="MAGETWO-91511: Top destinations cannot be removed after a selection was previously saved"/>
14+
<description value="Check that top destinations can be removed after a selection was previously saved"/>
15+
<features value="Checkout"/>
16+
<severity value="AVERAGE"/>
17+
<testCaseId value="MAGETWO-94195"/>
18+
<group value="Checkout"/>
19+
</annotations>
20+
21+
<before>
22+
<createData entity="_defaultCategory" stepKey="defaultCategory"/>
23+
<createData entity="_defaultProduct" stepKey="simpleProduct">
24+
<requiredEntity createDataKey="defaultCategory"/>
25+
</createData>
26+
27+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
28+
</before>
29+
30+
<!--Go to configuration general page-->
31+
<actionGroup ref="NavigateToConfigurationGeneralPage" stepKey="navigateToConfigurationGeneralPage"/>
32+
33+
<!--Open country options section-->
34+
<conditionalClick selector="{{CountryOptionsSection.countryOptions}}" dependentSelector="{{CountryOptionsSection.countryOptionsOpen}}" visible="false" stepKey="clickOnStoreInformation"/>
35+
36+
<!--Select top destinations country-->
37+
<actionGroup ref="SelectTopDestinationsCountry" stepKey="selectTopDestinationsCountry">
38+
<argument name="countries" value="Countries"/>
39+
</actionGroup>
40+
41+
<!--Go to product page-->
42+
<amOnPage url="{{StorefrontProductPage.url($$simpleProduct.name$$)}}" stepKey="amOnStorefrontProductPage"/>
43+
<waitForPageLoad stepKey="waitForProductPageLoad"/>
44+
45+
<!--Add product to cart-->
46+
<actionGroup ref="StorefrontAddToCartCustomOptionsProductPageActionGroup" stepKey="addToCart">
47+
<argument name="productName" value="$$simpleProduct.name$$"/>
48+
</actionGroup>
49+
50+
<!--Go to shopping cart-->
51+
<amOnPage url="{{CheckoutCartPage.url}}" stepKey="amOnPageShoppingCart"/>
52+
53+
<!--Verify country options in checkout top destination section-->
54+
<actionGroup ref="VerifyTopDestinationsCountry" stepKey="verifyTopDestinationsCountry">
55+
<argument name="country" value="Bahamas"/>
56+
<argument name="placeNumber" value="2"/>
57+
</actionGroup>
58+
59+
<!--Go to configuration general page-->
60+
<actionGroup ref="NavigateToConfigurationGeneralPage" stepKey="navigateToConfigurationGeneralPage2"/>
61+
62+
<!--Open country options section-->
63+
<conditionalClick selector="{{CountryOptionsSection.countryOptions}}" dependentSelector="{{CountryOptionsSection.countryOptionsOpen}}" visible="false" stepKey="clickOnStoreInformation2"/>
64+
65+
<!--Deselect top destinations country-->
66+
<actionGroup ref="UnSelectTopDestinationsCountry" stepKey="unSelectTopDestinationsCountry">
67+
<argument name="countries" value="Countries"/>
68+
</actionGroup>
69+
70+
<!--Go to shopping cart-->
71+
<amOnPage url="{{CheckoutCartPage.url}}" stepKey="amOnPageShoppingCart2"/>
72+
73+
<!--Verify country options is shown by default-->
74+
<actionGroup ref="VerifyTopDestinationsCountry" stepKey="verifyTopDestinationsCountry2">
75+
<argument name="country" value="Afghanistan"/>
76+
<argument name="placeNumber" value="2"/>
77+
</actionGroup>
78+
79+
<after>
80+
<actionGroup ref="logout" stepKey="logout"/>
81+
82+
<deleteData createDataKey="simpleProduct" stepKey="deleteProduct"/>
83+
<deleteData createDataKey="defaultCategory" stepKey="deleteCategory"/>
84+
</after>
85+
</test>
86+
</tests>

app/code/Magento/Config/Test/Mftf/ActionGroup/GeneralConfigurationActionGroup.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,27 @@
1414
<conditionalClick stepKey="expandDefaultLayouts" selector="{{WebSection.DefaultLayoutsTab}}" dependentSelector="{{WebSection.CheckIfTabExpand}}" visible="true" />
1515
<waitForElementVisible selector="{{DefaultLayoutsSection.categoryLayout}}" stepKey="waittForDefaultCategoryLayout" />
1616
</actionGroup>
17+
18+
<actionGroup name="NavigateToConfigurationGeneralPage">
19+
<amOnPage url="{{AdminConfigGeneralPage.url}}" stepKey="navigateToConfigGeneralPage"/>
20+
<waitForPageLoad stepKey="waitForConfigPageLoad"/>
21+
</actionGroup>
22+
23+
<actionGroup name="SelectTopDestinationsCountry">
24+
<arguments>
25+
<argument name="countries" type="countryArray"/>
26+
</arguments>
27+
<selectOption selector="{{CountryOptionsSection.topDestinations}}" parameterArray="[{{countries.country}}]" stepKey="selectTopDestinationsCountry"/>
28+
<click selector="#save" stepKey="saveConfig"/>
29+
<waitForPageLoad stepKey="waitForSavingConfig"/>
30+
</actionGroup>
31+
32+
<actionGroup name="UnSelectTopDestinationsCountry">
33+
<arguments>
34+
<argument name="countries" type="countryArray"/>
35+
</arguments>
36+
<unselectOption selector="{{CountryOptionsSection.topDestinations}}" parameterArray="[{{countries.country}}]" stepKey="unSelectTopDestinationsCountry"/>
37+
<click selector="#save" stepKey="saveConfig"/>
38+
<waitForPageLoad stepKey="waitForSavingConfig"/>
39+
</actionGroup>
1740
</actionGroups>

app/code/Magento/Config/Test/Mftf/Page/AdminConfigPage.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
<page name="AdminSalesTaxClassPage" url="admin/system_config/edit/section/tax/" area="admin" module="Magento_Config">
1919
<section name="SalesTaxClassSection"/>
2020
</page>
21+
<page name="AdminConfigGeneralPage" url="admin/system_config/edit/section/general/" area="admin" module="Magento_Config">
22+
<section name="GeneralSection"/>
23+
</page>
2124
</pages>

app/code/Magento/Config/Test/Mftf/Section/GeneralSection.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@
3333
<element name="addStoreCodeToUrl" type="select" selector="#web_url_use_store"/>
3434
<element name="systemValueForStoreCode" type="checkbox" selector="#web_url_use_store_inherit"/>
3535
</section>
36+
<section name="CountryOptionsSection">
37+
<element name="countryOptions" type="button" selector="#general_country-head"/>
38+
<element name="countryOptionsOpen" type="button" selector="#general_country-head.open"/>
39+
<element name="topDestinations" type="select" selector="#general_country_destinations"/>
40+
</section>
3641
</sections>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Plugin;
9+
10+
/**
11+
* Plugin to convert shipping label from blob to base64encoded string
12+
*/
13+
class ShippingLabelConverter
14+
{
15+
/**
16+
* Convert shipping label from blob to base64encoded string
17+
*
18+
* @param \Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository
19+
* @param \Magento\Sales\Api\Data\ShipmentSearchResultInterface $searchResult
20+
* @return \Magento\Sales\Api\Data\ShipmentSearchResultInterface
21+
*
22+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
23+
*/
24+
public function afterGetList(
25+
\Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository,
26+
\Magento\Sales\Api\Data\ShipmentSearchResultInterface $searchResult
27+
) {
28+
/** @var \Magento\Sales\Model\Order\Shipment $item */
29+
foreach ($searchResult->getItems() as $item) {
30+
if ($item->getShippingLabel() !== null) {
31+
$item->setShippingLabel(base64_encode($item->getShippingLabel()));
32+
}
33+
}
34+
return $searchResult;
35+
}
36+
37+
/**
38+
* Convert shipping label from blob to base64encoded string
39+
*
40+
* @param \Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository
41+
* @param \Magento\Sales\Api\Data\ShipmentInterface $shipment
42+
* @return \Magento\Sales\Api\Data\ShipmentInterface
43+
*
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
45+
*/
46+
public function afterGet(
47+
\Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository,
48+
\Magento\Sales\Api\Data\ShipmentInterface $shipment
49+
) {
50+
if ($shipment->getShippingLabel() !== null) {
51+
$shipment->setShippingLabel(base64_encode($shipment->getShippingLabel()));
52+
}
53+
return $shipment;
54+
}
55+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Test\Unit\Model\Order\Shipment\Plugin;
9+
10+
/**
11+
* Unit test for plugin to convert shipping label from blob to base64encoded string
12+
*/
13+
class ShippingLabelConverterTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var \Magento\Sales\Plugin\ShippingLabelConverter
17+
*/
18+
private $model;
19+
20+
/**
21+
* @var \Magento\Sales\Api\Data\ShipmentInterface|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $shipmentMock;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function setUp()
29+
{
30+
$this->model = new \Magento\Sales\Plugin\ShippingLabelConverter();
31+
32+
$shippingLabel = 'shipping_label_test';
33+
$shippingLabelEncoded = base64_encode('shipping_label_test');
34+
$this->shipmentMock = $this->getMockBuilder(\Magento\Sales\Api\Data\ShipmentInterface::class)
35+
->disableOriginalConstructor()->getMock();
36+
$this->shipmentMock->expects($this->exactly(2))->method('getShippingLabel')->willReturn($shippingLabel);
37+
$this->shipmentMock->expects($this->once())
38+
->method('setShippingLabel')
39+
->with($shippingLabelEncoded)
40+
->willReturnSelf();
41+
}
42+
43+
/**
44+
* @covers \Magento\Sales\Plugin\ShippingLabelConverter::afterGet()
45+
*/
46+
public function testAfterGet()
47+
{
48+
$this->model->afterGet(
49+
$this->getMockBuilder(\Magento\Sales\Api\ShipmentRepositoryInterface::class)
50+
->disableOriginalConstructor()->getMock(),
51+
$this->shipmentMock
52+
);
53+
}
54+
55+
/**
56+
* @covers \Magento\Sales\Plugin\ShippingLabelConverter::afterGetList()
57+
*/
58+
public function testAfterGetList()
59+
{
60+
$searchResultMock = $this->getMockBuilder(\Magento\Sales\Api\Data\ShipmentSearchResultInterface::class)
61+
->disableOriginalConstructor()->getMock();
62+
$searchResultMock->expects($this->once())->method('getItems')->willReturn([$this->shipmentMock]);
63+
64+
$this->model->afterGetList(
65+
$this->getMockBuilder(\Magento\Sales\Api\ShipmentRepositoryInterface::class)
66+
->disableOriginalConstructor()->getMock(),
67+
$searchResultMock
68+
);
69+
}
70+
}

app/code/Magento/Sales/etc/webapi_rest/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
<type name="Magento\Sales\Model\ResourceModel\Order">
1313
<plugin name="authorization" type="Magento\Sales\Model\ResourceModel\Order\Plugin\Authorization" />
1414
</type>
15+
<type name="Magento\Sales\Api\ShipmentRepositoryInterface">
16+
<plugin name="convert_blob_to_string" type="Magento\Sales\Plugin\ShippingLabelConverter" />
17+
</type>
1518
</config>

app/code/Magento/Sales/etc/webapi_soap/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
<type name="Magento\Sales\Model\ResourceModel\Order">
1313
<plugin name="authorization" type="Magento\Sales\Model\ResourceModel\Order\Plugin\Authorization" />
1414
</type>
15+
<type name="Magento\Sales\Api\ShipmentRepositoryInterface">
16+
<plugin name="convert_blob_to_string" type="Magento\Sales\Plugin\ShippingLabelConverter" />
17+
</type>
1518
</config>

app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ class Configurable extends \Magento\ConfigurableProduct\Block\Product\View\Type\
4747
*/
4848
const MEDIA_CALLBACK_ACTION = 'swatches/ajax/media';
4949

50+
/**
51+
* Name of swatch image for json config
52+
*/
53+
const SWATCH_IMAGE_NAME = 'swatchImage';
54+
55+
/**
56+
* Name of swatch thumbnail for json config
57+
*/
58+
const SWATCH_THUMBNAIL_NAME = 'swatchThumb';
59+
5060
/**
5161
* @var Product
5262
*/
@@ -473,4 +483,22 @@ public function getIdentities()
473483
return [];
474484
}
475485
}
486+
487+
/**
488+
* Get Swatch image size config data.
489+
*
490+
* @return string
491+
*/
492+
public function getJsonSwatchSizeConfig()
493+
{
494+
$imageConfig = $this->swatchMediaHelper->getImageConfig();
495+
$sizeConfig = [];
496+
497+
$sizeConfig[self::SWATCH_IMAGE_NAME]['width'] = $imageConfig[Swatch::SWATCH_IMAGE_NAME]['width'];
498+
$sizeConfig[self::SWATCH_IMAGE_NAME]['height'] = $imageConfig[Swatch::SWATCH_IMAGE_NAME]['height'];
499+
$sizeConfig[self::SWATCH_THUMBNAIL_NAME]['height'] = $imageConfig[Swatch::SWATCH_THUMBNAIL_NAME]['height'];
500+
$sizeConfig[self::SWATCH_THUMBNAIL_NAME]['width'] = $imageConfig[Swatch::SWATCH_THUMBNAIL_NAME]['width'];
501+
502+
return $this->jsonEncoder->encode($sizeConfig);
503+
}
476504
}

app/code/Magento/Swatches/view/frontend/templates/product/view/renderer.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
1919
"mediaCallback": "<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>",
2020
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
21-
'Magento_ConfigurableProduct') ?: 'replace'; ?>"
21+
'Magento_ConfigurableProduct') ?: 'replace'; ?>",
22+
"jsonSwatchImageSizeConfig": <?php /* @noEscape */ echo $block->getJsonSwatchSizeConfig() ?>
2223
}
2324
},
2425
"*" : {

0 commit comments

Comments
 (0)