Skip to content

Commit b84b565

Browse files
authored
Merge pull request #495 from Shopify/soyed/update-pup-templates
Map pickup point address on pickup point templates
2 parents 26d7b17 + c799a04 commit b84b565

File tree

13 files changed

+84
-50
lines changed

13 files changed

+84
-50
lines changed

order-routing/javascript/pickup-point-delivery-option-generators/default/README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This repository contains a function that demonstrates how to generate pickup point delivery options based on an external
44
API accessible via an HTTP request. To simulate an external API, we have hosted a
5-
[JSON file](https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748),
5+
[JSON file](https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690),
66
which contains pickup point information in the following format:
77

88
```json
@@ -16,7 +16,10 @@ which contains pickup point information in the following format:
1616
"streetNumber": "620",
1717
"route": "King St W",
1818
"locality": "Toronto",
19-
"administrativeAreaLevel1": "ON",
19+
"administrativeArea": {
20+
"name": "Ontario",
21+
"code": "ON"
22+
},
2023
"postalCode": "M5V 1M6",
2124
"country": "Canada",
2225
"countryCode": "CA"
@@ -80,7 +83,7 @@ the [schema](./schema.graphql).
8083
{
8184
"request": {
8285
"method": "GET",
83-
"url": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/demo-pickup-points_3dcda620-e196-40cb-ae6b-6dac17dc81c3.json?v=1706119857&lat=-79.42&lon=43.7",
86+
"url": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=-79.42&lon=43.7",
8487
"headers": [
8588
{
8689
"name": "Accept",
@@ -112,7 +115,7 @@ specified by the `FunctionRunResult` type in the [schema](./schema.graphql).
112115
{
113116
"fetchResult": {
114117
"status": 200,
115-
"body": "{\"deliveryPoints\":[{\"pointId\":\"001\",\"pointName\":\"Toronto Store\",\"location\":{\"addressComponents\":{\"streetNumber\":\"620\",\"route\":\"King St W\",\"locality\":\"Toronto\",\"administrativeAreaLevel1\":\"ON\",\"postalCode\":\"M5V 1M6\",\"country\":\"Canada\",\"countryCode\":\"CA\"},\"geometry\":{\"location\":{\"lat\":43.644664618786685,\"lng\":-79.40066267417106}}},\"openingHours\":{\"weekdayText\":[\"Monday: 9:00 AM – 9:00 PM\",\"Tuesday: 9:00 AM – 9:00 PM\",\"Wednesday: 9:00 AM – 9:00 PM\",\"Thursday: 9:00 AM – 9:00 PM\",\"Friday: 9:00 AM – 9:00 PM\",\"Saturday: 10:00 AM – 6:00 PM\",\"Sunday: Closed\"]}}]}"
118+
"body": "{\"deliveryPoints\":[{\"pointId\":\"001\",\"pointName\":\"Toronto Store\",\"location\":{\"addressComponents\":{\"streetNumber\":\"620\",\"route\":\"King St W\",\"locality\":\"Toronto\",\"administrativeArea\":{\"name\":\"Ontario\",\"code\":\"ON\"},\"postalCode\":\"M5V 1M6\",\"country\":\"Canada\",\"countryCode\":\"CA\"},\"geometry\":{\"location\":{\"lat\":43.644664618786685,\"lng\":-79.40066267417106}}},\"openingHours\":{\"weekdayText\":[\"Monday: 9:00 AM – 9:00 PM\",\"Tuesday: 9:00 AM – 9:00 PM\",\"Wednesday: 9:00 AM – 9:00 PM\",\"Thursday: 9:00 AM – 9:00 PM\",\"Friday: 9:00 AM – 9:00 PM\",\"Saturday: 10:00 AM – 6:00 PM\",\"Sunday: Closed\"]}}]}"
116119
}
117120
}
118121
```
@@ -141,8 +144,8 @@ specified by the `FunctionRunResult` type in the [schema](./schema.graphql).
141144
"latitude": 43.644664618786685,
142145
"longitude": -79.40066267417106,
143146
"phone": null,
144-
"province": "ON",
145-
"province_code": null,
147+
"province": "Ontario",
148+
"province_code": "ON",
146149
"zip": "M5V 1M6"
147150
},
148151
"business_hours": [

order-routing/javascript/pickup-point-delivery-option-generators/default/src/fetch.liquid

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function fetch(input) {
1010

1111
function buildExternalApiRequest(latitude, longitude) {
1212
// The latitude and longitude parameters are included in the URL for demonstration purposes only. They do not influence the result.
13-
let url = `https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748&lat=${latitude}&lon=${longitude}`
13+
let url = `https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=${latitude}&lon=${longitude}`
1414

1515
return {
1616
method: 'GET',

order-routing/javascript/pickup-point-delivery-option-generators/default/src/fetch.test.liquid

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('fetch function', () => {
2424
policy: {
2525
readTimeoutMs: 500,
2626
},
27-
url: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748&lat=45.6&lon=12.3',
27+
url: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=45.6&lon=12.3',
2828
}
2929
});
3030

order-routing/javascript/pickup-point-delivery-option-generators/default/src/run.liquid

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function buildAddress(externalApiDeliveryPoint) {
4343
let location = externalApiDeliveryPoint.location;
4444
let addressComponents = location.addressComponents;
4545
let geometry = location.geometry.location;
46+
let administrativeArea = addressComponents.administrativeArea;
4647

4748
return {
4849
address1: `${addressComponents.streetNumber} ${addressComponents.route}`,
@@ -53,8 +54,8 @@ function buildAddress(externalApiDeliveryPoint) {
5354
latitude: geometry.lat,
5455
longitude: geometry.lng,
5556
phone: null,
56-
province: addressComponents.administrativeAreaLevel1,
57-
provinceCode: null,
57+
province: administrativeArea.name,
58+
provinceCode: administrativeArea.code,
5859
zip: addressComponents.postalCode,
5960
};
6061
}

order-routing/javascript/pickup-point-delivery-option-generators/default/src/run.test.liquid

+12-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ describe('run function', () => {
1717
streetNumber: '123',
1818
route: 'Main St',
1919
locality: 'Toronto',
20-
administrativeAreaLevel1: 'ON',
20+
administrativeArea: {
21+
name: 'Ontario',
22+
code: 'ON'
23+
},
2124
postalCode: 'M5V 2T6',
2225
},
2326
geometry: {
@@ -61,8 +64,8 @@ describe('run function', () => {
6164
latitude: 43.70,
6265
longitude: -79.42,
6366
phone: null,
64-
province: 'ON',
65-
provinceCode: null,
67+
province: 'Ontario',
68+
provinceCode: 'ON',
6669
zip: 'M5V 2T6',
6770
},
6871
businessHours: [
@@ -117,7 +120,10 @@ describe('run function', () => {
117120
streetNumber: '123',
118121
route: 'Main St',
119122
locality: 'Toronto',
120-
administrativeAreaLevel1: 'ON',
123+
administrativeArea: {
124+
name: "Ontario",
125+
code: "ON"
126+
},
121127
postalCode: 'M5V 2T6',
122128
},
123129
geometry: {
@@ -151,8 +157,8 @@ describe('run function', () => {
151157
latitude: 43.70,
152158
longitude: -79.42,
153159
phone: null,
154-
province: 'ON',
155-
provinceCode: null,
160+
province: 'Ontario',
161+
provinceCode: 'ON',
156162
zip: 'M5V 2T6',
157163
},
158164
businessHours: null,

order-routing/rust/pickup-point-delivery-option-generators/default/README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This repository contains a function that demonstrates how to generate pickup point delivery options based on an external
44
API accessible via an HTTP request. To simulate an external API, we have hosted a
5-
[JSON file](https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748),
5+
[JSON file](https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690),
66
which contains pickup point information in the following format:
77

88
```json
@@ -16,7 +16,10 @@ which contains pickup point information in the following format:
1616
"streetNumber": "620",
1717
"route": "King St W",
1818
"locality": "Toronto",
19-
"administrativeAreaLevel1": "ON",
19+
"administrativeArea": {
20+
"name": "Ontario",
21+
"code": "ON"
22+
},
2023
"postalCode": "M5V 1M6",
2124
"country": "Canada",
2225
"countryCode": "CA"
@@ -80,7 +83,7 @@ the [schema](./schema.graphql).
8083
{
8184
"request": {
8285
"method": "GET",
83-
"url": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/demo-pickup-points_3dcda620-e196-40cb-ae6b-6dac17dc81c3.json?v=1706119857&lat=-79.42&lon=43.7",
86+
"url": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=-79.42&lon=43.7",
8487
"headers": [
8588
{
8689
"name": "Accept",
@@ -94,7 +97,6 @@ the [schema](./schema.graphql).
9497
}
9598
}
9699
```
97-
98100
### Run target
99101

100102
The **run** target is responsible for generating the pickup point delivery options. Its input API is defined by
@@ -112,7 +114,7 @@ specified by the `FunctionRunResult` type in the [schema](./schema.graphql).
112114
{
113115
"fetchResult": {
114116
"status": 200,
115-
"body": "{\"deliveryPoints\":[{\"pointId\":\"001\",\"pointName\":\"Toronto Store\",\"location\":{\"addressComponents\":{\"streetNumber\":\"620\",\"route\":\"King St W\",\"locality\":\"Toronto\",\"administrativeAreaLevel1\":\"ON\",\"postalCode\":\"M5V 1M6\",\"country\":\"Canada\",\"countryCode\":\"CA\"},\"geometry\":{\"location\":{\"lat\":43.644664618786685,\"lng\":-79.40066267417106}}},\"openingHours\":{\"weekdayText\":[\"Monday: 9:00 AM – 9:00 PM\",\"Tuesday: 9:00 AM – 9:00 PM\",\"Wednesday: 9:00 AM – 9:00 PM\",\"Thursday: 9:00 AM – 9:00 PM\",\"Friday: 9:00 AM – 9:00 PM\",\"Saturday: 10:00 AM – 6:00 PM\",\"Sunday: Closed\"]}}]}"
117+
"body": "{\"deliveryPoints\":[{\"pointId\":\"001\",\"pointName\":\"Toronto Store\",\"location\":{\"addressComponents\":{\"streetNumber\":\"620\",\"route\":\"King St W\",\"locality\":\"Toronto\",\"administrativeArea\":{\"name\":\"Ontario\",\"code\":\"ON\"},\"postalCode\":\"M5V 1M6\",\"country\":\"Canada\",\"countryCode\":\"CA\"},\"geometry\":{\"location\":{\"lat\":43.644664618786685,\"lng\":-79.40066267417106}}},\"openingHours\":{\"weekdayText\":[\"Monday: 9:00 AM – 9:00 PM\",\"Tuesday: 9:00 AM – 9:00 PM\",\"Wednesday: 9:00 AM – 9:00 PM\",\"Thursday: 9:00 AM – 9:00 PM\",\"Friday: 9:00 AM – 9:00 PM\",\"Saturday: 10:00 AM – 6:00 PM\",\"Sunday: Closed\"]}}]}"
116118
}
117119
}
118120
```
@@ -141,8 +143,8 @@ specified by the `FunctionRunResult` type in the [schema](./schema.graphql).
141143
"latitude": 43.644664618786685,
142144
"longitude": -79.40066267417106,
143145
"phone": null,
144-
"province": "ON",
145-
"province_code": null,
146+
"province": "Ontario",
147+
"province_code": "ON",
146148
"zip": "M5V 1M6"
147149
},
148150
"business_hours": [

order-routing/rust/pickup-point-delivery-option-generators/default/src/fetch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn fetch(input: fetch::input::ResponseData) -> Result<fetch::output::FunctionFet
2222
fn build_external_api_request(latitude: &f64, longitude: &f64) -> fetch::output::HttpRequest {
2323
// The latitude and longitude parameters are included in the URL for demonstration purposes only. They do not influence the result.
2424
let url = format!(
25-
"https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748&lat={}&lon={}",
25+
"https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat={}&lon={}",
2626
latitude, longitude
2727
);
2828

@@ -65,7 +65,7 @@ mod tests {
6565
let expected = FunctionFetchResult {
6666
request: Some(HttpRequest {
6767
method: HttpRequestMethod::GET,
68-
url: "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748&lat=-79.42&lon=43.7".to_string(),
68+
url: "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=-79.42&lon=43.7".to_string(),
6969

7070
headers: vec![
7171
HttpRequestHeader {

order-routing/rust/pickup-point-delivery-option-generators/default/src/run.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,19 @@ fn build_address(external_api_delivery_point: &Value) -> Option<run::output::Pic
9696
.unwrap_or_default(),
9797
phone: None,
9898
province: Some(
99-
external_api_delivery_point["location"]["addressComponents"]
100-
["administrativeAreaLevel1"]
99+
external_api_delivery_point["location"]["addressComponents"]["administrativeArea"]
100+
["name"]
101+
.as_str()
102+
.unwrap()
103+
.to_string(),
104+
),
105+
province_code: Some(
106+
external_api_delivery_point["location"]["addressComponents"]["administrativeArea"]
107+
["code"]
101108
.as_str()
102109
.unwrap()
103110
.to_string(),
104111
),
105-
province_code: None,
106112
zip: Some(
107113
external_api_delivery_point["location"]["addressComponents"]["postalCode"]
108114
.as_str()
@@ -206,7 +212,10 @@ mod tests {
206212
"streetNumber": "620",
207213
"route": "King St W",
208214
"locality": "Toronto",
209-
"administrativeAreaLevel1": "ON",
215+
"administrativeArea": {
216+
"name": "Ontario",
217+
"code": "ON"
218+
},
210219
"postalCode": "M5V 1M6",
211220
"country": "Canada",
212221
"countryCode": "CA"
@@ -258,8 +267,8 @@ mod tests {
258267
latitude: 43.644664618786685,
259268
longitude: -79.40066267417106,
260269
phone: None,
261-
province: Some("ON".to_string()),
262-
province_code: None,
270+
province: Some("Ontario".to_string()),
271+
province_code: Some("ON".to_string()),
263272
zip: Some("M5V 1M6".to_string()),
264273
},
265274
business_hours: Some(vec![
@@ -362,7 +371,10 @@ mod tests {
362371
"streetNumber": "620",
363372
"route": "King St W",
364373
"locality": "Toronto",
365-
"administrativeAreaLevel1": "ON",
374+
"administrativeArea": {
375+
"name": "Ontario",
376+
"code": "ON"
377+
},
366378
"postalCode": "M5V 1M6",
367379
"country": "Canada",
368380
"countryCode": "CA"
@@ -404,8 +416,8 @@ mod tests {
404416
latitude: 43.644664618786685,
405417
longitude: -79.40066267417106,
406418
phone: None,
407-
province: Some("ON".to_string()),
408-
province_code: None,
419+
province: Some("Ontario".to_string()),
420+
province_code: Some("ON".to_string()),
409421
zip: Some("M5V 1M6".to_string()),
410422
},
411423
business_hours: None,

order-routing/typescript/pickup-point-delivery-option-generators/default/README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This repository contains a function that demonstrates how to generate pickup point delivery options based on an external
44
API accessible via an HTTP request. To simulate an external API, we have hosted a
5-
[JSON file](https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748),
5+
[JSON file](https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690),
66
which contains pickup point information in the following format:
77

88
```json
@@ -16,7 +16,10 @@ which contains pickup point information in the following format:
1616
"streetNumber": "620",
1717
"route": "King St W",
1818
"locality": "Toronto",
19-
"administrativeAreaLevel1": "ON",
19+
"administrativeArea": {
20+
"name": "Ontario",
21+
"code": "ON"
22+
},
2023
"postalCode": "M5V 1M6",
2124
"country": "Canada",
2225
"countryCode": "CA"
@@ -80,7 +83,7 @@ the [schema](./schema.graphql).
8083
{
8184
"request": {
8285
"method": "GET",
83-
"url": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/demo-pickup-points_3dcda620-e196-40cb-ae6b-6dac17dc81c3.json?v=1706119857&lat=-79.42&lon=43.7",
86+
"url": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=-79.42&lon=43.7",
8487
"headers": [
8588
{
8689
"name": "Accept",
@@ -112,7 +115,7 @@ specified by the `FunctionRunResult` type in the [schema](./schema.graphql).
112115
{
113116
"fetchResult": {
114117
"status": 200,
115-
"body": "{\"deliveryPoints\":[{\"pointId\":\"001\",\"pointName\":\"Toronto Store\",\"location\":{\"addressComponents\":{\"streetNumber\":\"620\",\"route\":\"King St W\",\"locality\":\"Toronto\",\"administrativeAreaLevel1\":\"ON\",\"postalCode\":\"M5V 1M6\",\"country\":\"Canada\",\"countryCode\":\"CA\"},\"geometry\":{\"location\":{\"lat\":43.644664618786685,\"lng\":-79.40066267417106}}},\"openingHours\":{\"weekdayText\":[\"Monday: 9:00 AM – 9:00 PM\",\"Tuesday: 9:00 AM – 9:00 PM\",\"Wednesday: 9:00 AM – 9:00 PM\",\"Thursday: 9:00 AM – 9:00 PM\",\"Friday: 9:00 AM – 9:00 PM\",\"Saturday: 10:00 AM – 6:00 PM\",\"Sunday: Closed\"]}}]}"
118+
"body": "{\"deliveryPoints\":[{\"pointId\":\"001\",\"pointName\":\"Toronto Store\",\"location\":{\"addressComponents\":{\"streetNumber\":\"620\",\"route\":\"King St W\",\"locality\":\"Toronto\",\"administrativeArea\":{\"name\":\"Ontario\",\"code\":\"ON\"},\"postalCode\":\"M5V 1M6\",\"country\":\"Canada\",\"countryCode\":\"CA\"},\"geometry\":{\"location\":{\"lat\":43.644664618786685,\"lng\":-79.40066267417106}}},\"openingHours\":{\"weekdayText\":[\"Monday: 9:00 AM – 9:00 PM\",\"Tuesday: 9:00 AM – 9:00 PM\",\"Wednesday: 9:00 AM – 9:00 PM\",\"Thursday: 9:00 AM – 9:00 PM\",\"Friday: 9:00 AM – 9:00 PM\",\"Saturday: 10:00 AM – 6:00 PM\",\"Sunday: Closed\"]}}]}"
116119
}
117120
}
118121
```
@@ -141,8 +144,8 @@ specified by the `FunctionRunResult` type in the [schema](./schema.graphql).
141144
"latitude": 43.644664618786685,
142145
"longitude": -79.40066267417106,
143146
"phone": null,
144-
"province": "ON",
145-
"province_code": null,
147+
"province": "Ontario",
148+
"province_code": "ON",
146149
"zip": "M5V 1M6"
147150
},
148151
"business_hours": [

order-routing/typescript/pickup-point-delivery-option-generators/default/src/fetch.liquid

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function fetch(input: FetchInput): FunctionFetchResult {
2121

2222
function buildExternalApiRequest(latitude: number, longitude: number): HttpRequest {
2323
// The latitude and longitude parameters are included in the URL for demonstration purposes only. They do not influence the result.
24-
let url = `https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748&lat=${latitude}&lon=${longitude}`;
24+
let url = `https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=${latitude}&lon=${longitude}`;
2525

2626
return {
2727
method: HttpRequestMethod.Get,

order-routing/typescript/pickup-point-delivery-option-generators/default/src/fetch.test.liquid

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('fetch function', () => {
2222
policy: {
2323
readTimeoutMs: 500,
2424
},
25-
url: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v1.json?v=1712853748&lat=45.6&lon=12.3',
25+
url: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=45.6&lon=12.3',
2626
}
2727
});
2828

order-routing/typescript/pickup-point-delivery-option-generators/default/src/run.liquid

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function buildAddress(externalApiDeliveryPoint: any): PickupAddress {
5353
let location = externalApiDeliveryPoint.location;
5454
let addressComponents = location.addressComponents;
5555
let geometry = location.geometry.location;
56+
let administrativeArea = addressComponents.administrativeArea;
5657

5758
return {
5859
address1: `${addressComponents.streetNumber} ${addressComponents.route}`,
@@ -63,8 +64,8 @@ function buildAddress(externalApiDeliveryPoint: any): PickupAddress {
6364
latitude: geometry.lat,
6465
longitude: geometry.lng,
6566
phone: null,
66-
province: addressComponents.administrativeAreaLevel1,
67-
provinceCode: null,
67+
province: administrativeArea.name,
68+
provinceCode: administrativeArea.code,
6869
zip: addressComponents.postalCode,
6970
};
7071
}

0 commit comments

Comments
 (0)