Skip to content

Commit

Permalink
ENGCOM-2063: [FORWARDPORT #15097] Add field to filter to collection #…
Browse files Browse the repository at this point in the history
…15672

 - Merge Pull Request #15672 from dverkade/magento2:2.3-forwardport-15097
 - Merged commits:
   1. 5076e11
  • Loading branch information
magento-engcom-team committed Jun 20, 2018
2 parents e47b0d7 + 5076e11 commit 303f1f0
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ public function apply()
public function fillQuoteAddressIdInSalesOrderAddress()
{
$addressCollection = $this->addressCollectionFactory->create();
$addressCollection->addFieldToFilter('quote_address_id', ['null' => true]);

/** @var \Magento\Sales\Model\Order\Address $orderAddress */
foreach ($addressCollection as $orderAddress) {
if (!$orderAddress->getData('quote_address_id')) {
$orderId = $orderAddress->getParentId();
$addressType = $orderAddress->getAddressType();

/** @var \Magento\Sales\Model\Order $order */
$order = $this->orderFactory->create()->load($orderId);
$quoteId = $order->getQuoteId();
$quote = $this->quoteFactory->create()->load($quoteId);

if ($addressType == \Magento\Sales\Model\Order\Address::TYPE_SHIPPING) {
$quoteAddressId = $quote->getShippingAddress()->getId();
$orderAddress->setData('quote_address_id', $quoteAddressId);
} elseif ($addressType == \Magento\Sales\Model\Order\Address::TYPE_BILLING) {
$quoteAddressId = $quote->getBillingAddress()->getId();
$orderAddress->setData('quote_address_id', $quoteAddressId);
}

$orderAddress->save();
$orderId = $orderAddress->getParentId();
$addressType = $orderAddress->getAddressType();

/** @var \Magento\Sales\Model\Order $order */
$order = $this->orderFactory->create()->load($orderId);
$quoteId = $order->getQuoteId();
$quote = $this->quoteFactory->create()->load($quoteId);

if ($addressType == \Magento\Sales\Model\Order\Address::TYPE_SHIPPING) {
$quoteAddressId = $quote->getShippingAddress()->getId();
$orderAddress->setData('quote_address_id', $quoteAddressId);
} elseif ($addressType == \Magento\Sales\Model\Order\Address::TYPE_BILLING) {
$quoteAddressId = $quote->getBillingAddress()->getId();
$orderAddress->setData('quote_address_id', $quoteAddressId);
}

$orderAddress->save();
}
}

Expand Down

0 comments on commit 303f1f0

Please sign in to comment.