Skip to content

Commit ffc8cec

Browse files
MAGETWO-99883: Reorder doesn't show discount price in Order Items row if the Customer Group is not Default
1 parent 98703f6 commit ffc8cec

File tree

3 files changed

+136
-2
lines changed

3 files changed

+136
-2
lines changed

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
516516
/* Check if we edit guest order */
517517
$session->setCustomerId($order->getCustomerId() ?: false);
518518
$session->setStoreId($order->getStoreId());
519+
if ($session->getData('reordered')) {
520+
$this->getQuote()->setCustomerGroupId($order->getCustomerGroupId());
521+
}
519522

520523
/* Initialize catalog rule data with new session values */
521524
$this->initRuleData();
@@ -773,7 +776,7 @@ public function getCustomerCompareList()
773776
public function getCustomerGroupId()
774777
{
775778
$groupId = $this->getQuote()->getCustomerGroupId();
776-
if (!$groupId) {
779+
if (!isset($groupId)) {
777780
$groupId = $this->getSession()->getCustomerGroupId();
778781
}
779782

app/code/Magento/Sales/Test/Mftf/Test/AdminReorderWithCatalogPriceTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
</actionGroup>
5959
<!--Reorder-->
6060
<click selector="{{AdminOrderDetailsMainActionsSection.reorder}}" stepKey="clickReorder"/>
61+
<!--Verify order item row-->
62+
<waitForElementVisible selector="{{AdminOrderFormItemsSection.rowPrice('1')}}" stepKey="waitOrderItemPriceToBeVisible"/>
63+
<see selector="{{AdminOrderFormItemsSection.rowPrice('1')}}" userInput="${{AdminOrderSimpleProductWithCatalogRule.subtotal}}" stepKey="seeOrderItemSubTotal"/>
6164
<!--Verify totals on Order page-->
6265
<scrollTo selector="{{AdminOrderFormTotalSection.grandTotal}}" stepKey="scrollToOrderGrandTotal"/>
6366
<waitForElementVisible selector="{{AdminOrderFormTotalSection.total('Subtotal')}}" stepKey="waitOrderSubtotalToBeVisible"/>

app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
use Magento\Sales\Model\AdminOrder\Create;
2727
use Magento\Sales\Model\AdminOrder\Product;
2828
use Magento\Quote\Model\QuoteFactory;
29+
use Magento\Sales\Model\Order;
30+
use Magento\Sales\Model\Order\Item as OrderItem;
31+
use Magento\Sales\Model\ResourceModel\Order\Item\Collection as ItemCollection;
32+
use Magento\Store\Api\Data\StoreInterface;
2933
use PHPUnit_Framework_MockObject_MockObject as MockObject;
3034

3135
/**
@@ -86,6 +90,11 @@ class CreateTest extends \PHPUnit\Framework\TestCase
8690
*/
8791
private $dataObjectHelper;
8892

93+
/**
94+
* @var Order|MockObject
95+
*/
96+
private $orderMock;
97+
8998
protected function setUp()
9099
{
91100
$this->formFactory = $this->createPartialMock(FormFactory::class, ['create']);
@@ -101,9 +110,29 @@ protected function setUp()
101110

102111
$this->sessionQuote = $this->getMockBuilder(\Magento\Backend\Model\Session\Quote::class)
103112
->disableOriginalConstructor()
104-
->setMethods(['getQuote', 'getStoreId', 'getCustomerId'])
113+
->setMethods(
114+
[
115+
'getQuote',
116+
'getStoreId',
117+
'getCustomerId',
118+
'setData',
119+
'setCurrencyId',
120+
'setCustomerId',
121+
'setStoreId',
122+
'setCustomerGroupId',
123+
'getData',
124+
'getStore',
125+
'getUseOldShippingMethod',
126+
]
127+
)
105128
->getMock();
106129

130+
$storeMock = $this->getMockBuilder(StoreInterface::class)
131+
->setMethods(['getId'])
132+
->getMockForAbstractClass();
133+
$this->sessionQuote->method('getStore')
134+
->willReturn($storeMock);
135+
107136
$this->customerMapper = $this->getMockBuilder(Mapper::class)
108137
->setMethods(['toFlatArray'])
109138
->disableOriginalConstructor()
@@ -114,6 +143,24 @@ protected function setUp()
114143
->disableOriginalConstructor()
115144
->getMock();
116145

146+
$this->orderMock = $this->getMockBuilder(Order::class)
147+
->disableOriginalConstructor()
148+
->setMethods(
149+
[
150+
'getEntityId',
151+
'getId',
152+
'setReordered',
153+
'getReordered',
154+
'getOrderCurrencyCode',
155+
'getCustomerGroupId',
156+
'getItemsCollection',
157+
'getShippingAddress',
158+
'getBillingAddress',
159+
'getCouponCode',
160+
]
161+
)
162+
->getMock();
163+
117164
$objectManagerHelper = new ObjectManagerHelper($this);
118165
$this->adminOrderCreate = $objectManagerHelper->getObject(
119166
Create::class,
@@ -312,4 +359,85 @@ public function testGetCustomerCart()
312359

313360
$this->assertEquals($cartResult, $this->adminOrderCreate->getCustomerCart());
314361
}
362+
363+
public function testInitFromOrder()
364+
{
365+
$this->sessionQuote->method('getData')
366+
->with('reordered')
367+
->willReturn(true);
368+
369+
$address = $this->createPartialMock(
370+
Address::class,
371+
[
372+
'setSameAsBilling',
373+
'setCustomerAddressId',
374+
'getSameAsBilling'
375+
]
376+
);
377+
$address->method('getSameAsBilling')
378+
->willReturn(true);
379+
$address->method('setCustomerAddressId')
380+
->willReturnSelf();
381+
382+
$quote = $this->getMockBuilder(Quote::class)
383+
->disableOriginalConstructor()
384+
->setMethods(
385+
[
386+
'setCustomerGroupId',
387+
'getBillingAddress',
388+
'getShippingAddress',
389+
'isVirtual',
390+
'collectTotals',
391+
]
392+
)
393+
->getMock();
394+
395+
$quote->method('getBillingAddress')
396+
->willReturn($address);
397+
$quote->method('getShippingAddress')
398+
->willReturn($address);
399+
400+
$this->sessionQuote
401+
->method('getQuote')
402+
->willReturn($quote);
403+
404+
$orderItem = $this->createPartialMock(
405+
OrderItem::class,
406+
[
407+
'getParentItem',
408+
'getQtyOrdered',
409+
'getQtyShipped',
410+
'getQtyInvoiced',
411+
]
412+
);
413+
$orderItem->method('getQtyOrdered')
414+
->willReturn(2);
415+
$orderItem->method('getParentItem')
416+
->willReturn(false);
417+
418+
$iterator = new \ArrayIterator([$orderItem]);
419+
420+
$itemCollectionMock = $this->getMockBuilder(ItemCollection::class)
421+
->disableOriginalConstructor()
422+
->setMethods(['getIterator'])
423+
->getMock();
424+
$itemCollectionMock->method('getIterator')
425+
->willReturn($iterator);
426+
427+
$this->orderMock->method('getItemsCollection')
428+
->willReturn($itemCollectionMock);
429+
$this->orderMock->method('getReordered')
430+
->willReturn(false);
431+
$this->orderMock->method('getShippingAddress')
432+
->willReturn($address);
433+
$this->orderMock->method('getBillingAddress')
434+
->willReturn($address);
435+
$this->orderMock->method('getCouponCode')
436+
->willReturn(true);
437+
438+
$quote->expects($this->once())
439+
->method('setCustomerGroupId');
440+
441+
$this->adminOrderCreate->initFromOrder($this->orderMock);
442+
}
315443
}

0 commit comments

Comments
 (0)