Skip to content

Commit a6b2172

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into 2.2-develop-pr11
2 parents 92d7ecf + d002aa8 commit a6b2172

File tree

9 files changed

+140
-28
lines changed

9 files changed

+140
-28
lines changed

app/code/Magento/Bundle/Test/Unit/Pricing/Price/TierPriceTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,28 @@ public function providerForGetterTierPriceList()
180180
/**
181181
* @dataProvider providerForTestGetSavePercent
182182
*/
183-
public function testGetSavePercent($baseAmount, $savePercent)
183+
public function testGetSavePercent($baseAmount, $tierPrice, $savePercent)
184184
{
185-
$basePrice = 10.;
185+
/** @var \Magento\Framework\Pricing\Amount\AmountInterface|\PHPUnit_Framework_MockObject_MockObject $amount */
186186
$amount = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Amount\AmountInterface::class);
187-
$amount->expects($this->once())->method('getBaseAmount')->willReturn($baseAmount);
187+
$amount->expects($this->any())
188+
->method('getValue')
189+
->will($this->returnValue($tierPrice));
190+
191+
$priceAmount = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Amount\AmountInterface::class);
192+
$priceAmount->expects($this->any())
193+
->method('getValue')
194+
->will($this->returnValue($baseAmount));
195+
188196
$price = $this->createMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
189197
$price->expects($this->any())
190-
->method('getValue')
191-
->will($this->returnValue($basePrice));
198+
->method('getAmount')
199+
->will($this->returnValue($priceAmount));
192200

193201
$this->priceInfo->expects($this->any())
194202
->method('getPrice')
195203
->will($this->returnValue($price));
204+
196205
$this->assertEquals($savePercent, $this->model->getSavePercent($amount));
197206
}
198207

@@ -202,8 +211,8 @@ public function testGetSavePercent($baseAmount, $savePercent)
202211
public function providerForTestGetSavePercent()
203212
{
204213
return [
205-
'no fraction' => [9.0000, 10],
206-
'lower half' => [9.1234, 9],
214+
'no fraction' => [9.0000, 8.1, 10],
215+
'lower half' => [9.1234, 8.3, 9],
207216
];
208217
}
209218
}

app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public function __construct(
168168
*/
169169
protected function parseSelections($rowData, $entityId)
170170
{
171+
if (empty($rowData['bundle_values'])) {
172+
return [];
173+
}
174+
171175
$rowData['bundle_values'] = str_replace(
172176
self::BEFORE_OPTION_VALUE_DELIMITER,
173177
$this->_entityModel->getMultipleValueSeparator(),

app/code/Magento/BundleImportExport/Test/Unit/Model/Import/Product/Type/BundleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ public function saveDataProvider()
294294
'bunch' => ['bundle_values' => 'value1', 'sku' => 'sku', 'name' => 'name'],
295295
'allowImport' => false
296296
],
297+
'Import without bundle values' => [
298+
'skus' => ['newSku' => ['sku' => ['sku' => 'sku', 'entity_id' => 3, 'type_id' => 'bundle']]],
299+
'bunch' => ['sku' => 'sku', 'name' => 'name'],
300+
'allowImport' => true,
301+
],
297302
[
298303
'skus' => ['newSku' => [
299304
'sku' => ['sku' => 'sku', 'entity_id' => 3, 'type_id' => 'bundle'],

app/code/Magento/Catalog/Pricing/Price/TierPrice.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,21 @@ protected function getBasePrice()
215215
}
216216

217217
/**
218+
* Calculates savings percentage according to the given tier price amount
219+
* and related product price amount.
220+
*
218221
* @param AmountInterface $amount
222+
*
219223
* @return float
220224
*/
221225
public function getSavePercent(AmountInterface $amount)
222226
{
227+
$productPriceAmount = $this->priceInfo->getPrice(
228+
FinalPrice::PRICE_CODE
229+
)->getAmount();
230+
223231
return round(
224-
100 - ((100 / $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)->getValue())
225-
* $amount->getBaseAmount())
232+
100 - ((100 / $productPriceAmount->getValue()) * $amount->getValue())
226233
);
227234
}
228235

app/code/Magento/Catalog/Test/Unit/Pricing/Price/TierPriceTest.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use Magento\Catalog\Pricing\Price\TierPrice;
1212
use Magento\Catalog\Pricing\Price\FinalPrice;
13+
use Magento\Framework\Pricing\Amount\AmountInterface;
14+
use Magento\Framework\Pricing\Price\PriceInterface;
1315
use Magento\Customer\Model\Group;
1416
use Magento\Customer\Model\GroupManagement;
1517

@@ -250,7 +252,7 @@ public function testGetterTierPriceList($tierPrices, $basePrice, $expectedResult
250252
{
251253
$this->product->setData(TierPrice::PRICE_CODE, $tierPrices);
252254

253-
$price = $this->createMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
255+
$price = $this->createMock(PriceInterface::class);
254256
$price->expects($this->any())->method('getValue')->will($this->returnValue($basePrice));
255257

256258
$this->calculator->expects($this->atLeastOnce())->method('getAmount')
@@ -341,27 +343,37 @@ public function providerForGetterTierPriceList()
341343
}
342344

343345
/**
344-
* @covers \Magento\Catalog\Pricing\Price\TierPrice::__construct
345-
* @covers \Magento\Catalog\Pricing\Price\TierPrice::getSavePercent
346-
* @covers \Magento\Catalog\Pricing\Price\TierPrice::getBasePrice
346+
* @param float $basePrice
347+
* @param float $tierPrice
348+
* @param float $savedPercent
349+
*
347350
* @dataProvider dataProviderGetSavePercent
348351
*/
349352
public function testGetSavePercent($basePrice, $tierPrice, $savedPercent)
350353
{
351-
$price = $this->createMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
354+
/** @var AmountInterface|\PHPUnit_Framework_MockObject_MockObject $amount */
355+
$amount = $this->getMockForAbstractClass(AmountInterface::class);
352356

353-
$this->priceInfo->expects(static::atLeastOnce())
354-
->method('getPrice')
355-
->with(FinalPrice::PRICE_CODE)
356-
->willReturn($price);
357-
$price->expects(static::atLeastOnce())
357+
$amount->expects($this->any())
358+
->method('getValue')
359+
->willReturn($tierPrice);
360+
361+
$basePriceAmount = $this->getMockForAbstractClass(AmountInterface::class);
362+
363+
$basePriceAmount->expects($this->any())
358364
->method('getValue')
359365
->willReturn($basePrice);
360366

361-
$amount = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Amount\AmountInterface::class);
362-
$amount->expects($this->atLeastOnce())
363-
->method('getBaseAmount')
364-
->will($this->returnValue($tierPrice));
367+
$price = $this->getMockForAbstractClass(PriceInterface::class);
368+
369+
$price->expects($this->any())
370+
->method('getAmount')
371+
->willReturn($basePriceAmount);
372+
373+
$this->priceInfo->expects($this->any())
374+
->method('getPrice')
375+
->with(FinalPrice::PRICE_CODE)
376+
->willReturn($price);
365377

366378
$this->assertEquals($savedPercent, $this->model->getSavePercent($amount));
367379
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,9 @@ public function addProduct(
16201620
$item = $this->getItemByProduct($candidate);
16211621
if (!$item) {
16221622
$item = $this->itemProcessor->init($candidate, $request);
1623+
$item->setQuote($this);
1624+
$item->setOptions($candidate->getCustomOptions());
1625+
$item->setProduct($candidate);
16231626
// Add only item that is not in quote already
16241627
$this->addItem($item);
16251628
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ public function init(Product $product, $request)
7171
return $item;
7272
}
7373

74-
$item->setOptions($product->getCustomOptions());
75-
$item->setProduct($product);
76-
7774
if ($request->getResetCount() && !$product->getStickWithinParent() && $item->getId() === $request->getId()) {
7875
$item->setData(CartItemInterface::KEY_QTY, 0);
7976
}

app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class QuoteTest extends \PHPUnit\Framework\TestCase
142142
*/
143143
private $customerDataFactoryMock;
144144

145+
/**
146+
* @var \PHPUnit_Framework_MockObject_MockObject
147+
*/
148+
private $itemProcessor;
149+
145150
/**
146151
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
147152
*/
@@ -223,7 +228,9 @@ protected function setUp()
223228
$this->filterBuilderMock = $this->getMockBuilder(\Magento\Framework\Api\FilterBuilder::class)
224229
->disableOriginalConstructor()
225230
->getMock();
226-
231+
$this->itemProcessor = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Processor::class)
232+
->disableOriginalConstructor()
233+
->getMock();
227234
$this->extensionAttributesJoinProcessorMock = $this->createMock(\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface::class);
228235
$this->customerDataFactoryMock = $this->createPartialMock(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class, ['create']);
229236
$this->quote = (new ObjectManager($this))
@@ -249,6 +256,7 @@ protected function setUp()
249256
'objectCopyService' => $this->objectCopyServiceMock,
250257
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock,
251258
'customerDataFactory' => $this->customerDataFactoryMock,
259+
'itemProcessor' => $this->itemProcessor,
252260
'data' => [
253261
'reserved_order_id' => 1000001
254262
]
@@ -853,6 +861,69 @@ public function testAddProductItemPreparation()
853861
$this->assertEquals($expectedResult, $result);
854862
}
855863

864+
public function testAddProductItemNew()
865+
{
866+
$itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
867+
868+
$expectedResult = $itemMock;
869+
$requestMock = $this->createMock(
870+
\Magento\Framework\DataObject::class
871+
);
872+
$this->objectFactoryMock->expects($this->once())
873+
->method('create')
874+
->with($this->equalTo(['qty' => 1]))
875+
->will($this->returnValue($requestMock));
876+
877+
$typeInstanceMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Type\Simple::class, [
878+
'prepareForCartAdvanced'
879+
]);
880+
881+
$productMock = $this->createPartialMock(\Magento\Catalog\Model\Product::class, [
882+
'getParentProductId',
883+
'setStickWithinParent',
884+
'__wakeup'
885+
]);
886+
887+
$collectionMock = $this->createMock(\Magento\Quote\Model\ResourceModel\Quote\Item\Collection::class);
888+
889+
$itemMock->expects($this->any())
890+
->method('representProduct')
891+
->will($this->returnValue(false));
892+
893+
$iterator = new \ArrayIterator([$itemMock]);
894+
$collectionMock->expects($this->any())
895+
->method('getIterator')
896+
->will($this->returnValue($iterator));
897+
898+
$this->quoteItemCollectionFactoryMock->expects($this->once())
899+
->method('create')
900+
->will($this->returnValue($collectionMock));
901+
902+
$this->productMock->expects($this->once())
903+
->method('isSalable')
904+
->willReturn(true);
905+
$this->itemProcessor
906+
->expects($this->once())
907+
->method('init')
908+
->willReturn($itemMock);
909+
$itemMock->expects($this->once())
910+
->method('setProduct');
911+
$itemMock->expects($this->once())
912+
->method('setOptions');
913+
$itemMock->expects($this->any())
914+
->method('setQuote')
915+
->with($this->quote);
916+
$typeInstanceMock->expects($this->once())
917+
->method('prepareForCartAdvanced')
918+
->will($this->returnValue([$productMock]));
919+
$this->productMock->expects($this->once())
920+
->method('getTypeInstance')
921+
->will($this->returnValue($typeInstanceMock));
922+
923+
$result = $this->quote->addProduct($this->productMock, null);
924+
$this->assertEquals($expectedResult, $result);
925+
}
926+
856927
public function testValidateMiniumumAmount()
857928
{
858929
$storeId = 1;

app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function _processActionData($action = null)
154154
$this->_eventManager->dispatch('adminhtml_sales_order_create_process_data_before', $eventData);
155155

156156
/**
157-
* Saving order data
157+
* Import post data, in order to make order quote valid
158158
*/
159159
if ($data = $this->getRequest()->getPost('order')) {
160160
$this->_getOrderCreateModel()->importPostData($data);
@@ -210,6 +210,8 @@ protected function _processActionData($action = null)
210210
$this->_getOrderCreateModel()->applySidebarData($data);
211211
}
212212

213+
$this->_eventManager->dispatch('adminhtml_sales_order_create_process_item_before', $eventData);
214+
213215
/**
214216
* Adding product to quote from shopping cart, wishlist etc.
215217
*/
@@ -256,6 +258,8 @@ protected function _processActionData($action = null)
256258
$this->_getOrderCreateModel()->moveQuoteItem($moveItemId, $moveTo, $moveQty);
257259
}
258260

261+
$this->_eventManager->dispatch('adminhtml_sales_order_create_process_item_after', $eventData);
262+
259263
if ($paymentData = $this->getRequest()->getPost('payment')) {
260264
$this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentData);
261265
}

0 commit comments

Comments
 (0)