Skip to content

Commit 5f1357c

Browse files
MAGETWO-99884: Reorder doesn't show discount price in Order Items row if the Customer Group is not Default
1 parent 364645d commit 5f1357c

File tree

4 files changed

+141
-3
lines changed

4 files changed

+141
-3
lines changed

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

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

521524
/* Initialize catalog rule data with new session values */
522525
$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/Section/AdminOrderItemsOrderedSection.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<element name="productNameColumn" type="text" selector=".edit-order-table .col-product .product-title"/>
2525
<element name="productNameOptions" type="text" selector=".edit-order-table .col-product .item-options"/>
2626
<element name="productSkuColumn" type="text" selector=".edit-order-table .col-product .product-sku-block"/>
27+
<element name="productPrice" type="text" selector=".order-tables tbody td:nth-child({{row}}) .price" parameterized="true"/>
2728
<element name="statusColumn" type="text" selector=".edit-order-table .col-status"/>
2829
<element name="originalPriceColumn" type="text" selector=".edit-order-table .col-original-price .price"/>
2930
<element name="priceColumn" type="text" selector=".edit-order-table .col-price .price"/>
@@ -34,4 +35,4 @@
3435
<element name="discountAmountColumn" type="text" selector=".edit-order-table .col-discont .price"/>
3536
<element name="totalColumn" type="text" selector=".edit-order-table .col-total .price"/>
3637
</section>
37-
</sections>
38+
</sections>

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="{{AdminOrderItemsOrderedSection.productPrice('2')}}" stepKey="waitOrderItemPriceToBeVisible"/>
63+
<see selector="{{AdminOrderItemsOrderedSection.productPrice('2')}}" userInput="${{AdminOrderSimpleProductWithCatalogRule.subtotal}}" stepKey="seeOrderItemPrice"/>
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: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
use Magento\Sales\Model\AdminOrder\Create;
2828
use Magento\Sales\Model\AdminOrder\Product;
2929
use Magento\Quote\Model\QuoteFactory;
30+
use Magento\Sales\Model\Order;
31+
use Magento\Sales\Model\Order\Item as OrderItem;
32+
use Magento\Sales\Model\ResourceModel\Order\Item\Collection as ItemCollection;
33+
use Magento\Store\Api\Data\StoreInterface;
3034
use PHPUnit_Framework_MockObject_MockObject as MockObject;
3135

3236
/**
@@ -87,6 +91,14 @@ class CreateTest extends \PHPUnit\Framework\TestCase
8791
*/
8892
private $dataObjectHelper;
8993

94+
/**
95+
* @var Order|MockObject
96+
*/
97+
private $orderMock;
98+
99+
/**
100+
* @inheritdoc
101+
*/
90102
protected function setUp()
91103
{
92104
$this->formFactory = $this->createPartialMock(FormFactory::class, ['create']);
@@ -102,9 +114,29 @@ protected function setUp()
102114

103115
$this->sessionQuote = $this->getMockBuilder(\Magento\Backend\Model\Session\Quote::class)
104116
->disableOriginalConstructor()
105-
->setMethods(['getQuote', 'getStoreId', 'getCustomerId'])
117+
->setMethods(
118+
[
119+
'getQuote',
120+
'getStoreId',
121+
'getCustomerId',
122+
'setData',
123+
'setCurrencyId',
124+
'setCustomerId',
125+
'setStoreId',
126+
'setCustomerGroupId',
127+
'getData',
128+
'getStore',
129+
'getUseOldShippingMethod',
130+
]
131+
)
106132
->getMock();
107133

134+
$storeMock = $this->getMockBuilder(StoreInterface::class)
135+
->setMethods(['getId'])
136+
->getMockForAbstractClass();
137+
$this->sessionQuote->method('getStore')
138+
->willReturn($storeMock);
139+
108140
$this->customerMapper = $this->getMockBuilder(Mapper::class)
109141
->setMethods(['toFlatArray'])
110142
->disableOriginalConstructor()
@@ -115,6 +147,24 @@ protected function setUp()
115147
->disableOriginalConstructor()
116148
->getMock();
117149

150+
$this->orderMock = $this->getMockBuilder(Order::class)
151+
->disableOriginalConstructor()
152+
->setMethods(
153+
[
154+
'getEntityId',
155+
'getId',
156+
'setReordered',
157+
'getReordered',
158+
'getOrderCurrencyCode',
159+
'getCustomerGroupId',
160+
'getItemsCollection',
161+
'getShippingAddress',
162+
'getBillingAddress',
163+
'getCouponCode',
164+
]
165+
)
166+
->getMock();
167+
118168
$objectManagerHelper = new ObjectManagerHelper($this);
119169
$this->adminOrderCreate = $objectManagerHelper->getObject(
120170
Create::class,
@@ -316,4 +366,85 @@ public function testGetCustomerCart()
316366

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

0 commit comments

Comments
 (0)