@@ -93,27 +93,27 @@ public function apply()
93
93
public function fillQuoteAddressIdInSalesOrderAddress ()
94
94
{
95
95
$ addressCollection = $ this ->addressCollectionFactory ->create ();
96
+ $ addressCollection ->addFieldToFilter ('quote_address_id ' , ['null ' => true ]);
97
+
96
98
/** @var \Magento\Sales\Model\Order\Address $orderAddress */
97
99
foreach ($ addressCollection as $ orderAddress ) {
98
- if (!$ orderAddress ->getData ('quote_address_id ' )) {
99
- $ orderId = $ orderAddress ->getParentId ();
100
- $ addressType = $ orderAddress ->getAddressType ();
101
-
102
- /** @var \Magento\Sales\Model\Order $order */
103
- $ order = $ this ->orderFactory ->create ()->load ($ orderId );
104
- $ quoteId = $ order ->getQuoteId ();
105
- $ quote = $ this ->quoteFactory ->create ()->load ($ quoteId );
106
-
107
- if ($ addressType == \Magento \Sales \Model \Order \Address::TYPE_SHIPPING ) {
108
- $ quoteAddressId = $ quote ->getShippingAddress ()->getId ();
109
- $ orderAddress ->setData ('quote_address_id ' , $ quoteAddressId );
110
- } elseif ($ addressType == \Magento \Sales \Model \Order \Address::TYPE_BILLING ) {
111
- $ quoteAddressId = $ quote ->getBillingAddress ()->getId ();
112
- $ orderAddress ->setData ('quote_address_id ' , $ quoteAddressId );
113
- }
114
-
115
- $ orderAddress ->save ();
100
+ $ orderId = $ orderAddress ->getParentId ();
101
+ $ addressType = $ orderAddress ->getAddressType ();
102
+
103
+ /** @var \Magento\Sales\Model\Order $order */
104
+ $ order = $ this ->orderFactory ->create ()->load ($ orderId );
105
+ $ quoteId = $ order ->getQuoteId ();
106
+ $ quote = $ this ->quoteFactory ->create ()->load ($ quoteId );
107
+
108
+ if ($ addressType == \Magento \Sales \Model \Order \Address::TYPE_SHIPPING ) {
109
+ $ quoteAddressId = $ quote ->getShippingAddress ()->getId ();
110
+ $ orderAddress ->setData ('quote_address_id ' , $ quoteAddressId );
111
+ } elseif ($ addressType == \Magento \Sales \Model \Order \Address::TYPE_BILLING ) {
112
+ $ quoteAddressId = $ quote ->getBillingAddress ()->getId ();
113
+ $ orderAddress ->setData ('quote_address_id ' , $ quoteAddressId );
116
114
}
115
+
116
+ $ orderAddress ->save ();
117
117
}
118
118
}
119
119
0 commit comments