From 0194d4b8e07d8bf09d789ffd7e0dd568b71f57b2 Mon Sep 17 00:00:00 2001
From: Stanislav Idolov <sidolov@magento.com>
Date: Fri, 16 Sep 2016 11:22:53 +0300
Subject: [PATCH] MAGETWO-58136: [Github] Shipping and billing address are not
 set if order placed with payment action Sale #6438

---
 .../Sales/Model/Order/Invoice/Plugin/AddressUpdate.php       | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/app/code/Magento/Sales/Model/Order/Invoice/Plugin/AddressUpdate.php b/app/code/Magento/Sales/Model/Order/Invoice/Plugin/AddressUpdate.php
index 9efa4258763..9fe280f5521 100644
--- a/app/code/Magento/Sales/Model/Order/Invoice/Plugin/AddressUpdate.php
+++ b/app/code/Magento/Sales/Model/Order/Invoice/Plugin/AddressUpdate.php
@@ -33,6 +33,7 @@ class AddressUpdate
 
     /**
      * @param \Magento\Sales\Model\ResourceModel\Order\Handler\Address $subject
+     * @param \Magento\Sales\Model\ResourceModel\Order\Handler\Address $result
      * @param \Magento\Sales\Model\Order $order
      * @return void
      * @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -51,13 +52,13 @@ class AddressUpdate
             foreach ($order->getInvoiceCollection()->getItems() as $invoice) {
                 $invoiceAttributesForSave = [];
 
-                if (!$invoice->getBillingAddressId()) {
+                if (!$invoice->getBillingAddressId() && $billingAddress) {
                     $invoice->setBillingAddressId($billingAddress->getId());
                     $invoiceAttributesForSave[] = 'billing_address_id';
                     $orderInvoiceHasChanges = true;
                 }
 
-                if (!$invoice->getShippingAddressId()) {
+                if (!$invoice->getShippingAddressId() && $shippingAddress) {
                     $invoice->setShippingAddressId($shippingAddress->getId());
                     $invoiceAttributesForSave[] = 'shipping_address_id';
                     $orderInvoiceHasChanges = true;
-- 
GitLab