From 206dda08a84bf51ecf71dc4835d23b6455a24344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Gust?= Date: Thu, 5 Dec 2024 15:09:19 +0100 Subject: [PATCH] PSPAYPAL-815 add PSPAYPAL-866 to this branch --- src/Core/PatchRequestFactory.php | 47 ++++++++++++-------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/Core/PatchRequestFactory.php b/src/Core/PatchRequestFactory.php index 08e2707b5..3cabc96ea 100644 --- a/src/Core/PatchRequestFactory.php +++ b/src/Core/PatchRequestFactory.php @@ -68,49 +68,36 @@ public function getRequest( protected function getShippingAddressPatch(): void { - $addressObj = false; - $address = new AddressPortable(); - $session = Registry::getSession(); + $deliveryId = Registry::getSession()->getVariable("deladrid"); + $deliveryAddress = oxNew(Address::class); - $deliveryId = $session->getVariable("deladrid"); + if ($deliveryId && $deliveryAddress->load($deliveryId)) { + $patch = new Patch(); + $patch->op = Patch::OP_REPLACE; + $patch->path = "/purchase_units/@reference_id=='" + . Constants::PAYPAL_ORDER_REFERENCE_ID + . "'/shipping/address"; - if ($deliveryId) { - $deliveryAddress = oxNew(Address::class); - if ($deliveryAddress->load($deliveryId)) { - $addressObj = $deliveryAddress; - } - } else { - $user = $this->basket->getUser(); - if ($user) { - $addressObj = $user; - } - } + $address = new AddressPortable(); - if ($addressObj) { $state = oxNew(State::class); - $country = oxNew(Country::class); + $state->load($deliveryAddress->getFieldData('oxstateid')); - $state->load($addressObj->getFieldData('oxstateid')); - $country->load($addressObj->getFieldData('oxcountryid')); + $country = oxNew(Country::class); + $country->load($deliveryAddress->getFieldData('oxcountryid')); $addressLine = - $addressObj->getFieldData('oxstreet') . " " . $addressObj->getFieldData('oxstreetnr'); + $deliveryAddress->getFieldData('oxstreet') . " " . $deliveryAddress->getFieldData('oxstreetnr'); $address->address_line_1 = $addressLine; - $addinfoLine = $addressObj->getFieldData('oxcompany') . " " . - $addressObj->getFieldData('oxaddinfo'); + $addinfoLine = $deliveryAddress->getFieldData('oxcompany') . " " . + $deliveryAddress->getFieldData('oxaddinfo'); $address->address_line_2 = $addinfoLine; $address->admin_area_1 = $state->getFieldData('oxtitle'); - $address->admin_area_2 = $addressObj->getFieldData('oxcity'); + $address->admin_area_2 = $deliveryAddress->getFieldData('oxcity'); $address->country_code = $country->oxcountry__oxisoalpha2->value; - $address->postal_code = $addressObj->getFieldData('oxzip'); - - $patch = new Patch(); - $patch->op = Patch::OP_REPLACE; - $patch->path = "/purchase_units/@reference_id=='" - . Constants::PAYPAL_ORDER_REFERENCE_ID - . "'/shipping/address"; + $address->postal_code = $deliveryAddress->getFieldData('oxzip'); $patch->value = $address;