Skip to content

Commit 19c2ec7

Browse files
authored
Add field to filter to collection
Currently the setup upgrade is looping truth all order addresses and is the checking if the quote_address_id is empty. Changed this so that the collection contains only addresses where the quote_address_id is NULL.
1 parent aca8c0b commit 19c2ec7

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

app/code/Magento/Sales/Setup/UpgradeData.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,27 +177,27 @@ private function convertSerializedDataToJson($setupVersion, SalesSetup $salesSet
177177
public function fillQuoteAddressIdInSalesOrderAddress()
178178
{
179179
$addressCollection = $this->addressCollectionFactory->create();
180+
$addressCollection->addFieldToFilter('quote_address_id', ['null' => true]);
181+
180182
/** @var \Magento\Sales\Model\Order\Address $orderAddress */
181183
foreach ($addressCollection as $orderAddress) {
182-
if (!$orderAddress->getData('quote_address_id')) {
183-
$orderId = $orderAddress->getParentId();
184-
$addressType = $orderAddress->getAddressType();
185-
186-
/** @var \Magento\Sales\Model\Order $order */
187-
$order = $this->orderFactory->create()->load($orderId);
188-
$quoteId = $order->getQuoteId();
189-
$quote = $this->quoteFactory->create()->load($quoteId);
190-
191-
if ($addressType == \Magento\Sales\Model\Order\Address::TYPE_SHIPPING) {
192-
$quoteAddressId = $quote->getShippingAddress()->getId();
193-
$orderAddress->setData('quote_address_id', $quoteAddressId);
194-
} elseif ($addressType == \Magento\Sales\Model\Order\Address::TYPE_BILLING) {
195-
$quoteAddressId = $quote->getBillingAddress()->getId();
196-
$orderAddress->setData('quote_address_id', $quoteAddressId);
197-
}
198-
199-
$orderAddress->save();
184+
$orderId = $orderAddress->getParentId();
185+
$addressType = $orderAddress->getAddressType();
186+
187+
/** @var \Magento\Sales\Model\Order $order */
188+
$order = $this->orderFactory->create()->load($orderId);
189+
$quoteId = $order->getQuoteId();
190+
$quote = $this->quoteFactory->create()->load($quoteId);
191+
192+
if ($addressType == \Magento\Sales\Model\Order\Address::TYPE_SHIPPING) {
193+
$quoteAddressId = $quote->getShippingAddress()->getId();
194+
$orderAddress->setData('quote_address_id', $quoteAddressId);
195+
} elseif ($addressType == \Magento\Sales\Model\Order\Address::TYPE_BILLING) {
196+
$quoteAddressId = $quote->getBillingAddress()->getId();
197+
$orderAddress->setData('quote_address_id', $quoteAddressId);
200198
}
199+
200+
$orderAddress->save();
201201
}
202202
}
203203
}

0 commit comments

Comments
 (0)