@@ -3,13 +3,11 @@ use shopify_function::Result;
3
3
4
4
use serde:: { Deserialize , Serialize } ;
5
5
6
- // Use the shopify_function crate to generate structs for the function input and output
7
6
generate_types ! (
8
7
query_path = "./input.graphql" ,
9
8
schema_path = "./schema.graphql"
10
9
) ;
11
10
12
- // Create a structure that matches the JSON structure that you'll use for your configuration
13
11
#[ derive( Serialize , Deserialize , PartialEq ) ]
14
12
#[ serde( rename_all( deserialize = "camelCase" ) ) ]
15
13
struct Configuration {
@@ -21,7 +19,6 @@ impl Configuration {
21
19
const DEFAULT_QUANTITY : i64 = 999 ;
22
20
const DEFAULT_PERCENTAGE : f64 = 0.0 ;
23
21
24
- // Parse the JSON metafield value using serde
25
22
fn from_str ( value : & str ) -> Self {
26
23
serde_json:: from_str ( value) . expect ( "Unable to parse configuration value from metafield" )
27
24
}
@@ -43,7 +40,6 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
43
40
discount_application_strategy : output:: DiscountApplicationStrategy :: FIRST ,
44
41
} ;
45
42
46
- // Get the configuration from the metafield on your function owner
47
43
let config = match input. discount_node . metafield {
48
44
Some ( input:: InputDiscountNodeMetafield { value } ) =>
49
45
Configuration :: from_str ( & value) ,
@@ -52,7 +48,6 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
52
48
53
49
let targets = input. cart . lines
54
50
. iter ( )
55
- // Use the configured quantity instead of a hardcoded value
56
51
. filter ( |line| line. quantity >= config. quantity )
57
52
. filter_map ( |line| match & line. merchandise {
58
53
input:: InputCartLinesMerchandise :: ProductVariant ( variant) => Some ( variant) ,
@@ -75,7 +70,6 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
75
70
discounts : vec ! [ output:: Discount {
76
71
message: None ,
77
72
targets,
78
- // Use the configured percentage instead of a hardcoded value
79
73
value: output:: Value {
80
74
fixed_amount: None ,
81
75
percentage: Some ( output:: Percentage {
0 commit comments