Skip to content

Commit 31097f4

Browse files
author
Mariana Lashch
committed
Merge branch 'MAGETWO-70532' into forwardport-1411
-resolve merge conflict
2 parents e357480 + 7c6ecc3 commit 31097f4

File tree

11 files changed

+273
-554
lines changed

11 files changed

+273
-554
lines changed

app/code/Magento/Bundle/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@
143143
</argument>
144144
</arguments>
145145
</type>
146+
<type name="Magento\Sales\Model\Order\ProductOption">
147+
<arguments>
148+
<argument name="processorPool" xsi:type="array">
149+
<item name="bundle" xsi:type="object">Magento\Bundle\Model\ProductOptionProcessor</item>
150+
</argument>
151+
</arguments>
152+
</type>
146153
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
147154
<arguments>
148155
<argument name="excludeAdjustments" xsi:type="array">

app/code/Magento/Catalog/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,13 @@
602602
</argument>
603603
</arguments>
604604
</type>
605+
<type name="Magento\Sales\Model\Order\ProductOption">
606+
<arguments>
607+
<argument name="processorPool" xsi:type="array">
608+
<item name="custom_options" xsi:type="object">Magento\Catalog\Model\ProductOptionProcessor</item>
609+
</argument>
610+
</arguments>
611+
</type>
605612
<type name="Magento\Framework\Model\Entity\RepositoryFactory">
606613
<arguments>
607614
<argument name="entities" xsi:type="array">

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@
125125
</argument>
126126
</arguments>
127127
</type>
128+
<type name="Magento\Sales\Model\Order\ProductOption">
129+
<arguments>
130+
<argument name="processorPool" xsi:type="array">
131+
<item name="configurable" xsi:type="object">Magento\ConfigurableProduct\Model\ProductOptionProcessor</item>
132+
</argument>
133+
</arguments>
134+
</type>
128135
<virtualType name="ConfigurableFinalPriceResolver" type="Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver">
129136
<arguments>
130137
<argument name="priceResolver" xsi:type="object">Magento\ConfigurableProduct\Pricing\Price\FinalPriceResolver</argument>

app/code/Magento/Downloadable/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@
7777
</argument>
7878
</arguments>
7979
</type>
80+
<type name="Magento\Sales\Model\Order\ProductOption">
81+
<arguments>
82+
<argument name="processorPool" xsi:type="array">
83+
<item name="downloadable" xsi:type="object">Magento\Downloadable\Model\ProductOptionProcessor</item>
84+
</argument>
85+
</arguments>
86+
</type>
8087
<preference for="Magento\Downloadable\Api\LinkRepositoryInterface" type="Magento\Downloadable\Model\LinkRepository" />
8188
<preference for="Magento\Downloadable\Api\SampleRepositoryInterface" type="Magento\Downloadable\Model\SampleRepository" />
8289
<preference for="Magento\Downloadable\Api\Data\LinkInterface" type="Magento\Downloadable\Model\Link" />

app/code/Magento/Sales/Model/Order.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Sales\Api\Data\OrderInterface;
1414
use Magento\Sales\Api\Data\OrderStatusHistoryInterface;
1515
use Magento\Sales\Model\Order\Payment;
16+
use Magento\Sales\Model\Order\ProductOption;
1617
use Magento\Sales\Model\ResourceModel\Order\Address\Collection;
1718
use Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection as CreditmemoCollection;
1819
use Magento\Sales\Model\ResourceModel\Order\Invoice\Collection as InvoiceCollection;
@@ -279,6 +280,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
279280
*/
280281
private $localeResolver;
281282

283+
/**
284+
* @var ProductOption
285+
*/
286+
private $productOption;
287+
282288
/**
283289
* @param \Magento\Framework\Model\Context $context
284290
* @param \Magento\Framework\Registry $registry
@@ -308,6 +314,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
308314
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
309315
* @param array $data
310316
* @param ResolverInterface $localeResolver
317+
* @param ProductOption|null $productOption
311318
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
312319
*/
313320
public function __construct(
@@ -338,7 +345,8 @@ public function __construct(
338345
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
339346
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
340347
array $data = [],
341-
ResolverInterface $localeResolver = null
348+
ResolverInterface $localeResolver = null,
349+
ProductOption $productOption = null
342350
) {
343351
$this->_storeManager = $storeManager;
344352
$this->_orderConfig = $orderConfig;
@@ -361,6 +369,7 @@ public function __construct(
361369
$this->salesOrderCollectionFactory = $salesOrderCollectionFactory;
362370
$this->priceCurrency = $priceCurrency;
363371
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(ResolverInterface::class);
372+
$this->productOption = $productOption ?: ObjectManager::getInstance()->get(ProductOption::class);
364373

365374
parent::__construct(
366375
$context,
@@ -1347,6 +1356,7 @@ public function getItemsCollection($filterByTypes = [], $nonChildrenOnly = false
13471356
if ($this->getId()) {
13481357
foreach ($collection as $item) {
13491358
$item->setOrder($this);
1359+
$this->productOption->add($item);
13501360
}
13511361
}
13521362
return $collection;

app/code/Magento/Sales/Model/Order/ItemRepository.php

Lines changed: 21 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
namespace Magento\Sales\Model\Order;
88

9-
use Magento\Catalog\Api\Data\ProductOptionExtensionFactory;
10-
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
11-
use Magento\Catalog\Model\ProductOptionFactory;
129
use Magento\Catalog\Model\ProductOptionProcessorInterface;
10+
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1311
use Magento\Framework\Api\SearchCriteriaInterface;
1412
use Magento\Framework\DataObject;
1513
use Magento\Framework\DataObject\Factory as DataObjectFactory;
@@ -18,6 +16,7 @@
1816
use Magento\Sales\Api\Data\OrderItemInterface;
1917
use Magento\Sales\Api\Data\OrderItemSearchResultInterfaceFactory;
2018
use Magento\Sales\Api\OrderItemRepositoryInterface;
19+
use Magento\Sales\Model\Order\ProductOption;
2120
use Magento\Sales\Model\ResourceModel\Metadata;
2221

2322
/**
@@ -41,16 +40,6 @@ class ItemRepository implements OrderItemRepositoryInterface
4140
*/
4241
protected $searchResultFactory;
4342

44-
/**
45-
* @var ProductOptionFactory
46-
*/
47-
protected $productOptionFactory;
48-
49-
/**
50-
* @var ProductOptionExtensionFactory
51-
*/
52-
protected $extensionFactory;
53-
5443
/**
5544
* @var ProductOptionProcessorInterface[]
5645
*/
@@ -62,40 +51,41 @@ class ItemRepository implements OrderItemRepositoryInterface
6251
protected $registry = [];
6352

6453
/**
65-
* @var \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface
54+
* @var CollectionProcessorInterface
6655
*/
6756
private $collectionProcessor;
6857

6958
/**
70-
* ItemRepository constructor.
59+
* @var ProductOption
60+
*/
61+
private $productOption;
62+
63+
/**
7164
* @param DataObjectFactory $objectFactory
7265
* @param Metadata $metadata
7366
* @param OrderItemSearchResultInterfaceFactory $searchResultFactory
74-
* @param ProductOptionFactory $productOptionFactory
75-
* @param ProductOptionExtensionFactory $extensionFactory
67+
* @param CollectionProcessorInterface $collectionProcessor
68+
* @param ProductOption $productOption
7669
* @param array $processorPool
77-
* @param CollectionProcessorInterface|null $collectionProcessor
7870
*/
7971
public function __construct(
8072
DataObjectFactory $objectFactory,
8173
Metadata $metadata,
8274
OrderItemSearchResultInterfaceFactory $searchResultFactory,
83-
ProductOptionFactory $productOptionFactory,
84-
ProductOptionExtensionFactory $extensionFactory,
85-
array $processorPool = [],
86-
CollectionProcessorInterface $collectionProcessor = null
75+
CollectionProcessorInterface $collectionProcessor,
76+
ProductOption $productOption,
77+
array $processorPool = []
8778
) {
8879
$this->objectFactory = $objectFactory;
8980
$this->metadata = $metadata;
9081
$this->searchResultFactory = $searchResultFactory;
91-
$this->productOptionFactory = $productOptionFactory;
92-
$this->extensionFactory = $extensionFactory;
82+
$this->collectionProcessor = $collectionProcessor;
83+
$this->productOption = $productOption;
9384
$this->processorPool = $processorPool;
94-
$this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
9585
}
9686

9787
/**
98-
* Load entity
88+
* Loads entity.
9989
*
10090
* @param int $id
10191
* @return OrderItemInterface
@@ -116,7 +106,7 @@ public function get($id)
116106
);
117107
}
118108

119-
$this->addProductOption($orderItem);
109+
$this->productOption->add($orderItem);
120110
$this->addParentItem($orderItem);
121111
$this->registry[$id] = $orderItem;
122112
}
@@ -137,7 +127,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
137127
$this->collectionProcessor->process($searchCriteria, $searchResult);
138128
/** @var OrderItemInterface $orderItem */
139129
foreach ($searchResult->getItems() as $orderItem) {
140-
$this->addProductOption($orderItem);
130+
$this->productOption->add($orderItem);
141131
}
142132

143133
return $searchResult;
@@ -178,45 +168,16 @@ public function save(OrderItemInterface $entity)
178168
{
179169
if ($entity->getProductOption()) {
180170
$request = $this->getBuyRequest($entity);
181-
$entity->setProductOptions(['info_buyRequest' => $request->toArray()]);
171+
$productOptions = $entity->getProductOptions();
172+
$productOptions['info_buyRequest'] = $request->toArray();
173+
$entity->setProductOptions($productOptions);
182174
}
183175

184176
$this->metadata->getMapper()->save($entity);
185177
$this->registry[$entity->getEntityId()] = $entity;
186178
return $this->registry[$entity->getEntityId()];
187179
}
188180

189-
/**
190-
* Add product option data
191-
*
192-
* @param OrderItemInterface $orderItem
193-
* @return $this
194-
*/
195-
protected function addProductOption(OrderItemInterface $orderItem)
196-
{
197-
/** @var DataObject $request */
198-
$request = $orderItem->getBuyRequest();
199-
200-
$productType = $orderItem->getProductType();
201-
if (isset($this->processorPool[$productType])
202-
&& !$orderItem->getParentItemId()) {
203-
$data = $this->processorPool[$productType]->convertToProductOption($request);
204-
if ($data) {
205-
$this->setProductOption($orderItem, $data);
206-
}
207-
}
208-
209-
if (isset($this->processorPool['custom_options'])
210-
&& !$orderItem->getParentItemId()) {
211-
$data = $this->processorPool['custom_options']->convertToProductOption($request);
212-
if ($data) {
213-
$this->setProductOption($orderItem, $data);
214-
}
215-
}
216-
217-
return $this;
218-
}
219-
220181
/**
221182
* Set parent item.
222183
*
@@ -239,32 +200,6 @@ private function addParentItem(OrderItemInterface $orderItem)
239200
}
240201
}
241202

242-
/**
243-
* Set product options data
244-
*
245-
* @param OrderItemInterface $orderItem
246-
* @param array $data
247-
* @return $this
248-
*/
249-
protected function setProductOption(OrderItemInterface $orderItem, array $data)
250-
{
251-
$productOption = $orderItem->getProductOption();
252-
if (!$productOption) {
253-
$productOption = $this->productOptionFactory->create();
254-
$orderItem->setProductOption($productOption);
255-
}
256-
257-
$extensionAttributes = $productOption->getExtensionAttributes();
258-
if (!$extensionAttributes) {
259-
$extensionAttributes = $this->extensionFactory->create();
260-
$productOption->setExtensionAttributes($extensionAttributes);
261-
}
262-
263-
$extensionAttributes->setData(key($data), current($data));
264-
265-
return $this;
266-
}
267-
268203
/**
269204
* Retrieve order item's buy request
270205
*
@@ -296,20 +231,4 @@ protected function getBuyRequest(OrderItemInterface $entity)
296231

297232
return $request;
298233
}
299-
300-
/**
301-
* Retrieve collection processor
302-
*
303-
* @deprecated 100.2.0
304-
* @return CollectionProcessorInterface
305-
*/
306-
private function getCollectionProcessor()
307-
{
308-
if (!$this->collectionProcessor) {
309-
$this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get(
310-
\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class
311-
);
312-
}
313-
return $this->collectionProcessor;
314-
}
315234
}

0 commit comments

Comments
 (0)