11use shopify_function:: prelude:: * ;
22use shopify_function:: Result ;
33
4+
5+ // [START discount-function.run.cart]
46#[ shopify_function_target(
57 query_path = "src/cart_lines_discounts_generate_run.graphql" ,
68 schema_path = "schema.graphql"
79) ]
810fn cart_lines_discounts_generate_run (
9- input : cart_lines_discounts_generate_run :: input:: ResponseData ,
10- ) -> Result < cart_lines_discounts_generate_run :: output:: CartLinesDiscountsGenerateRunResult > {
11+ input : input:: ResponseData ,
12+ ) -> Result < output:: CartLinesDiscountsGenerateRunResult > {
1113 let max_cart_line = input
1214 . cart
1315 . lines
@@ -24,15 +26,15 @@ fn cart_lines_discounts_generate_run(
2426 let has_order_discount_class = input
2527 . discount
2628 . discount_classes
27- . contains ( & cart_lines_discounts_generate_run :: input:: DiscountClass :: ORDER ) ;
29+ . contains ( & input:: DiscountClass :: ORDER ) ;
2830 let has_product_discount_class = input
2931 . discount
3032 . discount_classes
31- . contains ( & cart_lines_discounts_generate_run :: input:: DiscountClass :: PRODUCT ) ;
33+ . contains ( & input:: DiscountClass :: PRODUCT ) ;
3234
3335 if !has_order_discount_class && !has_product_discount_class {
3436 return Ok (
35- cart_lines_discounts_generate_run :: output:: CartLinesDiscountsGenerateRunResult {
37+ output:: CartLinesDiscountsGenerateRunResult {
3638 operations : vec ! [ ] ,
3739 } ,
3840 ) ;
@@ -42,17 +44,17 @@ fn cart_lines_discounts_generate_run(
4244
4345 // Check if the discount has the ORDER class
4446 if has_order_discount_class {
45- operations. push ( cart_lines_discounts_generate_run :: output:: CartOperation :: OrderDiscountsAdd (
46- cart_lines_discounts_generate_run :: output:: OrderDiscountsAddOperation {
47- selection_strategy : cart_lines_discounts_generate_run :: output:: OrderDiscountSelectionStrategy :: FIRST ,
48- candidates : vec ! [ cart_lines_discounts_generate_run :: output:: OrderDiscountCandidate {
49- targets: vec![ cart_lines_discounts_generate_run :: output:: OrderDiscountCandidateTarget :: OrderSubtotal (
50- cart_lines_discounts_generate_run :: output:: OrderSubtotalTarget {
47+ operations. push ( output:: CartOperation :: OrderDiscountsAdd (
48+ output:: OrderDiscountsAddOperation {
49+ selection_strategy : output:: OrderDiscountSelectionStrategy :: FIRST ,
50+ candidates : vec ! [ output:: OrderDiscountCandidate {
51+ targets: vec![ output:: OrderDiscountCandidateTarget :: OrderSubtotal (
52+ output:: OrderSubtotalTarget {
5153 excluded_cart_line_ids: vec![ ] ,
5254 } ,
5355 ) ] ,
5456 message: Some ( "10% OFF ORDER" . to_string( ) ) ,
55- value: cart_lines_discounts_generate_run :: output:: OrderDiscountCandidateValue :: Percentage ( cart_lines_discounts_generate_run :: output:: Percentage {
57+ value: output:: OrderDiscountCandidateValue :: Percentage ( output:: Percentage {
5658 value: Decimal ( 10.0 ) ,
5759 } ) ,
5860 conditions: None ,
@@ -64,16 +66,16 @@ fn cart_lines_discounts_generate_run(
6466
6567 // Check if the discount has the PRODUCT class
6668 if has_product_discount_class {
67- operations. push ( cart_lines_discounts_generate_run :: output:: CartOperation :: ProductDiscountsAdd (
68- cart_lines_discounts_generate_run :: output:: ProductDiscountsAddOperation {
69- selection_strategy : cart_lines_discounts_generate_run :: output:: ProductDiscountSelectionStrategy :: FIRST ,
70- candidates : vec ! [ cart_lines_discounts_generate_run :: output:: ProductDiscountCandidate {
71- targets: vec![ cart_lines_discounts_generate_run :: output:: ProductDiscountCandidateTarget :: CartLine ( cart_lines_discounts_generate_run :: output:: CartLineTarget {
69+ operations. push ( output:: CartOperation :: ProductDiscountsAdd (
70+ output:: ProductDiscountsAddOperation {
71+ selection_strategy : output:: ProductDiscountSelectionStrategy :: FIRST ,
72+ candidates : vec ! [ output:: ProductDiscountCandidate {
73+ targets: vec![ output:: ProductDiscountCandidateTarget :: CartLine ( output:: CartLineTarget {
7274 id: max_cart_line. id. clone( ) ,
7375 quantity: None ,
7476 } ) ] ,
7577 message: Some ( "20% OFF PRODUCT" . to_string( ) ) ,
76- value: cart_lines_discounts_generate_run :: output:: ProductDiscountCandidateValue :: Percentage ( cart_lines_discounts_generate_run :: output:: Percentage {
78+ value: output:: ProductDiscountCandidateValue :: Percentage ( output:: Percentage {
7779 value: Decimal ( 20.0 ) ,
7880 } ) ,
7981 associated_discount_code: None ,
@@ -83,8 +85,9 @@ fn cart_lines_discounts_generate_run(
8385 }
8486
8587 Ok (
86- cart_lines_discounts_generate_run :: output:: CartLinesDiscountsGenerateRunResult {
88+ output:: CartLinesDiscountsGenerateRunResult {
8789 operations,
8890 } ,
8991 )
9092}
93+ // [END discount_function.run.cart]
0 commit comments