Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error on streetname + streetNr splitting #56

Open
wants to merge 3 commits into
base: b-6.4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public function splitShipToStreetPayPalAddress($shipToStreet)
if (!empty($address[1]) && $address[2]) {
$address['street'] = $address[1];
$address['streetnr'] = $address[2];

return $address;
}

Expand All @@ -178,9 +177,20 @@ public function splitShipToStreetPayPalAddress($shipToStreet)
if (!empty($address[1]) && $address[2]) {
$address['street'] = $address[2];
$address['streetnr'] = $address[1];
return $address;
}

#D3 START FIX IF CUST USES "streetName.Nr"
// checking if street number is at the end but has no space in between streetName and streetNr
preg_match("/(.*?)\s*(\d*(?<=\d{1}).?$)/", $shipToStreet, $address);

// checking if street name and number was found
if (!empty($address[1]) && $address[2]) {
$address['street'] = $address[1];
$address['streetnr'] = $address[2];
return $address;
}
#D3 END

// it is not possible to resolve address, so assign it without any parsing
$address['street'] = $shipToStreet;
Expand Down
113 changes: 112 additions & 1 deletion Tests/Unit/Model/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function createPayPalAddress_splittingAddress_dataProvider()
$address["ress"][] = array("Street Name", "4a-5");
$address["ress"][] = array("Street Name 11", "4a-5");
$address["ress"][] = array("Street Name", "");
$address["ress"][] = array("bertoldstr.48", "");
$address["ress"][] = array("bertoldstr.", "48");
$address["ress"][] = array("Street Name", "4 a");

foreach ($address["addr"] as $key => $value) {
Expand Down Expand Up @@ -293,4 +293,115 @@ public function testCreatePayPalAddress_splittingUserName($name, $result)
$this->assertEquals($result[0], $address->oxaddress__oxfname->value);
$this->assertEquals($result[1], $address->oxaddress__oxlname->value);
}

/**
* @param $address
* @param $expected
*
* @dataProvider testSplitShipToStreetPayPalAddressDataProvider
*/
public function testSplitShipToStreetPayPalAddress($address, $expected)
{
$payPalOxAddress = oxNew(\OxidEsales\Eshop\Application\Model\Address::class);
$addressArray = $payPalOxAddress->splitShipToStreetPayPalAddress($address);

$this->assertSame(
$expected,
$addressArray
);
}

public function testSplitShipToStreetPayPalAddressDataProvider()
{
return [
'dot without space' =>
[
'canzlerstr.333332',
[
'0' => 'canzlerstr.333332',
'1' => 'canzlerstr.',
'2' => '333332',
'street' => 'canzlerstr.',
'streetnr' => '333332'
]
],
'comma' =>
[
'alsenzstr,32',
[
'0' => 'alsenzstr,32',
'1' => 'alsenzstr,',
'2' => '32',
'street' => 'alsenzstr,',
'streetnr' => '32'
]
],
'dash' =>
[
'alsenzstr-32',
[
'0' => 'alsenzstr-32',
'1' => 'alsenzstr-',
'2' => '32',
'street' => 'alsenzstr-',
'streetnr' => '32'
]
],
'dot with number and letter' =>
[
'canzlerstr.333332a',
[
'0' => 'canzlerstr.333332a',
'1' => 'canzlerstr.',
'2' => '333332a',
'street' => 'canzlerstr.',
'streetnr' => '333332a'
]
],
'dot with space' =>
[
'canzlerstr. 333332',
[
'0' => 'canzlerstr. 333332',
'1' => 'canzlerstr.',
'2' => '333332',
'street' => 'canzlerstr.',
'streetnr' => '333332'
]
],
'inserted space and dot with space' =>
[
'can zlerstr. 333332',
[
'0' => 'can zlerstr. 333332',
'1' => 'can zlerstr.',
'2' => '333332',
'street' => 'can zlerstr.',
'streetnr' => '333332'
]
],
'inserted dash and space' =>
[
'Park-d.-Opfer-des-Faschismus 1',
[
'0' => 'Park-d.-Opfer-des-Faschismus 1',
'1' => 'Park-d.-Opfer-des-Faschismus',
'2' => '1',
'street' => 'Park-d.-Opfer-des-Faschismus',
'streetnr' => '1'
]
],
'digit in streetname plus streetnumber' =>
[
'Str. des 17.Juni 34',
[
'0' => 'Str. des 17.Juni 34',
'1' => 'Str. des 17.Juni',
'2' => '34',
'street' => 'Str. des 17.Juni',
'streetnr' => '34'
]
]
];
}
}