From 7e59597fdb36d43c32100623900b2f0e76f626c0 Mon Sep 17 00:00:00 2001 From: Maru Amallo Date: Thu, 28 Oct 2021 12:17:38 -0300 Subject: [PATCH] feat: add multiple address line support --- src/Contract/BusinessUnitOperatorCodes.php | 16 ++-- src/Factory/Xml/Order/AddressFactory.php | 10 +- src/Model/Order/Address.php | 54 ++++++++++- tests/Unit/Order/AddressTest.php | 18 +++- tests/Unit/Order/OrderTest.php | 12 +++ tests/Unit/Product/BusinessUnitTest.php | 9 +- tests/_schemas/Order/Address.xml | 6 +- tests/_schemas/Order/Order.json | 106 +++++++++++---------- tests/_schemas/Order/Order.xml | 10 +- tests/_schemas/Order/Orders.xml | 26 +++-- tests/_schemas/Order/OrdersResponse.xml | 26 +++-- 11 files changed, 208 insertions(+), 85 deletions(-) diff --git a/src/Contract/BusinessUnitOperatorCodes.php b/src/Contract/BusinessUnitOperatorCodes.php index fffafe1..fb04543 100644 --- a/src/Contract/BusinessUnitOperatorCodes.php +++ b/src/Contract/BusinessUnitOperatorCodes.php @@ -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, ]; } diff --git a/src/Factory/Xml/Order/AddressFactory.php b/src/Factory/Xml/Order/AddressFactory.php index 05e409a..2a8e8ad 100644 --- a/src/Factory/Xml/Order/AddressFactory.php +++ b/src/Factory/Xml/Order/AddressFactory.php @@ -17,6 +17,10 @@ class AddressFactory 'Phone', 'Phone2', 'Address1', + 'Address2', + 'Address3', + 'Address4', + 'Address5', 'CustomerEmail', 'City', 'Ward', @@ -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 ); } } diff --git a/src/Model/Order/Address.php b/src/Model/Order/Address.php index e5a500f..0ec48a9 100644 --- a/src/Model/Order/Address.php +++ b/src/Model/Order/Address.php @@ -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 */ @@ -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; @@ -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; @@ -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; diff --git a/tests/Unit/Order/AddressTest.php b/tests/Unit/Order/AddressTest.php index 739fc39..f4cad4b 100644 --- a/tests/Unit/Order/AddressTest.php +++ b/tests/Unit/Order/AddressTest.php @@ -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 = 'hello@sellercenter.net'; protected $city = 'City'; protected $ward = 'test'; @@ -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()); @@ -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; @@ -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, diff --git a/tests/Unit/Order/OrderTest.php b/tests/Unit/Order/OrderTest.php index 42b7449..e18fdb9 100644 --- a/tests/Unit/Order/OrderTest.php +++ b/tests/Unit/Order/OrderTest.php @@ -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'; @@ -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; diff --git a/tests/Unit/Product/BusinessUnitTest.php b/tests/Unit/Product/BusinessUnitTest.php index ab794bb..cec96ef 100644 --- a/tests/Unit/Product/BusinessUnitTest.php +++ b/tests/Unit/Product/BusinessUnitTest.php @@ -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 { @@ -26,7 +26,6 @@ class BusinessUnitTest extends LinioTestCase */ protected $countryCode = 'cl'; - /** * @var string */ diff --git a/tests/_schemas/Order/Address.xml b/tests/_schemas/Order/Address.xml index 012fffc..5a56a62 100644 --- a/tests/_schemas/Order/Address.xml +++ b/tests/_schemas/Order/Address.xml @@ -5,10 +5,14 @@ %s %s + %s + %s + %s + %s %s %s %s %s %s %s - \ No newline at end of file + diff --git a/tests/_schemas/Order/Order.json b/tests/_schemas/Order/Order.json index 401b312..fe7d512 100644 --- a/tests/_schemas/Order/Order.json +++ b/tests/_schemas/Order/Order.json @@ -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 } \ No newline at end of file diff --git a/tests/_schemas/Order/Order.xml b/tests/_schemas/Order/Order.xml index 98a19b2..fa66386 100644 --- a/tests/_schemas/Order/Order.xml +++ b/tests/_schemas/Order/Order.xml @@ -20,6 +20,10 @@ %s + address2 + address3 + address4 + address5 %s @@ -33,6 +37,10 @@ %s + address2 + address3 + address4 + address5 %s @@ -49,4 +57,4 @@ %s %s - \ No newline at end of file + diff --git a/tests/_schemas/Order/Orders.xml b/tests/_schemas/Order/Orders.xml index 656c318..c479dcd 100644 --- a/tests/_schemas/Order/Orders.xml +++ b/tests/_schemas/Order/Orders.xml @@ -22,6 +22,10 @@ Johannisstr. 20 + address2 + address3 + address4 + address5 Berlin @@ -35,6 +39,10 @@ Charlottenstraße 4 + address2 + address3 + address4 + address5 Berlin @@ -71,10 +79,10 @@ Johannisstr. 20 - - - - + address2 + address3 + address4 + address5 Berlin @@ -88,10 +96,10 @@ Charlottenstraße 4 - - - - + address2 + address3 + address4 + address5 Berlin @@ -108,4 +116,4 @@ - \ No newline at end of file + diff --git a/tests/_schemas/Order/OrdersResponse.xml b/tests/_schemas/Order/OrdersResponse.xml index 2622a1f..79afeb1 100644 --- a/tests/_schemas/Order/OrdersResponse.xml +++ b/tests/_schemas/Order/OrdersResponse.xml @@ -29,6 +29,10 @@ Johannisstr. 20 + address2 + address3 + address4 + address5 Berlin @@ -42,6 +46,10 @@ Charlottenstraße 4 + address2 + address3 + address4 + address5 Berlin @@ -79,10 +87,10 @@ Johannisstr. 20 - - - - + address2 + address3 + address4 + address5 Berlin @@ -96,10 +104,10 @@ Charlottenstraße 4 - - - - + address2 + address3 + address4 + address5 Berlin @@ -118,4 +126,4 @@ - \ No newline at end of file +