@@ -616,14 +616,14 @@ public function returnFromPaypal($token)
616
616
617
617
$ this ->ignoreAddressValidation ();
618
618
619
+ $ isButton = $ quote ->getPayment ()->getAdditionalInformation (self ::PAYMENT_INFO_BUTTON ) == 1 ;
620
+
619
621
// import shipping address
620
622
$ exportedShippingAddress = $ this ->_getApi ()->getExportedShippingAddress ();
621
623
if (!$ quote ->getIsVirtual ()) {
622
624
$ shippingAddress = $ quote ->getShippingAddress ();
623
625
if ($ shippingAddress ) {
624
- if ($ exportedShippingAddress
625
- && $ quote ->getPayment ()->getAdditionalInformation (self ::PAYMENT_INFO_BUTTON ) == 1
626
- ) {
626
+ if ($ exportedShippingAddress && $ isButton ) {
627
627
$ this ->_setExportedAddressData ($ shippingAddress , $ exportedShippingAddress );
628
628
// PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix
629
629
$ shippingAddress ->setPrefix (null );
@@ -651,24 +651,29 @@ public function returnFromPaypal($token)
651
651
}
652
652
653
653
// import billing address
654
- $ portBillingFromShipping = $ quote ->getPayment ()->getAdditionalInformation (self ::PAYMENT_INFO_BUTTON ) == 1
655
- && $ this ->_config ->getValue (
654
+ $ requireBillingAddress = $ this ->_config ->getValue (
656
655
'requireBillingAddress '
657
- ) != \Magento \Paypal \Model \Config::REQUIRE_BILLING_ADDRESS_ALL
658
- && ! $ quote -> isVirtual ();
659
- if ($ portBillingFromShipping ) {
656
+ ) == \Magento \Paypal \Model \Config::REQUIRE_BILLING_ADDRESS_ALL ;
657
+
658
+ if ($ isButton && ! $ requireBillingAddress && ! $ quote -> isVirtual () ) {
660
659
$ billingAddress = clone $ shippingAddress ;
661
660
$ billingAddress ->unsAddressId ()->unsAddressType ()->setCustomerAddressId (null );
662
661
$ data = $ billingAddress ->getData ();
663
662
$ data ['save_in_address_book ' ] = 0 ;
664
663
$ quote ->getBillingAddress ()->addData ($ data );
665
664
$ quote ->getShippingAddress ()->setSameAsBilling (1 );
666
665
} else {
667
- $ billingAddress = $ quote ->getBillingAddress ();
666
+ $ billingAddress = $ quote ->getBillingAddress ()-> setCustomerAddressId ( null ) ;
668
667
}
669
668
$ exportedBillingAddress = $ this ->_getApi ()->getExportedBillingAddress ();
670
669
671
- $ this ->_setExportedAddressData ($ billingAddress , $ exportedBillingAddress );
670
+ // Since country is required field for billing and shipping address,
671
+ // we consider the address information to be empty if country is empty.
672
+ $ isEmptyAddress = ($ billingAddress ->getCountryId () === null );
673
+
674
+ if ($ requireBillingAddress || $ isEmptyAddress ) {
675
+ $ this ->_setExportedAddressData ($ billingAddress , $ exportedBillingAddress );
676
+ }
672
677
$ billingAddress ->setCustomerNote ($ exportedBillingAddress ->getData ('note ' ));
673
678
$ quote ->setBillingAddress ($ billingAddress );
674
679
$ quote ->setCheckoutMethod ($ this ->getCheckoutMethod ());
@@ -904,19 +909,6 @@ public function getCheckoutMethod()
904
909
*/
905
910
protected function _setExportedAddressData ($ address , $ exportedAddress )
906
911
{
907
- // Exported data is more priority if require billing address setting is yes
908
- $ requireBillingAddress = $ this ->_config ->getValue (
909
- 'requireBillingAddress '
910
- ) == \Magento \Paypal \Model \Config::REQUIRE_BILLING_ADDRESS_ALL ;
911
-
912
- // Since country is required field for billing and shipping address,
913
- // we consider the address information to be empty if country is empty.
914
- $ isEmptyAddress = ($ address ->getCountryId () === null );
915
-
916
- if (!$ requireBillingAddress && !$ isEmptyAddress ) {
917
- return ;
918
- }
919
-
920
912
foreach ($ exportedAddress ->getExportedKeys () as $ key ) {
921
913
$ data = $ exportedAddress ->getData ($ key );
922
914
if (!empty ($ data )) {
0 commit comments