Skip to content

Commit 5f39ec6

Browse files
committed
MAGETWO-96441: "Custom price" can't be removed during order creation in admin
1 parent 069d5cd commit 5f39ec6

File tree

5 files changed

+103
-5
lines changed

5 files changed

+103
-5
lines changed

app/code/Magento/Quote/Model/Quote/Item/Updater.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function __construct(
6060

6161
/**
6262
* Update quote item qty.
63+
*
6364
* Custom price is updated in case 'custom_price' value exists
6465
*
6566
* @param Item $item
@@ -145,8 +146,8 @@ protected function unsetCustomPrice(Item $item)
145146
$item->addOption($infoBuyRequest);
146147
}
147148

148-
$item->unsetData('custom_price');
149-
$item->unsetData('original_custom_price');
149+
$item->setData('custom_price', null);
150+
$item->setData('original_custom_price', null);
150151
}
151152

152153
/**

app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function setUp()
6767
'addOption',
6868
'setCustomPrice',
6969
'setOriginalCustomPrice',
70-
'unsetData',
70+
'setData',
7171
'hasData',
7272
'setIsQtyDecimal'
7373
]);
@@ -301,7 +301,7 @@ public function testUpdateUnsetCustomPrice()
301301
'setProduct',
302302
'getData',
303303
'unsetData',
304-
'hasData'
304+
'hasData',
305305
]);
306306
$buyRequestMock->expects($this->never())->method('setCustomPrice');
307307
$buyRequestMock->expects($this->once())->method('getData')->will($this->returnValue([]));
@@ -353,7 +353,11 @@ public function testUpdateUnsetCustomPrice()
353353
->will($this->returnValue($buyRequestMock));
354354

355355
$this->itemMock->expects($this->exactly(2))
356-
->method('unsetData');
356+
->method('setData')
357+
->withConsecutive(
358+
['custom_price', null],
359+
['original_custom_price', null]
360+
);
357361

358362
$this->itemMock->expects($this->once())
359363
->method('hasData')
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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\Quote\Model\Quote\Item;
9+
10+
use Magento\Quote\Api\CartItemRepositoryInterface;
11+
use Magento\Quote\Api\Data\CartItemInterface;
12+
use Magento\Quote\Model\Quote;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
/**
16+
* Tests \Magento\Quote\Model\Quote\Item\Updater
17+
*/
18+
class UpdaterTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var Updater
22+
*/
23+
private $updater;
24+
25+
/**
26+
* @var \Magento\Framework\ObjectManagerInterface
27+
*/
28+
private $objectManager;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
protected function setUp()
34+
{
35+
$this->objectManager = Bootstrap::getObjectManager();
36+
$this->updater = $this->objectManager->create(Updater::class);
37+
}
38+
39+
/**
40+
* @magentoDataFixture Magento/Sales/_files/quote_with_custom_price.php
41+
* @return void
42+
*/
43+
public function testUpdate(): void
44+
{
45+
/** @var CartItemRepositoryInterface $quoteItemRepository */
46+
$quoteItemRepository = $this->objectManager->create(CartItemRepositoryInterface::class);
47+
/** @var Quote $quote */
48+
$quote = $this->objectManager->create(Quote::class);
49+
$quoteId = $quote->load('test01', 'reserved_order_id')->getId();
50+
/** @var CartItemInterface[] $quoteItems */
51+
$quoteItems = $quoteItemRepository->getList($quoteId);
52+
/** @var CartItemInterface $actualQuoteItem */
53+
$actualQuoteItem = array_pop($quoteItems);
54+
$this->assertInstanceOf(CartItemInterface::class, $actualQuoteItem);
55+
56+
$this->updater->update($actualQuoteItem, ['qty' => 1]);
57+
58+
$this->assertNull(
59+
$actualQuoteItem->getCustomPrice(),
60+
'Item custom price has to be null'
61+
);
62+
}
63+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
include __DIR__ . '/quote.php';
9+
10+
$buyRequest = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
11+
\Magento\Framework\DataObject::class,
12+
[
13+
'data' => [
14+
'qty' => 1,
15+
'custom_price' => 12,
16+
],
17+
]
18+
);
19+
/** @var \Magento\Quote\Model\Quote $items */
20+
$items = $quote->getItemsCollection()->getItems();
21+
$quoteItem = reset($items);
22+
$quote->updateItem($quoteItem->getId(), $buyRequest)->save();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
include __DIR__ . '/quote_rollback.php';

0 commit comments

Comments
 (0)