Skip to content

Commit 267e0fe

Browse files
authored
Merge pull request #488 from Shopify/soyed/pup-deprecate-allocations
Deprecate `Allocations` on pickup point functions template.
2 parents f16d84e + 19282f0 commit 267e0fe

File tree

16 files changed

+169
-405
lines changed

16 files changed

+169
-405
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,11 @@ the [schema](./schema.graphql).
6666

6767
```json
6868
{
69-
"allocations": [
70-
{
71-
"deliveryAddress": {
72-
"countryCode": "CA",
73-
"longitude": 43.70,
74-
"latitude": -79.42
75-
}
76-
}
77-
]
69+
"deliveryAddres": {
70+
"countryCode": "CA",
71+
"longitude": 43.70,
72+
"latitude": -79.42
73+
}
7874
}
7975
```
8076

order-routing/javascript/pickup-point-delivery-option-generators/default/schema.graphql

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,13 +2940,18 @@ type Input {
29402940
"""
29412941
A list of allocations.
29422942
"""
2943-
allocations: [Allocation!]!
2943+
allocations: [Allocation!]! @deprecated(reason: "Use `deliveryAddress` instead.")
29442944

29452945
"""
29462946
The cart.
29472947
"""
29482948
cart: Cart!
29492949

2950+
"""
2951+
The delivery address for pickup point delivery option.
2952+
"""
2953+
deliveryAddress: MailingAddress!
2954+
29502955
"""
29512956
The result of the fetch target. Refer to network access for Shopify Functions.
29522957
"""
@@ -4303,7 +4308,7 @@ type PurchasingCompany {
43034308
"""
43044309
Represents how products and variants can be sold and purchased.
43054310
"""
4306-
type SellingPlan {
4311+
type SellingPlan implements HasMetafields {
43074312
"""
43084313
The description of the selling plan.
43094314
"""
@@ -4314,6 +4319,21 @@ type SellingPlan {
43144319
"""
43154320
id: ID!
43164321

4322+
"""
4323+
Returns a metafield by namespace and key that belongs to the resource.
4324+
"""
4325+
metafield(
4326+
"""
4327+
The key for the metafield.
4328+
"""
4329+
key: String!
4330+
4331+
"""
4332+
The container the metafield belongs to. If omitted, the app-reserved namespace will be used.
4333+
"""
4334+
namespace: String
4335+
): Metafield
4336+
43174337
"""
43184338
The name of the selling plan. For example, '6 weeks of prepaid granola, delivered weekly'.
43194339
"""
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
query FetchInput {
2-
allocations {
3-
deliveryAddress {
4-
countryCode
5-
longitude
6-
latitude
7-
}
2+
deliveryAddress{
3+
countryCode
4+
longitude
5+
latitude
86
}
97
}
Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
export function fetch(input) {
2-
let deliveryAddress = getUniformDeliveryAddress(input.allocations);
3-
if (deliveryAddress) {
4-
let { countryCode, longitude, latitude } = deliveryAddress;
5-
if (longitude && latitude && countryCode === 'CA') {
6-
return {
7-
request: buildExternalApiRequest(latitude, longitude),
8-
};
9-
}
2+
let { countryCode, longitude, latitude } = input.deliveryAddress;
3+
if (longitude && latitude && countryCode === 'CA') {
4+
return {
5+
request: buildExternalApiRequest(latitude, longitude),
6+
};
107
}
118
return { request: null };
129
}
@@ -28,26 +25,3 @@ function buildExternalApiRequest(latitude, longitude) {
2825
},
2926
};
3027
}
31-
32-
function getUniformDeliveryAddress(allocations) {
33-
if (allocations.length === 0) {
34-
return null;
35-
}
36-
37-
let deliveryAddress = allocations[0].deliveryAddress;
38-
39-
for (let i = 1; i < allocations.length; i++) {
40-
if (!isDeliveryAddressEqual(allocations[i].deliveryAddress, deliveryAddress)) {
41-
console.error("Allocations pointing to different delivery addresses are not supported.");
42-
return null;
43-
}
44-
}
45-
46-
return deliveryAddress;
47-
}
48-
49-
function isDeliveryAddressEqual(address1, address2) {
50-
return address1.countryCode === address2.countryCode &&
51-
address1.longitude === address2.longitude &&
52-
address1.latitude === address2.latitude;
53-
}

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

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ import { fetch } from './fetch';
88
describe('fetch function', () => {
99
it('returns a request when country is Canada', () => {
1010
const result = fetch({
11-
allocations: [
12-
{
13-
deliveryAddress: {
14-
countryCode: 'CA',
15-
longitude: 12.3,
16-
latitude: 45.6,
17-
}
18-
}
19-
]
11+
deliveryAddress: {
12+
countryCode: 'CA',
13+
longitude: 12.3,
14+
latitude: 45.6,
15+
}
2016
});
2117
const expected = ({
2218
request: {
@@ -37,77 +33,13 @@ describe('fetch function', () => {
3733

3834
it('returns no request when country is not Canada', () => {
3935
const result = fetch({
40-
allocations: [
41-
{
42-
deliveryAddress: {
43-
countryCode: 'US',
44-
longitude: 12.3,
45-
latitude: 45.6,
46-
}
47-
}
48-
]
49-
});
50-
const expected = ({ request: null });
51-
52-
expect(result).toEqual(expected);
53-
});
54-
55-
it('returns no request when allocations have different addresses', () => {
56-
const result = fetch({
57-
allocations: [
58-
{
59-
deliveryAddress: {
60-
countryCode: 'CA',
61-
longitude: 12.3,
62-
latitude: 45.6,
63-
}
64-
},
65-
{
66-
deliveryAddress: {
67-
countryCode: 'CA',
68-
longitude: 78.9,
69-
latitude: 10.1,
70-
}
71-
}
72-
]
73-
});
74-
const expected = ({ request: null });
75-
76-
expect(result).toEqual(expected);
77-
});
78-
79-
it('returns a request when allocations have the same address', () => {
80-
const result = fetch({
81-
allocations: [
82-
{
83-
deliveryAddress: {
84-
countryCode: 'CA',
85-
longitude: 12.3,
86-
latitude: 45.6,
87-
}
88-
},
89-
{
90-
deliveryAddress: {
91-
countryCode: 'CA',
92-
longitude: 12.3,
93-
latitude: 45.6,
94-
}
95-
}
96-
]
97-
});
98-
const expected = ({
99-
request: {
100-
body: null,
101-
headers: [
102-
{ name: "Accept", value: "application/json; charset=utf-8" },
103-
],
104-
method: 'GET',
105-
policy: {
106-
readTimeoutMs: 500,
107-
},
108-
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',
36+
deliveryAddress: {
37+
countryCode: 'US',
38+
longitude: 12.3,
39+
latitude: 45.6,
10940
}
11041
});
42+
const expected = ({ request: null });
11143

11244
expect(result).toEqual(expected);
11345
});

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,11 @@ the [schema](./schema.graphql).
6666

6767
```json
6868
{
69-
"allocations": [
70-
{
71-
"deliveryAddress": {
72-
"countryCode": "CA",
73-
"longitude": 43.70,
74-
"latitude": -79.42
75-
}
76-
}
77-
]
69+
"deliveryAddress": {
70+
"countryCode": "CA",
71+
"longitude": 43.70,
72+
"latitude": -79.42
73+
}
7874
}
7975
```
8076

order-routing/rust/pickup-point-delivery-option-generators/default/schema.graphql

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,13 +2940,18 @@ type Input {
29402940
"""
29412941
A list of allocations.
29422942
"""
2943-
allocations: [Allocation!]!
2943+
allocations: [Allocation!]! @deprecated(reason: "Use `deliveryAddress` instead.")
29442944

29452945
"""
29462946
The cart.
29472947
"""
29482948
cart: Cart!
29492949

2950+
"""
2951+
The delivery address for pickup point delivery option.
2952+
"""
2953+
deliveryAddress: MailingAddress!
2954+
29502955
"""
29512956
The result of the fetch target. Refer to network access for Shopify Functions.
29522957
"""
@@ -4303,7 +4308,7 @@ type PurchasingCompany {
43034308
"""
43044309
Represents how products and variants can be sold and purchased.
43054310
"""
4306-
type SellingPlan {
4311+
type SellingPlan implements HasMetafields {
43074312
"""
43084313
The description of the selling plan.
43094314
"""
@@ -4314,6 +4319,21 @@ type SellingPlan {
43144319
"""
43154320
id: ID!
43164321

4322+
"""
4323+
Returns a metafield by namespace and key that belongs to the resource.
4324+
"""
4325+
metafield(
4326+
"""
4327+
The key for the metafield.
4328+
"""
4329+
key: String!
4330+
4331+
"""
4332+
The container the metafield belongs to. If omitted, the app-reserved namespace will be used.
4333+
"""
4334+
namespace: String
4335+
): Metafield
4336+
43174337
"""
43184338
The name of the selling plan. For example, '6 weeks of prepaid granola, delivered weekly'.
43194339
"""
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
query Input {
2-
allocations {
3-
deliveryAddress {
4-
countryCode
5-
longitude
6-
latitude
7-
}
2+
deliveryAddress{
3+
countryCode
4+
longitude
5+
latitude
86
}
97
}

0 commit comments

Comments
 (0)