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

[ENHANCEMENT] Added province code to AddressView #600

Merged
merged 10 commits into from
Dec 19, 2019
Merged
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
6 changes: 4 additions & 2 deletions spec/Factory/AddressBook/AddressViewFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function it_creates_address_view(AddressInterface $address): void
$address->getCountryCode()->willReturn('GB');
$address->getCity()->willReturn('London');
$address->getPostcode()->willReturn('NMW');
$address->getProvinceName()->willReturn('Greater London');
$address->getProvinceCode()->willReturn('GB-ENG');
$address->getProvinceName()->willReturn('England');
$address->getCompany()->willReturn('Detective Inc');
$address->getPhoneNumber()->willReturn('999');

Expand All @@ -40,7 +41,8 @@ function it_creates_address_view(AddressInterface $address): void
$addressView->countryCode = 'GB';
$addressView->city = 'London';
$addressView->postcode = 'NMW';
$addressView->provinceName = 'Greater London';
$addressView->provinceCode = 'GB-ENG';
$addressView->provinceName = 'England';
$addressView->company = 'Detective Inc';
$addressView->phoneNumber = '999';

Expand Down
1 change: 1 addition & 0 deletions src/Factory/AddressBook/AddressViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function create(AddressInterface $address): AddressView
$addressView->street = $address->getStreet();
$addressView->city = $address->getCity();
$addressView->postcode = $address->getPostcode();
$addressView->provinceCode = $address->getProvinceCode();
$addressView->provinceName = $address->getProvinceName();
$addressView->company = $address->getCompany();
$addressView->phoneNumber = $address->getPhoneNumber();
Expand Down
3 changes: 3 additions & 0 deletions src/View/AddressBook/AddressView.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class AddressView
/** @var string */
public $postcode;

/** @var string */
public $provinceCode;

/** @var string */
public $provinceName;

Expand Down
48 changes: 48 additions & 0 deletions tests/Controller/Checkout/SummarizeApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,54 @@ public function it_shows_an_order_with_same_shipping_and_billing_address_with_pr
$this->assertResponse($response, 'checkout/cart_addressed_response', Response::HTTP_OK);
}

/**
* @test
*/
public function it_shows_an_order_addressed_with_province_codes(): void
{
$this->loadFixturesFromFiles(['shop.yml', 'country.yml']);

$token = 'SDAOSLEFNWU35H3QLI5325';

/** @var MessageBusInterface $bus */
$bus = $this->get('sylius_shop_api_plugin.command_bus');
$bus->dispatch(new PickupCart($token, 'WEB_GB'));
$bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5));

$data =
<<<JSON
{
"shippingAddress": {
"firstName": "Sherlock",
"lastName": "Holmes",
"countryCode": "GB",
"street": "Baker Street 221b",
"city": "London",
"postcode": "NW1",
"provinceCode": "GB-ENG",
"company": "Detective Inc",
"phoneNumber": "999"
},
"billingAddress": {
"firstName": "Sherlock",
"lastName": "Holmes",
"countryCode": "GB",
"street": "Baker Street 221b",
"city": "London",
"postcode": "NW1",
"provinceCode": "GB-WLS",
"company": "Detective Inc",
"phoneNumber": "999"
}
}
JSON;

$this->client->request('PUT', sprintf('/shop-api/checkout/%s/address', $token), [], [], static::CONTENT_TYPE_HEADER, $data);

$response = $this->summarize($token);
$this->assertResponse($response, 'checkout/cart_addressed_with_province_codes_response', Response::HTTP_OK);
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"tokenValue": "SDAOSLEFNWU35H3QLI5325",
"channel": "WEB_GB",
"currency": "GBP",
"locale": "en_GB",
"checkoutState": "addressed",
"items": [
{
"id": @integer@,
"quantity": 5,
"total": 9995,
"product": {
"code": "LOGAN_MUG_CODE",
"name": "Logan Mug",
"slug": "logan-mug",
"channelCode": "WEB_GB",
"description": "Some description Lorem ipsum dolor sit amet.",
"averageRating": 0,
"taxons": {
"main": "MUG",
"others": [
"MUG",
"BRAND"
]
},
"variants": [
{
"code": "LOGAN_MUG_CODE",
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"price": {
"current": 1999,
"currency": "GBP"
},
"originalPrice": {
"current": 2999,
"currency": "GBP"
},
"images": []
}
],
"attributes": [
{
"code": "MUG_MATERIAL_CODE",
"name": "Mug material",
"type": "select",
"value": [
"Wood"
]
}
],
"associations": [],
"images": [
{
"code": "thumbnail",
"path": "/pants.jpeg",
"cachedPath": "http://localhost/media/cache/sylius_shop_api/pants.jpeg"
}
],
"_links": {
"self": {
"href": "\/shop-api\/products\/by-slug\/logan-mug"
}
}
}
}
],
"totals": {
"total": 9995,
"items": 9995,
"taxes": 0,
"shipping": 0,
"promotion": 0
},
"shippingAddress": {
"firstName": "Sherlock",
"lastName": "Holmes",
"countryCode": "GB",
"street": "Baker Street 221b",
"city": "London",
"postcode": "NW1",
"provinceName": "England",
"provinceCode": "GB-ENG",
"company": "Detective Inc",
"phoneNumber": "999"
},
"billingAddress": {
"firstName": "Sherlock",
"lastName": "Holmes",
"countryCode": "GB",
"street": "Baker Street 221b",
"city": "London",
"postcode": "NW1",
"provinceName": "Wales",
"provinceCode": "GB-WLS",
"company": "Detective Inc",
"phoneNumber": "999"
},
"payments": [],
"shipments": [],
"cartDiscounts": []
}