Skip to content

Commit c67bdfd

Browse files
committed
MAGETWO-53362: Gift Message not returned via API on getList #4414
1 parent 4740771 commit c67bdfd

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GiftMessage\Model\Plugin;
8+
9+
class OrderGetList extends \Magento\GiftMessage\Model\Plugin\OrderGet
10+
{
11+
/**
12+
* @param \Magento\Sales\Api\OrderRepositoryInterface $subject
13+
* @param \Magento\Sales\Model\ResourceModel\Order\Collection $resultOrder
14+
* @return \Magento\Sales\Model\ResourceModel\Order\Collection
15+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
16+
*/
17+
public function afterGetList(
18+
\Magento\Sales\Api\OrderRepositoryInterface $subject,
19+
\Magento\Sales\Model\ResourceModel\Order\Collection $resultOrder
20+
) {
21+
foreach ($resultOrder->getItems() as $order) {
22+
$this->getOrderGiftMessage($order);
23+
$this->getOrderItemGiftMessage($order);
24+
}
25+
return $resultOrder;
26+
}
27+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GiftMessage\Test\Unit\Model\Plugin;
8+
9+
class OrderGetListTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\GiftMessage\Model\Plugin\OrderGet
13+
*/
14+
private $plugin;
15+
16+
/**
17+
* @var \PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
private $giftMessageOrderRepositoryMock;
20+
21+
/**
22+
* @var \PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $giftMessageOrderItemRepositoryMock;
25+
26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $orderExtensionFactoryMock;
30+
31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $orderItemExtensionFactoryMock;
35+
36+
/**
37+
* @var \PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $orderMock;
40+
41+
/**
42+
* @var \PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $orderExtensionMock;
45+
46+
/**
47+
* @var \PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
private $giftMessageMock;
50+
51+
/**
52+
* @var \PHPUnit_Framework_MockObject_MockObject
53+
*/
54+
private $orderRepositoryMock;
55+
56+
/**
57+
* @var \PHPUnit_Framework_MockObject_MockObject
58+
*/
59+
private $collectionMock;
60+
61+
public function setUp()
62+
{
63+
$this->giftMessageOrderRepositoryMock = $this->getMock(
64+
\Magento\GiftMessage\Api\OrderRepositoryInterface::class
65+
);
66+
$this->giftMessageOrderItemRepositoryMock = $this->getMock(
67+
\Magento\GiftMessage\Api\OrderItemRepositoryInterface::class
68+
);
69+
$this->orderExtensionFactoryMock = $this->getMock(
70+
\Magento\Sales\Api\Data\OrderExtensionFactory::class,
71+
['create'],
72+
[],
73+
'',
74+
false
75+
);
76+
$this->orderItemExtensionFactoryMock = $this->getMock(
77+
\Magento\Sales\Api\Data\OrderItemExtensionFactory::class,
78+
['create'],
79+
[],
80+
'',
81+
false
82+
);
83+
$this->orderMock = $this->getMock(
84+
\Magento\Sales\Api\Data\OrderInterface::class
85+
);
86+
$this->orderExtensionMock = $this->getMock(
87+
\Magento\Sales\Api\Data\OrderExtension::class,
88+
['getGiftMessage', 'setGiftMessage'],
89+
[],
90+
'',
91+
false
92+
);
93+
$this->giftMessageMock = $this->getMock(
94+
\Magento\GiftMessage\Api\Data\MessageInterface::class
95+
);
96+
97+
$this->orderRepositoryMock = $this->getMock(
98+
\Magento\Sales\Api\OrderRepositoryInterface::class
99+
);
100+
101+
$this->collectionMock = $this->getMock(
102+
\Magento\Sales\Model\ResourceModel\Order\Collection::class,
103+
[],
104+
[],
105+
'',
106+
false
107+
);
108+
$this->plugin = new \Magento\GiftMessage\Model\Plugin\OrderGetList(
109+
$this->giftMessageOrderRepositoryMock,
110+
$this->giftMessageOrderItemRepositoryMock,
111+
$this->orderExtensionFactoryMock,
112+
$this->orderItemExtensionFactoryMock
113+
);
114+
}
115+
116+
public function testAfterGetList()
117+
{
118+
//set Gift Message List for Order
119+
$orderId = 1;
120+
$this->orderMock->expects($this->once())->method('getEntityId')->willReturn($orderId);
121+
$this->orderMock
122+
->expects($this->once())
123+
->method('getExtensionAttributes')
124+
->willReturn($this->orderExtensionMock);
125+
$this->orderExtensionMock->expects($this->once())->method('getGiftMessage')->willReturn([]);
126+
$this->giftMessageOrderRepositoryMock
127+
->expects($this->once())
128+
->method('get')
129+
->with($orderId)
130+
->willReturn($this->giftMessageMock);
131+
$this->orderExtensionMock
132+
->expects($this->once())
133+
->method('setGiftMessage')
134+
->with($this->giftMessageMock)
135+
->willReturnSelf();
136+
$this->orderMock
137+
->expects($this->once())
138+
->method('setExtensionAttributes')
139+
->with($this->orderExtensionMock)
140+
->willReturnSelf();
141+
142+
// set Gift Message on Item Level
143+
$this->orderMock->expects($this->once())->method('getItems')->willReturn([]);
144+
$this->collectionMock->expects($this->once())->method('getItems')->willReturn([$this->orderMock]);
145+
$this->plugin->afterGetList($this->orderRepositoryMock, $this->collectionMock);
146+
}
147+
148+
}

app/code/Magento/GiftMessage/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
<type name="Magento\Sales\Api\OrderRepositoryInterface">
2828
<plugin name="save_gift_message" type="Magento\GiftMessage\Model\Plugin\OrderSave"/>
2929
<plugin name="get_gift_message" type="Magento\GiftMessage\Model\Plugin\OrderGet"/>
30+
<plugin name="add_gift_messages_to_orders" type="Magento\GiftMessage\Model\Plugin\OrderGetList"/>
3031
</type>
3132
</config>

0 commit comments

Comments
 (0)