-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from Shopify/dc-local-pickup
Update local pickup examples
- Loading branch information
Showing
9 changed files
with
120 additions
and
93 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...javascript/local-pickup-delivery-option-generators/default/locales/en.default.json.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "{{name}}", | ||
"description": "{{name}}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 18 additions & 6 deletions
24
.../javascript/local-pickup-delivery-option-generators/default/shopify.extension.toml.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
name = "{{name}}" | ||
type = "local_pickup_delivery_option_generator" | ||
{% if uid %}uid = "{{ uid }}"{% endif %} | ||
api_version = "unstable" | ||
|
||
[build] | ||
command = "" | ||
path = "dist/function.wasm" | ||
[[extensions]] | ||
name = "t:name" | ||
handle = "{{handle}}" | ||
type = "function" | ||
{% if uid %}uid = "{{ uid }}"{% endif %} | ||
|
||
[[extensions.targeting]] | ||
target = "purchase.local-pickup-delivery-option-generator.run" | ||
input_query = "src/run.graphql" | ||
export = "run" | ||
|
||
[extensions.build] | ||
command = "" | ||
path = "dist/function.wasm" | ||
|
||
[extensions.ui.paths] | ||
create = "/" | ||
details = "/" |
68 changes: 1 addition & 67 deletions
68
order-routing/javascript/local-pickup-delivery-option-generators/default/src/index.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1 @@ | ||
{%- if flavor contains "vanilla-js" -%} | ||
// @ts-check | ||
|
||
/** | ||
* @typedef {import("../generated/api").InputQuery} InputQuery | ||
* @typedef {import("../generated/api").FunctionResult} FunctionResult | ||
*/ | ||
|
||
/** | ||
* @type {FunctionResult} | ||
*/ | ||
const DELIVERY_OPTION = { | ||
operations: [ | ||
{ | ||
add: { | ||
title: "Main St.", | ||
cost: 1.99, | ||
pickupLocation: { | ||
locationHandle: "2578303", | ||
pickupInstruction: "Usually ready in 24 hours." | ||
} | ||
} | ||
} | ||
], | ||
}; | ||
|
||
export default /** | ||
* @param {InputQuery} input | ||
* @returns {FunctionResult} | ||
*/ | ||
(input) => { | ||
const configuration = JSON.parse( | ||
input?.deliveryOptionGenerator?.metafield?.value ?? "{}" | ||
); | ||
|
||
return DELIVERY_OPTION; | ||
}; | ||
{%- elsif flavor contains "typescript" -%} | ||
import { | ||
InputQuery, | ||
FunctionResult, | ||
} from "../generated/api"; | ||
|
||
const DELIVERY_OPTION: FunctionResult = { | ||
operations: [ | ||
{ | ||
add: { | ||
title: "Main St.", | ||
cost: 1.99, | ||
pickupLocation: { | ||
locationHandle: "2578303", | ||
pickupInstruction: "Usually ready in 24 hours." | ||
} | ||
} | ||
} | ||
], | ||
}; | ||
|
||
type Configuration = {}; | ||
|
||
export default (input: InputQuery): FunctionResult => { | ||
const configuration: Configuration = JSON.parse( | ||
input?.deliveryOptionGenerator?.metafield?.value ?? "{}" | ||
); | ||
return DELIVERY_OPTION; | ||
}; | ||
{%- endif -%} | ||
export * from './run'; |
2 changes: 1 addition & 1 deletion
2
...n-generators/default/input.graphql.liquid → ...generators/default/src/run.graphql.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
query Input { | ||
query RunInput { | ||
cart { | ||
lines { | ||
id | ||
|
61 changes: 61 additions & 0 deletions
61
order-routing/javascript/local-pickup-delivery-option-generators/default/src/run.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{%- if flavor contains "vanilla-js" -%} | ||
// @ts-check | ||
|
||
/** | ||
* @typedef {import("../generated/api").RunInput} RunInput | ||
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult | ||
*/ | ||
|
||
/** | ||
* @param {RunInput} input | ||
* @returns {FunctionRunResult} | ||
*/ | ||
export function run(input) { | ||
const configuration = JSON.parse( | ||
input?.deliveryOptionGenerator?.metafield?.value ?? "{}" | ||
); | ||
|
||
return { | ||
operations: [ | ||
{ | ||
add: { | ||
title: "Main St.", | ||
cost: 1.99, | ||
pickupLocation: { | ||
locationHandle: "2578303", | ||
pickupInstruction: "Usually ready in 24 hours." | ||
} | ||
} | ||
} | ||
], | ||
}; | ||
} | ||
{%- elsif flavor contains "typescript" -%} | ||
import { | ||
RunInput, | ||
FunctionRunResult, | ||
} from "../generated/api"; | ||
|
||
type Configuration = {}; | ||
|
||
export function run(input: RunInput): FunctionRunResult { | ||
const configuration: Configuration = JSON.parse( | ||
input?.deliveryOptionGenerator?.metafield?.value ?? "{}" | ||
); | ||
|
||
return { | ||
operations: [ | ||
{ | ||
add: { | ||
title: "Main St.", | ||
cost: 1.99, | ||
pickupLocation: { | ||
locationHandle: "2578303", | ||
pickupInstruction: "Usually ready in 24 hours." | ||
} | ||
} | ||
} | ||
], | ||
}; | ||
} | ||
{%- endif -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...uting/rust/local-pickup-delivery-option-generators/default/locales/en.default.json.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "{{name}}", | ||
"description": "{{name}}" | ||
} |
28 changes: 18 additions & 10 deletions
28
...outing/rust/local-pickup-delivery-option-generators/default/shopify.extension.toml.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
name = "{{name}}" | ||
type = "local_pickup_delivery_option_generator" | ||
{% if uid %}uid = "{{ uid }}"{% endif %} | ||
api_version = "unstable" | ||
|
||
[build] | ||
command = "cargo build --target=wasm32-wasip1 --release" | ||
path = "target/wasm32-wasip1/release/{{name | replace: " ", "-" | downcase}}.wasm" | ||
watch = [ "src/**/*.rs" ] | ||
[[extensions]] | ||
name = "t:name" | ||
handle = "{{handle}}" | ||
type = "function" | ||
{% if uid %}uid = "{{ uid }}"{% endif %} | ||
|
||
[[extensions.targeting]] | ||
target = "purchase.local-pickup-delivery-option-generator.run" | ||
input_query = "src/run.graphql" | ||
export = "run" | ||
|
||
[extensions.build] | ||
command = "cargo build --target=wasm32-wasip1 --release" | ||
path = "target/wasm32-wasip1/release/{{handle | replace: " ", "-" | downcase}}.wasm" | ||
watch = [ "src/**/*.rs" ] | ||
|
||
[ui.paths] | ||
create = "/" | ||
details = "/" | ||
[extensions.ui.paths] | ||
create = "/" | ||
details = "/" |