10
10
use Magento \Sales \Model \Order \ShippingAssignmentBuilder ;
11
11
use Magento \Sales \Api \Data \OrderSearchResultInterfaceFactory as SearchResultFactory ;
12
12
use Magento \Sales \Api \Data \OrderExtensionInterface ;
13
- use Magento \Sales \Api \Data \OrderExtension ;
13
+ use Magento \Sales \Api \Data \OrderExtensionFactory ;
14
14
use Magento \Sales \Api \Data \OrderInterface ;
15
15
use Magento \Sales \Api \Data \ShippingAssignmentInterface ;
16
16
use Magento \Framework \Exception \NoSuchEntityException ;
17
17
use Magento \Framework \Exception \InputException ;
18
18
use Magento \Framework \Api \SortOrder ;
19
- use Magento \Framework \App \ObjectManager ;
20
19
21
20
/**
22
21
* Repository class for @see OrderInterface
@@ -34,6 +33,16 @@ class OrderRepository implements \Magento\Sales\Api\OrderRepositoryInterface
34
33
*/
35
34
protected $ searchResultFactory = null ;
36
35
36
+ /**
37
+ * @var OrderExtensionFactory
38
+ */
39
+ private $ orderExtensionFactory ;
40
+
41
+ /**
42
+ * @var ShippingAssignmentBuilder
43
+ */
44
+ private $ shippingAssignmentBuilder ;
45
+
37
46
/**
38
47
* OrderInterface[]
39
48
*
@@ -164,7 +173,7 @@ private function setShippingAssignments(OrderInterface $order)
164
173
$ extensionAttributes = $ order ->getExtensionAttributes ();
165
174
166
175
if ($ extensionAttributes === null ) {
167
- $ extensionAttributes = $ this ->getOrderExtensionDependency ();
176
+ $ extensionAttributes = $ this ->getOrderExtensionDependencyFactory ()-> create ();
168
177
} elseif ($ extensionAttributes ->getShippingAssignments () !== null ) {
169
178
return ;
170
179
}
@@ -180,12 +189,14 @@ private function setShippingAssignments(OrderInterface $order)
180
189
* @return OrderExtension
181
190
* @deprecated
182
191
*/
183
- private function getOrderExtensionDependency ()
192
+ private function getOrderExtensionDependencyFactory ()
184
193
{
185
-
186
- return ObjectManager::getInstance ()->create (
187
- '\Magento\Sales\Api\Data\OrderExtension '
188
- );
194
+ if (!$ this ->orderExtensionFactory instanceof OrderExtensionFactory) {
195
+ $ this ->orderExtensionFactory = \Magento \Framework \App \ObjectManager::getInstance ()->get (
196
+ '\Magento\Sales\Api\Data\OrderExtensionFactory '
197
+ );
198
+ }
199
+ return $ this ->orderExtensionFactory ;
189
200
}
190
201
191
202
/**
@@ -196,9 +207,12 @@ private function getOrderExtensionDependency()
196
207
*/
197
208
private function getShippingAssignmentBuilderDependency ()
198
209
{
199
- return ObjectManager::getInstance ()->create (
200
- '\Magento\Sales\Model\Order\ShippingAssignmentBuilder '
201
- );
210
+ if (!$ this ->shippingAssignmentBuilder instanceof ShippingAssignmentBuilder) {
211
+ $ this ->shippingAssignmentBuilder = \Magento \Framework \App \ObjectManager::getInstance ()->get (
212
+ '\Magento\Sales\Model\Order\ShippingAssignmentBuilder '
213
+ );
214
+ }
215
+ return $ this ->shippingAssignmentBuilder ;
202
216
}
203
217
204
218
/**
0 commit comments