Skip to content

Commit 889e1f1

Browse files
committed
move location rule template under order routing folder
1 parent f91171e commit 889e1f1

File tree

10 files changed

+221
-82
lines changed

10 files changed

+221
-82
lines changed

order-routing-location-rule/rust/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

order-routing-location-rule/rust/src/main.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
Cargo.lock
3+
.output.graphql

order-routing-location-rule/rust/schema.graphql renamed to order-routing/rust/rankers/default/schema.graphql

Lines changed: 158 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# This file is auto-generated from the current state of the GraphQL API. Instead of editing this file,
2+
# please edit the ruby definition files and run `bin/rails graphql:schema:dump` to regenerate the schema.
3+
#
4+
# If you're just looking to browse, you may find it friendlier to use the graphiql browser which is
5+
# available in services-internal at https://app.shopify.com/services/internal/shops/14168/graphql.
6+
# Check out the "Docs" tab in the top right.
7+
18
schema {
29
query: Input
310
mutation: MutationRoot
@@ -19,7 +26,7 @@ type Attribute {
1926
}
2027

2128
"""
22-
Represents information about the buyer that is interacting with the cart.
29+
Represents information about the buyer that is interacting with the cart. Only set when the buyer is logged in.
2330
"""
2431
type BuyerIdentity {
2532
"""
@@ -67,6 +74,11 @@ type Cart {
6774
"""
6875
cost: CartCost!
6976

77+
"""
78+
A list of lines containing information about the items that can be delivered.
79+
"""
80+
deliverableLines: [DeliverableCartLine!]!
81+
7082
"""
7183
The delivery groups available for the cart based on the buyer's shipping address.
7284
"""
@@ -359,21 +371,6 @@ type CompanyLocation implements HasMetafields {
359371
updatedAt: DateTime!
360372
}
361373

362-
"""
363-
A country which comprises a market.
364-
"""
365-
type Country implements Region {
366-
"""
367-
The two-letter code for the country.
368-
"""
369-
code: CountryCode!
370-
371-
"""
372-
The country name.
373-
"""
374-
name: String!
375-
}
376-
377374
"""
378375
The code designating a country/region, which generally follows ISO 3166-1 alpha-2 guidelines.
379376
If a territory doesn't have a country code value in the `CountryCode` enum, then it might be considered a subdivision
@@ -2514,6 +2511,38 @@ Example values: `"29.99"`, `"29.999"`.
25142511
"""
25152512
scalar Decimal
25162513

2514+
"""
2515+
Represents information about the merchandise in the cart.
2516+
"""
2517+
type DeliverableCartLine {
2518+
"""
2519+
Retrieve a cart line attribute by key.
2520+
2521+
Cart line attributes are also known as line item properties in Liquid.
2522+
"""
2523+
attribute(
2524+
"""
2525+
The key of the attribute to retrieve.
2526+
"""
2527+
key: String
2528+
): Attribute
2529+
2530+
"""
2531+
The ID of the cart line.
2532+
"""
2533+
id: ID!
2534+
2535+
"""
2536+
The merchandise that the buyer intends to purchase.
2537+
"""
2538+
merchandise: Merchandise!
2539+
2540+
"""
2541+
The quantity of the merchandise that the customer intends to purchase.
2542+
"""
2543+
quantity: Int!
2544+
}
2545+
25172546
"""
25182547
List of different delivery method types.
25192548
"""
@@ -2576,7 +2605,7 @@ input FulfillmentGroupRankedLocations {
25762605
"""
25772606
The identifier for the fulfillment group.
25782607
"""
2579-
fulfillmentGroupId: String!
2608+
fulfillmentGroupId: ID!
25802609

25812610
"""
25822611
The ranked locations for this fulfillment group.
@@ -2594,6 +2623,76 @@ input FunctionResult {
25942623
operations: [Operation!]!
25952624
}
25962625

2626+
"""
2627+
Represents a gate configuration.
2628+
"""
2629+
type GateConfiguration implements HasMetafields {
2630+
"""
2631+
An optional string identifier.
2632+
"""
2633+
appId: String
2634+
2635+
"""
2636+
A non-unique string used to group gate configurations.
2637+
"""
2638+
handle: String
2639+
2640+
"""
2641+
The ID of the gate configuration.
2642+
"""
2643+
id: ID!
2644+
2645+
"""
2646+
Returns a metafield by namespace and key that belongs to the resource.
2647+
"""
2648+
metafield(
2649+
"""
2650+
The key for the metafield.
2651+
"""
2652+
key: String!
2653+
2654+
"""
2655+
The namespace for the metafield.
2656+
"""
2657+
namespace: String!
2658+
): Metafield
2659+
}
2660+
2661+
"""
2662+
Represents a connection from a subject to a gate configuration.
2663+
"""
2664+
type GateSubject {
2665+
"""
2666+
The bound gate configuration.
2667+
"""
2668+
configuration(
2669+
"""
2670+
The appId of the gate configurations to search for.
2671+
"""
2672+
appId: String @deprecated(reason: "Use GateSubject.handle to filter gates instead.")
2673+
): GateConfiguration!
2674+
2675+
"""
2676+
The ID of the gate subject.
2677+
"""
2678+
id: ID!
2679+
}
2680+
2681+
"""
2682+
Gate subjects associated to the specified resource.
2683+
"""
2684+
interface HasGates {
2685+
"""
2686+
Returns active gate subjects bound to the resource.
2687+
"""
2688+
gates(
2689+
"""
2690+
The handle of the gate configurations to search for.
2691+
"""
2692+
handle: String
2693+
): [GateSubject!]!
2694+
}
2695+
25972696
"""
25982697
Represents information about the metafields associated to the specified resource.
25992698
"""
@@ -2622,6 +2721,9 @@ Example value: `"gid://shopify/Product/10079785100"`
26222721
"""
26232722
scalar ID
26242723

2724+
"""
2725+
The input object for the function.
2726+
"""
26252727
type Input {
26262728
"""
26272729
Cart.
@@ -2660,7 +2762,7 @@ type InventoryLocation {
26602762
}
26612763

26622764
"""
2663-
Represents the location where the physical good resides.
2765+
Represents the location where the inventory resides.
26642766
"""
26652767
type Location implements HasMetafields {
26662768
"""
@@ -2798,6 +2900,16 @@ type MailingAddress {
27982900
"""
27992901
lastName: String
28002902

2903+
"""
2904+
The approximate latitude of the address.
2905+
"""
2906+
latitude: Float
2907+
2908+
"""
2909+
The approximate longitude of the address.
2910+
"""
2911+
longitude: Float
2912+
28012913
"""
28022914
The full name of the customer, based on firstName and lastName.
28032915
"""
@@ -2834,6 +2946,21 @@ type Market {
28342946
regions: [Region!]!
28352947
}
28362948

2949+
"""
2950+
A country which comprises a market.
2951+
"""
2952+
type MarketRegionCountry implements Region {
2953+
"""
2954+
The two-letter code for the country.
2955+
"""
2956+
code: CountryCode!
2957+
2958+
"""
2959+
The country name.
2960+
"""
2961+
name: String!
2962+
}
2963+
28372964
"""
28382965
The merchandise to be purchased at checkout.
28392966
"""
@@ -2891,11 +3018,11 @@ type MutationRoot {
28913018
}
28923019

28933020
"""
2894-
A list of ranked locations for a fulfillment group.
3021+
An operation to apply to the fulfillment group inventory locations.
28953022
"""
28963023
input Operation {
28973024
"""
2898-
The ranked locations for a fulfillment group.
3025+
Request to rank a fulfillment group's inventory locations.
28993026
"""
29003027
rank: FulfillmentGroupRankedLocations!
29013028
}
@@ -2923,7 +3050,17 @@ type OrderRoutingLocationRule implements HasMetafields {
29233050
"""
29243051
Represents a product.
29253052
"""
2926-
type Product implements HasMetafields {
3053+
type Product implements HasGates & HasMetafields {
3054+
"""
3055+
Returns active gate subjects bound to the resource.
3056+
"""
3057+
gates(
3058+
"""
3059+
The handle of the gate configurations to search for.
3060+
"""
3061+
handle: String
3062+
): [GateSubject!]!
3063+
29273064
"""
29283065
A unique human-friendly string of the product's title.
29293066
"""

order-routing-location-rule/rust/shopify.function.extension.toml.liquid renamed to order-routing/rust/rankers/default/shopify.function.extension.toml.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "{{name}}"
22
type = "{{extensionType}}"
3-
api_version = "2023-04"
3+
api_version = "unstable"
44

55
[build]
66
command = "cargo wasi build --release"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use shopify_function::prelude::*;
2+
use shopify_function::Result;
3+
4+
use serde::{Deserialize, Serialize};
5+
6+
generate_types!(
7+
query_path = "./input.graphql",
8+
schema_path = "./schema.graphql"
9+
);
10+
11+
#[derive(Serialize, Deserialize, Default, PartialEq)]
12+
struct Config {}
13+
14+
#[shopify_function]
15+
fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
16+
let operations = input
17+
.fulfillment_groups
18+
.iter()
19+
.map(|group| {
20+
let fulfillment_group_id = group.id.clone();
21+
let rankings = group
22+
.inventory_locations
23+
.clone()
24+
.unwrap()
25+
.iter()
26+
.map(|inventory_location| {
27+
let location_id = inventory_location.location.id.clone();
28+
output::RankedLocation {
29+
location_id,
30+
rank: 0,
31+
}
32+
})
33+
.collect();
34+
let rank_operation = output::FulfillmentGroupRankedLocations {
35+
fulfillment_group_id,
36+
rankings,
37+
};
38+
output::Operation {
39+
rank: rank_operation,
40+
}
41+
})
42+
.collect();
43+
44+
Ok(output::FunctionResult { operations })
45+
}
46+
47+
#[cfg(test)]
48+
mod tests;

0 commit comments

Comments
 (0)