Skip to content

Commit 599fc99

Browse files
committed
Merge remote-tracking branch 'github-magento/EPAM-MAGETWO-59529' into EPAM-PR-5
2 parents 3be6811 + 8913a34 commit 599fc99

File tree

7 files changed

+139
-1
lines changed

7 files changed

+139
-1
lines changed
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>

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipmentLabelGetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public function testShipmentGet()
5050
],
5151
];
5252
$result = $this->_webApiCall($serviceInfo, ['id' => $shipment->getId()]);
53-
$this->assertEquals($result, 'test_shipping_label');
53+
$this->assertEquals($result, base64_encode('test_shipping_label'));
5454
}
5555
}

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipmentListTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,7 @@ public function testShipmentList()
9191
$this->assertEquals($searchData, $result['search_criteria']);
9292
$this->assertEquals('100000002', $result['items'][0]['increment_id']);
9393
$this->assertEquals('100000003', $result['items'][1]['increment_id']);
94+
$this->assertEquals(base64_encode('shipping_label_100000002'), $result['items'][0]['shipping_label']);
95+
$this->assertEquals(base64_encode('shipping_label_100000003'), $result['items'][1]['shipping_label']);
9496
}
9597
}

dev/tests/integration/testsuite/Magento/Sales/_files/shipment_list.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,28 @@
2020
'shipping_address_id' => 1,
2121
'shipment_status' => \Magento\Sales\Model\Order\Shipment::STATUS_NEW,
2222
'store_id' => 1,
23+
'shipping_label' => 'shipping_label_100000001',
2324
],
2425
[
2526
'increment_id' => '100000002',
2627
'shipping_address_id' => 3,
2728
'shipment_status' => \Magento\Sales\Model\Order\Shipment::STATUS_NEW,
2829
'store_id' => 1,
30+
'shipping_label' => 'shipping_label_100000002',
2931
],
3032
[
3133
'increment_id' => '100000003',
3234
'shipping_address_id' => 3,
3335
'shipment_status' => \Magento\Sales\Model\Order\Shipment::STATUS_NEW,
3436
'store_id' => 1,
37+
'shipping_label' => 'shipping_label_100000003',
3538
],
3639
[
3740
'increment_id' => '100000004',
3841
'shipping_address_id' => 4,
3942
'shipment_status' => 'closed',
4043
'store_id' => 1,
44+
'shipping_label' => 'shipping_label_100000004',
4145
],
4246
];
4347

@@ -53,5 +57,6 @@
5357
$shipment->setShippingAddressId($shipmentData['shipping_address_id']);
5458
$shipment->setShipmentStatus($shipmentData['shipment_status']);
5559
$shipment->setStoreId($shipmentData['store_id']);
60+
$shipment->setShippingLabel($shipmentData['shipping_label']);
5661
$shipment->save();
5762
}

0 commit comments

Comments
 (0)