Skip to content

Commit

Permalink
PSPAYPAL-815 add PSPAYPAL-866 to this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
René Gust committed Dec 5, 2024
1 parent 6176a2f commit 206dda0
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions src/Core/PatchRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 206dda0

Please sign in to comment.