Skip to content

Commit 5a7c5e4

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-70743' into pr-regression-ece
2 parents 1464e5a + 7e822e1 commit 5a7c5e4

File tree

6 files changed

+155
-25
lines changed

6 files changed

+155
-25
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function getCartItemProcessors()
4242
return $this->cartItemProcessors;
4343
}
4444

45-
$arguments = $this->objectManagerConfig->getArguments(\Magento\Quote\Model\Quote\Item\Repository::class);
45+
$typePreference = $this->objectManagerConfig->getPreference(Repository::class);
46+
$arguments = $this->objectManagerConfig->getArguments($typePreference);
4647
if (isset($arguments['cartItemProcessors'])) {
4748
// Workaround for compiled mode.
4849
$processors = isset($arguments['cartItemProcessors']['_vac_'])

dev/tests/api-functional/testsuite/Magento/Quote/Api/CartItemRepositoryTest.php

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
namespace Magento\Quote\Api;
88

9+
use Magento\Catalog\Model\CustomOptions\CustomOptionProcessor;
10+
use Magento\Framework\Webapi\Rest\Request;
11+
use Magento\Quote\Model\Quote;
912
use Magento\TestFramework\TestCase\WebapiAbstract;
1013

1114
class CartItemRepositoryTest extends WebapiAbstract
@@ -25,33 +28,43 @@ protected function setUp()
2528
}
2629

2730
/**
28-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
31+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_and_custom_options_saved.php
2932
*/
3033
public function testGetList()
3134
{
32-
/** @var \Magento\Quote\Model\Quote $quote */
33-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
34-
$quote->load('test_order_item_with_items', 'reserved_order_id');
35+
/** @var Quote $quote */
36+
$quote = $this->objectManager->create(Quote::class);
37+
$quote->load('test_order_item_with_items_and_custom_options', 'reserved_order_id');
3538
$cartId = $quote->getId();
3639
$output = [];
40+
$customOptionProcessor = $this->objectManager->get(CustomOptionProcessor::class);
41+
3742
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
3843
foreach ($quote->getAllItems() as $item) {
44+
$customOptionProcessor->processOptions($item);
3945
$data = [
40-
'item_id' => $item->getItemId(),
46+
'item_id' => (int)$item->getItemId(),
4147
'sku' => $item->getSku(),
4248
'name' => $item->getName(),
43-
'price' => $item->getPrice(),
44-
'qty' => $item->getQty(),
49+
'price' => (float)$item->getPrice(),
50+
'qty' => (float)$item->getQty(),
4551
'product_type' => $item->getProductType(),
46-
'quote_id' => $item->getQuoteId()
52+
'quote_id' => $item->getQuoteId(),
4753
];
4854

55+
if ($item->getProductOption() !== null) {
56+
$customOptions = $item->getProductOption()->getExtensionAttributes()->getCustomOptions();
57+
foreach ($customOptions as $option) {
58+
$data['product_option']['extension_attributes']['custom_options'][] = $option->getData();
59+
}
60+
}
61+
4962
$output[] = $data;
5063
}
5164
$serviceInfo = [
5265
'rest' => [
5366
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items',
54-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
67+
'httpMethod' => Request::HTTP_METHOD_GET,
5568
],
5669
'soap' => [
5770
'service' => self::SERVICE_NAME,
@@ -73,14 +86,14 @@ public function testAddItem()
7386
/** @var \Magento\Catalog\Model\Product $product */
7487
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load(2);
7588
$productSku = $product->getSku();
76-
/** @var \Magento\Quote\Model\Quote $quote */
77-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
89+
/** @var Quote $quote */
90+
$quote = $this->objectManager->create(Quote::class);
7891
$quote->load('test_order_1', 'reserved_order_id');
7992
$cartId = $quote->getId();
8093
$serviceInfo = [
8194
'rest' => [
8295
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items',
83-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
96+
'httpMethod' => Request::HTTP_METHOD_POST,
8497
],
8598
'soap' => [
8699
'service' => self::SERVICE_NAME,
@@ -106,8 +119,8 @@ public function testAddItem()
106119
*/
107120
public function testRemoveItem()
108121
{
109-
/** @var \Magento\Quote\Model\Quote $quote */
110-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
122+
/** @var Quote $quote */
123+
$quote = $this->objectManager->create(Quote::class);
111124
$quote->load('test_order_item_with_items', 'reserved_order_id');
112125
$cartId = $quote->getId();
113126
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
@@ -117,7 +130,7 @@ public function testRemoveItem()
117130
$serviceInfo = [
118131
'rest' => [
119132
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items/' . $itemId,
120-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
133+
'httpMethod' => Request::HTTP_METHOD_DELETE,
121134
],
122135
'soap' => [
123136
'service' => self::SERVICE_NAME,
@@ -131,7 +144,7 @@ public function testRemoveItem()
131144
"itemId" => $itemId,
132145
];
133146
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
134-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
147+
$quote = $this->objectManager->create(Quote::class);
135148
$quote->load('test_order_item_with_items', 'reserved_order_id');
136149
$this->assertFalse($quote->hasProductId($productId));
137150
}
@@ -141,8 +154,8 @@ public function testRemoveItem()
141154
*/
142155
public function testUpdateItem()
143156
{
144-
/** @var \Magento\Quote\Model\Quote $quote */
145-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
157+
/** @var Quote $quote */
158+
$quote = $this->objectManager->create(Quote::class);
146159
$quote->load('test_order_item_with_items', 'reserved_order_id');
147160
$cartId = $quote->getId();
148161
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
@@ -152,7 +165,7 @@ public function testUpdateItem()
152165
$serviceInfo = [
153166
'rest' => [
154167
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items/' . $itemId,
155-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
168+
'httpMethod' => Request::HTTP_METHOD_PUT,
156169
],
157170
'soap' => [
158171
'service' => self::SERVICE_NAME,
@@ -178,7 +191,7 @@ public function testUpdateItem()
178191
];
179192
}
180193
$this->_webApiCall($serviceInfo, $requestData);
181-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
194+
$quote = $this->objectManager->create(Quote::class);
182195
$quote->load('test_order_item_with_items', 'reserved_order_id');
183196
$this->assertTrue($quote->hasProductId(1));
184197
$item = $quote->getItemByProduct($product);

dev/tests/integration/testsuite/Magento/Catalog/_files/product_with_options.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
true
3636
)->setStockData(
3737
[
38-
'qty' => 0,
39-
'is_in_stock' => 0
38+
'qty' => 100,
39+
'is_in_stock' => 1
4040
]
41-
);
41+
)->setHasOptions(true);
4242

4343
$options = [
4444
[
@@ -204,4 +204,8 @@
204204
$customOptions[] = $customOption;
205205
}
206206

207-
$product->setOptions($customOptions)->save();
207+
$product->setOptions($customOptions);
208+
209+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepositoryFactory */
210+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
211+
$productRepository->save($product);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\_files;
7+
8+
use Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile;
9+
10+
/**
11+
* Creates mock for ValidatorFile to replace real instance in fixtures.
12+
*/
13+
class ValidatorFileMock extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* Returns mock.
17+
*
18+
* @return ValidatorFile|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
public function getInstance()
21+
{
22+
$userValue = [
23+
'type' => 'image/jpeg',
24+
'title' => "test.jpg",
25+
'quote_path' => "custom_options/quote/s/t/4624d2.jpg",
26+
'order_path' => "custom_options/order/s/t/89d25b4624d2.jpg",
27+
"fullpath" => "pub/media/custom_options/quote/s/t/e47389d25b4624d2.jpg",
28+
"size"=> "71901",
29+
"width" => 5,
30+
"height" => 5,
31+
"secret_key" => "10839ec1631b77e5e473",
32+
];
33+
$instance = $this->getMockBuilder(ValidatorFile::class)
34+
->disableOriginalConstructor()
35+
->getMock();
36+
$instance->method('SetProduct')->willReturnSelf();
37+
$instance->method('validate')->willReturn($userValue);
38+
39+
return $instance;
40+
}
41+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Checkout\_files\ValidatorFileMock;
8+
9+
require __DIR__ . '/../../Checkout/_files/quote_with_address.php';
10+
require __DIR__ . '/../../Catalog/_files/product_with_options.php';
11+
require __DIR__ . '/../../Checkout/_files/ValidatorFileMock.php';
12+
13+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
14+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
15+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
16+
$product = $productRepository->get('simple');
17+
18+
$options = [];
19+
/** @var $option \Magento\Catalog\Model\Product\Option */
20+
foreach ($product->getOptions() as $option) {
21+
switch ($option->getGroupByType()) {
22+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE:
23+
$value = ['year' => 2013, 'month' => 8, 'day' => 9, 'hour' => 13, 'minute' => 35];
24+
break;
25+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
26+
$value = key($option->getValues());
27+
break;
28+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_FILE:
29+
$value = 'test.jpg';
30+
break;
31+
default:
32+
$value = 'test';
33+
break;
34+
}
35+
$options[$option->getId()] = $value;
36+
}
37+
38+
$requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'options' => $options]);
39+
$validatorFile = (new ValidatorFileMock())->getInstance();
40+
$objectManager->addSharedInstance($validatorFile, \Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile::class);
41+
42+
43+
$quote->setReservedOrderId('test_order_item_with_items_and_custom_options');
44+
$quote->addProduct($product, $requestInfo);
45+
$quote->collectTotals();
46+
$objectManager->get(\Magento\Quote\Model\QuoteRepository::class)->save($quote);
47+
48+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
49+
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
50+
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
51+
->create();
52+
$quoteIdMask->setQuoteId($quote->getId());
53+
$quoteIdMask->setDataChanges(true);
54+
$quoteIdMask->save();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
7+
$objectManager->removeSharedInstance(\Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile::class);
8+
9+
/** @var \Magento\Quote\Model\Quote $quote */
10+
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
11+
$quote->load('test_order_item_with_items_and_custom_options', 'reserved_order_id');
12+
$quoteId = $quote->getId();
13+
if ($quote->getId()) {
14+
$objectManager->get(\Magento\Quote\Model\QuoteRepository::class)->delete($quote);
15+
}
16+
17+
require __DIR__ . '/../../Checkout/_files/quote_with_address_rollback.php';

0 commit comments

Comments
 (0)