Skip to content

Commit c0ddb4d

Browse files
committed
#36636 - prevent ShippingAssignmentBuilder and ShippingBuilder from loading order when not needed.
1 parent 4a41ec4 commit c0ddb4d

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

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

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

8+
use Magento\Sales\Api\Data\OrderInterface;
89
use Magento\Sales\Api\Data\ShippingAssignmentInterface;
910
use Magento\Sales\Api\Data\ShippingAssignmentInterfaceFactory;
1011
use Magento\Sales\Model\OrderFactory;
@@ -31,9 +32,9 @@ class ShippingAssignmentBuilder
3132
private $shippingBuilderFactory;
3233

3334
/**
34-
* @var int|null
35+
* @var OrderInterface
3536
*/
36-
private $orderId = null;
37+
private $order;
3738

3839
/**
3940
* ShippingAssignment constructor.
@@ -58,15 +59,24 @@ public function __construct(
5859
*/
5960
public function setOrderId($orderId)
6061
{
61-
$this->orderId = $orderId;
62+
$this->order = $this->orderFactory->create()->load($orderId);
6263
}
6364

6465
/**
65-
* @return int|null
66+
* @param OrderInterface $order
67+
* @return void
68+
*/
69+
public function setOrder(OrderInterface $order)
70+
{
71+
$this->order = $order;
72+
}
73+
74+
/**
75+
* @return OrderInterface
6676
*/
67-
private function getOrderId()
77+
private function getOrder()
6878
{
69-
return $this->orderId;
79+
return $this->order;
7080
}
7181

7282
/**
@@ -75,13 +85,12 @@ private function getOrderId()
7585
public function create()
7686
{
7787
$shippingAssignments = null;
78-
if ($this->getOrderId()) {
79-
$order = $this->orderFactory->create()->load($this->getOrderId());
88+
if ($order = $this->getOrder()) {
8089
/** @var ShippingAssignmentInterface $shippingAssignment */
8190
$shippingAssignment = $this->shippingAssignmentFactory->create();
8291

8392
$shipping = $this->shippingBuilderFactory->create();
84-
$shipping->setOrderId($this->getOrderId());
93+
$shipping->setOrder($order);
8594
$shippingAssignment->setShipping($shipping->create());
8695
$shippingAssignment->setItems($order->getItems());
8796
$shippingAssignment->setStockId($order->getStockId());

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

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

8+
use Magento\Sales\Api\Data\OrderInterface;
89
use Magento\Sales\Api\Data\ShippingInterface;
910
use Magento\Sales\Api\Data\ShippingInterfaceFactory;
1011
use Magento\Sales\Api\Data\TotalInterface;
@@ -19,12 +20,7 @@
1920
class ShippingBuilder
2021
{
2122
/**
22-
* @var int|null
23-
*/
24-
private $orderId = null;
25-
26-
/**
27-
* @var Order
23+
* @var OrderInterface
2824
*/
2925
private $order;
3026

@@ -66,7 +62,16 @@ public function __construct(
6662
*/
6763
public function setOrderId($orderId)
6864
{
69-
$this->orderId = $orderId;
65+
$this->order = $this->orderFactory->create()->load($orderId);
66+
}
67+
68+
/**
69+
* @param OrderInterface $order
70+
* @return void
71+
*/
72+
public function setOrder(OrderInterface $order)
73+
{
74+
$this->order = $order;
7075
}
7176

7277
/**
@@ -75,30 +80,20 @@ public function setOrderId($orderId)
7580
public function create()
7681
{
7782
$shipping = null;
78-
if ($this->getOrderId()) {
79-
$this->order = $this->orderFactory->create()->load($this->getOrderId());
80-
if ($this->order->getEntityId()) {
81-
/** @var ShippingInterface $shipping */
82-
$shipping = $this->shippingFactory->create();
83-
$shippingAddress = $this->order->getShippingAddress();
84-
if ($shippingAddress) {
85-
$shipping->setAddress($shippingAddress);
86-
}
87-
$shipping->setMethod($this->order->getShippingMethod());
88-
$shipping->setTotal($this->getTotal());
83+
$order = $this->getOrder();
84+
if ($order && $order->getEntityId()) {
85+
/** @var ShippingInterface $shipping */
86+
$shipping = $this->shippingFactory->create();
87+
$shippingAddress = $order->getShippingAddress();
88+
if ($shippingAddress) {
89+
$shipping->setAddress($shippingAddress);
8990
}
91+
$shipping->setMethod($order->getShippingMethod());
92+
$shipping->setTotal($this->getTotal());
9093
}
9194
return $shipping;
9295
}
9396

94-
/**
95-
* @return int|null
96-
*/
97-
private function getOrderId()
98-
{
99-
return $this->orderId;
100-
}
101-
10297
/**
10398
* @return TotalInterface
10499
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ private function setShippingAssignments(OrderInterface $order)
302302
}
303303
/** @var ShippingAssignmentInterface $shippingAssignment */
304304
$shippingAssignments = $this->getShippingAssignmentBuilderDependency();
305-
$shippingAssignments->setOrderId($order->getEntityId());
305+
$shippingAssignments->setOrder($order);
306306
$extensionAttributes->setShippingAssignments($shippingAssignments->create());
307307
$order->setExtensionAttributes($extensionAttributes);
308308
}

0 commit comments

Comments
 (0)