Skip to content

Commit

Permalink
feat: add multiple address line support
Browse files Browse the repository at this point in the history
  • Loading branch information
maruamallo authored and gabrielpiriz committed Mar 25, 2022
1 parent a3ede15 commit 7e59597
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 85 deletions.
16 changes: 8 additions & 8 deletions src/Contract/BusinessUnitOperatorCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ interface BusinessUnitOperatorCodes
];

public const COUNTRY_CODES = [
self::CODE_CHILE,
self::CODE_PERU,
self::CODE_MEXICO,
self::CODE_COLOMBIA,
self::CODE_CHILE,
self::CODE_PERU,
self::CODE_MEXICO,
self::CODE_COLOMBIA,
];

public const COUNTRY_OPERATOR = [
self::CODE_CHILE => self::FALA_CHILE,
self::CODE_PERU => self::FALA_PERU,
self::CODE_MEXICO => self::FALA_MEXICO,
self::CODE_COLOMBIA => self::FALA_COLOMBIA,
self::CODE_CHILE => self::FALA_CHILE,
self::CODE_PERU => self::FALA_PERU,
self::CODE_MEXICO => self::FALA_MEXICO,
self::CODE_COLOMBIA => self::FALA_COLOMBIA,
];
}
10 changes: 9 additions & 1 deletion src/Factory/Xml/Order/AddressFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class AddressFactory
'Phone',
'Phone2',
'Address1',
'Address2',
'Address3',
'Address4',
'Address5',
'CustomerEmail',
'City',
'Ward',
Expand All @@ -40,7 +44,11 @@ public static function make(SimpleXMLElement $element): Address
(string) $element->Ward,
(string) $element->Region,
(string) $element->PostCode,
(string) $element->Country
(string) $element->Country,
(string) $element->Address2,
(string) $element->Address3,
(string) $element->Address4,
(string) $element->Address5
);
}
}
54 changes: 53 additions & 1 deletion src/Model/Order/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ class Address implements JsonSerializable
*/
protected $address;

/**
* @var string|null
*/
protected $address2;

/**
* @var string|null
*/
protected $address3;

/**
* @var string|null
*/
protected $address4;

/**
* @var string|null
*/
protected $address5;

/**
* @var string|null
*/
Expand Down Expand Up @@ -75,13 +95,21 @@ public function __construct(
string $ward,
string $region,
string $postCode,
string $country
string $country,
string $address2 = null,
string $address3 = null,
string $address4 = null,
string $address5 = null
) {
$this->firstName = !empty($firstName) ? $firstName : null;
$this->lastName = !empty($lastName) ? $lastName : null;
$this->phone = !empty($phone) ? $phone : null;
$this->phone2 = !empty($phone2) ? $phone2 : null;
$this->address = !empty($address) ? $address : null;
$this->address2 = !empty($address2) ? $address2 : null;
$this->address3 = !empty($address3) ? $address3 : null;
$this->address4 = !empty($address4) ? $address4 : null;
$this->address5 = !empty($address5) ? $address5 : null;
$this->customerEmail = !empty($customerEmail) ? $customerEmail : null;
$this->city = !empty($city) ? $city : null;
$this->ward = !empty($ward) ? $ward : null;
Expand Down Expand Up @@ -115,6 +143,26 @@ public function getAddress(): ?string
return $this->address;
}

public function getAddress2(): ?string
{
return $this->address2;
}

public function getAddress3(): ?string
{
return $this->address3;
}

public function getAddress4(): ?string
{
return $this->address4;
}

public function getAddress5(): ?string
{
return $this->address5;
}

public function getCustomerEmail(): ?string
{
return $this->customerEmail;
Expand Down Expand Up @@ -153,6 +201,10 @@ public function jsonSerialize(): stdClass
$serialized->phone = $this->phone;
$serialized->phone2 = $this->phone2;
$serialized->address = $this->address;
$serialized->address2 = $this->address2;
$serialized->address3 = $this->address3;
$serialized->address4 = $this->address4;
$serialized->address5 = $this->address5;
$serialized->customerEmail = $this->customerEmail;
$serialized->city = $this->city;
$serialized->ward = $this->ward;
Expand Down
18 changes: 17 additions & 1 deletion tests/Unit/Order/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class AddressTest extends LinioTestCase
protected $firstName = 'John';
protected $lastName = 'Doe';
protected $phone = 123456789;
protected $address1 = 'address';
protected $address1 = 'address1';
protected $address2 = 'address2';
protected $address3 = 'address3';
protected $address4 = 'address4';
protected $address5 = 'address5';
protected $customerEmail = '[email protected]';
protected $city = 'City';
protected $ward = 'test';
Expand All @@ -35,6 +39,10 @@ public function testItReturnsValidAddress(): void
$this->assertEquals((int) $simpleXml->Phone, $address->getPhone());
$this->assertEquals((int) $simpleXml->Phone2, $address->getPhone2());
$this->assertEquals($simpleXml->Address1, $address->getAddress());
$this->assertEquals($simpleXml->Address2, $address->getAddress2());
$this->assertEquals($simpleXml->Address3, $address->getAddress3());
$this->assertEquals($simpleXml->Address4, $address->getAddress4());
$this->assertEquals($simpleXml->Address5, $address->getAddress5());
$this->assertEquals($simpleXml->CustomerEmail, $address->getCustomerEmail());
$this->assertEquals($simpleXml->City, $address->getCity());
$this->assertEquals($simpleXml->Ward, $address->getWard());
Expand Down Expand Up @@ -76,6 +84,10 @@ public function testItReturnsAJsonRepresentation(): void
$expectedJson['lastName'] = $this->lastName;
$expectedJson['phone'] = $this->phone;
$expectedJson['address'] = $this->address1;
$expectedJson['address2'] = $this->address2;
$expectedJson['address3'] = $this->address3;
$expectedJson['address4'] = $this->address4;
$expectedJson['address5'] = $this->address5;
$expectedJson['customerEmail'] = $this->customerEmail;
$expectedJson['city'] = $this->city;
$expectedJson['ward'] = $this->ward;
Expand All @@ -94,6 +106,10 @@ public function createXmlStringForAddress(string $schema = 'Order/Address.xml'):
$this->lastName,
$this->phone,
$this->address1,
$this->address2,
$this->address3,
$this->address4,
$this->address5,
$this->customerEmail,
$this->city,
$this->ward,
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Order/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class OrderTest extends LinioTestCase
protected $firstName = 'firstName';
protected $lastName = 'Rocket';
protected $address1 = 'address';
protected $address2 = 'address2';
protected $address3 = 'address3';
protected $address4 = 'address4';
protected $address5 = 'address5';
protected $city = 'city';
protected $postCode = '10117';
protected $country = 'country';
Expand Down Expand Up @@ -156,12 +160,20 @@ public function testItReturnsAJsonRepresentation(string $property): void
$expectedJson['addressBilling']['firstName'] = $this->firstName;
$expectedJson['addressBilling']['lastName'] = $this->lastName;
$expectedJson['addressBilling']['address'] = $this->address1;
$expectedJson['addressBilling']['address2'] = $this->address2;
$expectedJson['addressBilling']['address3'] = $this->address3;
$expectedJson['addressBilling']['address4'] = $this->address4;
$expectedJson['addressBilling']['address5'] = $this->address5;
$expectedJson['addressBilling']['city'] = $this->city;
$expectedJson['addressBilling']['postCode'] = $this->postCode;
$expectedJson['addressBilling']['country'] = $this->country;
$expectedJson['addressShipping']['firstName'] = $this->firstName;
$expectedJson['addressShipping']['lastName'] = $this->lastName;
$expectedJson['addressShipping']['address'] = $this->address1;
$expectedJson['addressShipping']['address2'] = $this->address2;
$expectedJson['addressShipping']['address3'] = $this->address3;
$expectedJson['addressShipping']['address4'] = $this->address4;
$expectedJson['addressShipping']['address5'] = $this->address5;
$expectedJson['addressShipping']['city'] = $this->city;
$expectedJson['addressShipping']['postCode'] = $this->postCode;
$expectedJson['addressShipping']['country'] = $this->country;
Expand Down
9 changes: 4 additions & 5 deletions tests/Unit/Product/BusinessUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Linio\SellerCenter\Unit\Product;

use SimpleXMLElement;
use DateTimeImmutable;
use Linio\Component\Util\Json;
use Linio\SellerCenter\LinioTestCase;
use Linio\SellerCenter\Model\Product\BusinessUnit;
use Linio\SellerCenter\Exception\InvalidDomainException;
use Linio\SellerCenter\Contract\BusinessUnitOperatorCodes;
use Linio\SellerCenter\Exception\InvalidDomainException;
use Linio\SellerCenter\Exception\InvalidXmlStructureException;
use Linio\SellerCenter\Factory\Xml\Product\BusinessUnitFactory;
use Linio\SellerCenter\LinioTestCase;
use Linio\SellerCenter\Model\Product\BusinessUnit;
use SimpleXMLElement;

class BusinessUnitTest extends LinioTestCase
{
Expand All @@ -26,7 +26,6 @@ class BusinessUnitTest extends LinioTestCase
*/
protected $countryCode = 'cl';


/**
* @var string
*/
Expand Down
6 changes: 5 additions & 1 deletion tests/_schemas/Order/Address.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
<Phone>%s</Phone>
<Phone2></Phone2>
<Address1>%s</Address1>
<Address2>%s</Address2>
<Address3>%s</Address3>
<Address4>%s</Address4>
<Address5>%s</Address5>
<CustomerEmail>%s</CustomerEmail>
<City>%s</City>
<Ward>%s</Ward>
<Region>%s</Region>
<PostCode>%s</PostCode>
<Country>%s</Country>
</Address>
</Address>
106 changes: 57 additions & 49 deletions tests/_schemas/Order/Order.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
{
"orderId": "%d",
"customerFirstName": "%s",
"customerLastName": "%s",
"orderNumber": "%d",
"paymentMethod": "%s",
"remarks": "%s",
"deliveryInfo": "%s",
"price": "%d",
"giftOption": "%s",
"giftMessage": "",
"voucherCode": "",
"createdAt": "%s",
"updatedAt": "%s",
"addressUpdatedAt": "%s",
"addressBilling": {
"firstName": "%s",
"lastName": "%s",
"phone": null,
"phone2": null,
"address": "%s",
"customerEmail": null,
"city": "%s",
"ward": null,
"region": null,
"postCode": "%s",
"country": "%s"
},
"addressShipping": {
"firstName": "%s",
"lastName": "%s",
"phone": null,
"phone2": null,
"address": "%s",
"customerEmail": null,
"city": "%s",
"ward": null,
"region": null,
"postCode": "%s",
"country": "%s"
},
"nationalRegistrationNumber": "%s",
"itemsCount": "%d",
"promisedShippingTime": "%s",
"extraAttributes": "%s",
"statuses": [
"%s",
"%s"
],
"orderItems": null
"orderId": "%d",
"customerFirstName": "%s",
"customerLastName": "%s",
"orderNumber": "%d",
"paymentMethod": "%s",
"remarks": "%s",
"deliveryInfo": "%s",
"price": "%d",
"giftOption": "%s",
"giftMessage": "",
"voucherCode": "",
"createdAt": "%s",
"updatedAt": "%s",
"addressUpdatedAt": "%s",
"addressBilling": {
"firstName": "%s",
"lastName": "%s",
"phone": null,
"phone2": null,
"address": "%s",
"address2": "address2",
"address3": "address3",
"address4": "address4",
"address5": "address5",
"customerEmail": null,
"city": "%s",
"ward": null,
"region": null,
"postCode": "%s",
"country": "%s"
},
"addressShipping": {
"firstName": "%s",
"lastName": "%s",
"phone": null,
"phone2": null,
"address": "%s",
"address2": "address2",
"address3": "address3",
"address4": "address4",
"address5": "address5",
"customerEmail": null,
"city": "%s",
"ward": null,
"region": null,
"postCode": "%s",
"country": "%s"
},
"nationalRegistrationNumber": "%s",
"itemsCount": "%d",
"promisedShippingTime": "%s",
"extraAttributes": "%s",
"statuses": [
"%s",
"%s"
],
"orderItems": null
}
10 changes: 9 additions & 1 deletion tests/_schemas/Order/Order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<Phone/>
<Phone2/>
<Address1>%s</Address1>
<Address2>address2</Address2>
<Address3>address3</Address3>
<Address4>address4</Address4>
<Address5>address5</Address5>
<CustomerEmail/>
<City>%s</City>
<Ward/>
Expand All @@ -33,6 +37,10 @@
<Phone/>
<Phone2/>
<Address1>%s</Address1>
<Address2>address2</Address2>
<Address3>address3</Address3>
<Address4>address4</Address4>
<Address5>address5</Address5>
<CustomerEmail/>
<City>%s</City>
<Ward/>
Expand All @@ -49,4 +57,4 @@
<Status>%s</Status>
</Statuses>
<OperatorCode>%s</OperatorCode>
</Order>
</Order>
Loading

0 comments on commit 7e59597

Please sign in to comment.