Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit d3dcc9d

Browse files
authored
Merge pull request #3458 from magento-tsg-csl3/2.2-develop-pr10
[TSG-CSL3] For 2.2 (pr10)
2 parents d14510f + 4c761a5 commit d3dcc9d

File tree

29 files changed

+631
-692
lines changed

29 files changed

+631
-692
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
140140
</argument>
141141
</arguments>
142142
</type>
143+
<type name="Magento\Sales\Model\Order\ProductOption">
144+
<arguments>
145+
<argument name="processorPool" xsi:type="array">
146+
<item name="bundle" xsi:type="object">Magento\Bundle\Model\ProductOptionProcessor</item>
147+
</argument>
148+
</arguments>
149+
</type>
143150
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
144151
<arguments>
145152
<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
@@ -600,6 +600,13 @@
600600
</argument>
601601
</arguments>
602602
</type>
603+
<type name="Magento\Sales\Model\Order\ProductOption">
604+
<arguments>
605+
<argument name="processorPool" xsi:type="array">
606+
<item name="custom_options" xsi:type="object">Magento\Catalog\Model\ProductOptionProcessor</item>
607+
</argument>
608+
</arguments>
609+
</type>
603610
<type name="Magento\Framework\Model\Entity\RepositoryFactory">
604611
<arguments>
605612
<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
@@ -14,6 +14,7 @@
1414
use Magento\Sales\Api\Data\OrderInterface;
1515
use Magento\Sales\Api\Data\OrderStatusHistoryInterface;
1616
use Magento\Sales\Model\Order\Payment;
17+
use Magento\Sales\Model\Order\ProductOption;
1718
use Magento\Sales\Model\ResourceModel\Order\Address\Collection;
1819
use Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection as CreditmemoCollection;
1920
use Magento\Sales\Model\ResourceModel\Order\Invoice\Collection as InvoiceCollection;
@@ -275,6 +276,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
275276
*/
276277
private $localeResolver;
277278

279+
/**
280+
* @var ProductOption
281+
*/
282+
private $productOption;
283+
278284
/**
279285
* @param \Magento\Framework\Model\Context $context
280286
* @param \Magento\Framework\Registry $registry
@@ -304,6 +310,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
304310
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
305311
* @param array $data
306312
* @param ResolverInterface $localeResolver
313+
* @param ProductOption|null $productOption
307314
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
308315
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
309316
*/
@@ -335,7 +342,8 @@ public function __construct(
335342
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
336343
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
337344
array $data = [],
338-
ResolverInterface $localeResolver = null
345+
ResolverInterface $localeResolver = null,
346+
ProductOption $productOption = null
339347
) {
340348
$this->_storeManager = $storeManager;
341349
$this->_orderConfig = $orderConfig;
@@ -357,6 +365,7 @@ public function __construct(
357365
$this->salesOrderCollectionFactory = $salesOrderCollectionFactory;
358366
$this->priceCurrency = $priceCurrency;
359367
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(ResolverInterface::class);
368+
$this->productOption = $productOption ?: ObjectManager::getInstance()->get(ProductOption::class);
360369

361370
parent::__construct(
362371
$context,
@@ -1356,6 +1365,7 @@ public function getItemsCollection($filterByTypes = [], $nonChildrenOnly = false
13561365
if ($this->getId()) {
13571366
foreach ($collection as $item) {
13581367
$item->setOrder($this);
1368+
$this->productOption->add($item);
13591369
}
13601370
}
13611371
return $collection;

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

Lines changed: 20 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
namespace Magento\Sales\Model\Order;
77

8-
use Magento\Catalog\Api\Data\ProductOptionExtensionFactory;
98
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
10-
use Magento\Catalog\Model\ProductOptionFactory;
119
use Magento\Catalog\Model\ProductOptionProcessorInterface;
1210
use Magento\Framework\Api\SearchCriteriaInterface;
1311
use Magento\Framework\DataObject;
@@ -17,6 +15,7 @@
1715
use Magento\Sales\Api\Data\OrderItemInterface;
1816
use Magento\Sales\Api\Data\OrderItemSearchResultInterfaceFactory;
1917
use Magento\Sales\Api\OrderItemRepositoryInterface;
18+
use Magento\Sales\Model\Order\ProductOption;
2019
use Magento\Sales\Model\ResourceModel\Metadata;
2120

2221
/**
@@ -40,16 +39,6 @@ class ItemRepository implements OrderItemRepositoryInterface
4039
*/
4140
protected $searchResultFactory;
4241

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

6352
/**
64-
* @var \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface
53+
* @var CollectionProcessorInterface
6554
*/
6655
private $collectionProcessor;
6756

6857
/**
69-
* ItemRepository constructor.
58+
* @var ProductOption
59+
*/
60+
private $productOption;
61+
62+
/**
7063
* @param DataObjectFactory $objectFactory
7164
* @param Metadata $metadata
7265
* @param OrderItemSearchResultInterfaceFactory $searchResultFactory
73-
* @param ProductOptionFactory $productOptionFactory
74-
* @param ProductOptionExtensionFactory $extensionFactory
66+
* @param CollectionProcessorInterface $collectionProcessor
67+
* @param ProductOption $productOption
7568
* @param array $processorPool
76-
* @param CollectionProcessorInterface|null $collectionProcessor
7769
*/
7870
public function __construct(
7971
DataObjectFactory $objectFactory,
8072
Metadata $metadata,
8173
OrderItemSearchResultInterfaceFactory $searchResultFactory,
82-
ProductOptionFactory $productOptionFactory,
83-
ProductOptionExtensionFactory $extensionFactory,
84-
array $processorPool = [],
85-
CollectionProcessorInterface $collectionProcessor = null
74+
CollectionProcessorInterface $collectionProcessor,
75+
ProductOption $productOption,
76+
array $processorPool = []
8677
) {
8778
$this->objectFactory = $objectFactory;
8879
$this->metadata = $metadata;
8980
$this->searchResultFactory = $searchResultFactory;
90-
$this->productOptionFactory = $productOptionFactory;
91-
$this->extensionFactory = $extensionFactory;
81+
$this->collectionProcessor = $collectionProcessor;
82+
$this->productOption = $productOption;
9283
$this->processorPool = $processorPool;
93-
$this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
9484
}
9585

9686
/**
97-
* load entity
87+
* Loads entity.
9888
*
9989
* @param int $id
10090
* @return OrderItemInterface
@@ -113,7 +103,7 @@ public function get($id)
113103
throw new NoSuchEntityException(__('Requested entity doesn\'t exist'));
114104
}
115105

116-
$this->addProductOption($orderItem);
106+
$this->productOption->add($orderItem);
117107
$this->addParentItem($orderItem);
118108
$this->registry[$id] = $orderItem;
119109
}
@@ -134,7 +124,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
134124
$this->collectionProcessor->process($searchCriteria, $searchResult);
135125
/** @var OrderItemInterface $orderItem */
136126
foreach ($searchResult->getItems() as $orderItem) {
137-
$this->addProductOption($orderItem);
127+
$this->productOption->add($orderItem);
138128
}
139129

140130
return $searchResult;
@@ -175,45 +165,16 @@ public function save(OrderItemInterface $entity)
175165
{
176166
if ($entity->getProductOption()) {
177167
$request = $this->getBuyRequest($entity);
178-
$entity->setProductOptions(['info_buyRequest' => $request->toArray()]);
168+
$productOptions = $entity->getProductOptions();
169+
$productOptions['info_buyRequest'] = $request->toArray();
170+
$entity->setProductOptions($productOptions);
179171
}
180172

181173
$this->metadata->getMapper()->save($entity);
182174
$this->registry[$entity->getEntityId()] = $entity;
183175
return $this->registry[$entity->getEntityId()];
184176
}
185177

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

231-
/**
232-
* Set product options data
233-
*
234-
* @param OrderItemInterface $orderItem
235-
* @param array $data
236-
* @return $this
237-
*/
238-
protected function setProductOption(OrderItemInterface $orderItem, array $data)
239-
{
240-
$productOption = $orderItem->getProductOption();
241-
if (!$productOption) {
242-
$productOption = $this->productOptionFactory->create();
243-
$orderItem->setProductOption($productOption);
244-
}
245-
246-
$extensionAttributes = $productOption->getExtensionAttributes();
247-
if (!$extensionAttributes) {
248-
$extensionAttributes = $this->extensionFactory->create();
249-
$productOption->setExtensionAttributes($extensionAttributes);
250-
}
251-
252-
$extensionAttributes->setData(key($data), current($data));
253-
254-
return $this;
255-
}
256-
257192
/**
258193
* Retrieve order item's buy request
259194
*
@@ -285,20 +220,4 @@ protected function getBuyRequest(OrderItemInterface $entity)
285220

286221
return $request;
287222
}
288-
289-
/**
290-
* Retrieve collection processor
291-
*
292-
* @deprecated 100.2.0
293-
* @return CollectionProcessorInterface
294-
*/
295-
private function getCollectionProcessor()
296-
{
297-
if (!$this->collectionProcessor) {
298-
$this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get(
299-
\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class
300-
);
301-
}
302-
return $this->collectionProcessor;
303-
}
304223
}

0 commit comments

Comments
 (0)