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
  • Loading branch information
Stanislav Idolov authored Jun 21, 2018
2 parents 51d838c + 303f1f0 commit 7a308a2
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 7a308a2

Please sign in to comment.