1- use shopify_function:: prelude:: * ;
2- use shopify_function:: Result ;
1+ use crate :: input:: InputCart as Cart ;
2+ use crate :: input:: InputCartLinesMerchandise :: ProductVariant ;
3+ use crate :: input:: InputCartLinesMerchandiseOnProductVariant ;
34use crate :: output:: CartLineInput ;
4- use crate :: output:: PriceAdjustment ;
5- use crate :: output:: PriceAdjustmentValue ;
65use crate :: output:: CartOperation ;
76use crate :: output:: ExpandOperation ;
87use crate :: output:: ExpandedItem ;
98use crate :: output:: MergeOperation ;
10- use crate :: input:: InputCart as Cart ;
11- use crate :: input:: InputCartLinesMerchandiseOnProductVariant ;
12- use crate :: input:: InputCartLinesMerchandise :: ProductVariant as ProductVariant ;
9+ use crate :: output:: PriceAdjustment ;
10+ use crate :: output:: PriceAdjustmentValue ;
1311use serde:: { Deserialize , Serialize } ;
12+ use shopify_function:: prelude:: * ;
13+ use shopify_function:: Result ;
1414
1515generate_types ! (
1616 query_path = "./input.graphql" ,
@@ -55,10 +55,12 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
5555 let mut cart_operations: Vec < CartOperation > = get_merge_cart_operations ( & input. cart ) ;
5656 cart_operations. extend ( get_expand_cart_operations ( & input. cart ) ) ;
5757
58- Ok ( output:: FunctionResult { operations : Some ( cart_operations) } )
59- }
58+ Ok ( output:: FunctionResult {
59+ operations : Some ( cart_operations) ,
60+ } )
61+ }
6062
61- // merge operation logic
63+ // merge operation logic
6264
6365fn get_merge_cart_operations ( cart : & Cart ) -> Vec < CartOperation > {
6466 let merge_parent_defintions: Vec < ComponentParent > = get_merge_parent_definitions ( cart) ;
@@ -80,8 +82,8 @@ fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
8082 if let Some ( price_adjustment) = & definition. price_adjustment {
8183 price = Some ( PriceAdjustment {
8284 percentage_decrease : Some ( PriceAdjustmentValue {
83- value : ( * price_adjustment) . to_string ( )
84- } )
85+ value : ( * price_adjustment) . to_string ( ) ,
86+ } ) ,
8587 } ) ;
8688 }
8789
@@ -93,17 +95,17 @@ fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
9395 price : price,
9496 } ;
9597
96- result. push ( CartOperation { merge : Some ( merge_operation) , expand : None } ) ;
98+ result. push ( CartOperation {
99+ merge : Some ( merge_operation) ,
100+ expand : None ,
101+ } ) ;
97102 }
98103 }
99104
100105 return result;
101106}
102107
103- fn get_components_in_cart (
104- cart : & Cart ,
105- definition : & ComponentParent ,
106- ) -> Vec < CartLineInput > {
108+ fn get_components_in_cart ( cart : & Cart , definition : & ComponentParent ) -> Vec < CartLineInput > {
107109 let mut line_results: Vec < CartLineInput > = Vec :: new ( ) ;
108110 for ( reference, quantity) in definition
109111 . component_reference
@@ -120,13 +122,13 @@ fn get_components_in_cart(
120122 }
121123
122124 if let Some ( merchandise) = & variant {
123- if reference == & merchandise. id && & line. quantity >= quantity {
124- line_results. push ( CartLineInput {
125- cart_line_id : line. id . clone ( ) ,
126- quantity : quantity. clone ( ) ,
127- } ) ;
128- break ;
129- }
125+ if reference == & merchandise. id && & line. quantity >= quantity {
126+ line_results. push ( CartLineInput {
127+ cart_line_id : line. id . clone ( ) ,
128+ quantity : quantity. clone ( ) ,
129+ } ) ;
130+ break ;
131+ }
130132 }
131133 }
132134 }
@@ -154,7 +156,9 @@ fn get_merge_parent_definitions(cart: &Cart) -> Vec<ComponentParent> {
154156 return merge_parent_defintions;
155157}
156158
157- fn get_component_parents ( variant : & InputCartLinesMerchandiseOnProductVariant ) -> Vec < ComponentParent > {
159+ fn get_component_parents (
160+ variant : & InputCartLinesMerchandiseOnProductVariant ,
161+ ) -> Vec < ComponentParent > {
158162 let mut component_parents: Vec < ComponentParent > = Vec :: new ( ) ;
159163 if let Some ( component_parents_metafield) = & variant. component_parents {
160164 let value: Vec < ComponentParentMetafield > =
@@ -196,13 +200,17 @@ fn get_expand_cart_operations(cart: &Cart) -> Vec<CartOperation> {
196200 let component_references: Vec < ID > = get_component_references ( & merchandise) ;
197201 let component_quantities: Vec < i64 > = get_component_quantities ( & merchandise) ;
198202
199- if component_references. is_empty ( ) || component_references. len ( ) != component_quantities. len ( ) {
203+ if component_references. is_empty ( )
204+ || component_references. len ( ) != component_quantities. len ( )
205+ {
200206 continue ;
201207 }
202208
203209 let mut expand_relationships: Vec < ExpandedItem > = Vec :: new ( ) ;
204210
205- for ( reference, quantity) in component_references. iter ( ) . zip ( component_quantities. iter ( ) ) {
211+ for ( reference, quantity) in
212+ component_references. iter ( ) . zip ( component_quantities. iter ( ) )
213+ {
206214 let expand_relationship: ExpandedItem = ExpandedItem {
207215 merchandise_id : reference. clone ( ) ,
208216 quantity : quantity. clone ( ) ,
@@ -213,13 +221,16 @@ fn get_expand_cart_operations(cart: &Cart) -> Vec<CartOperation> {
213221
214222 let price: Option < PriceAdjustment > = get_price_adjustment ( & merchandise) ;
215223
216- let expand_operation: ExpandOperation = ExpandOperation {
224+ let expand_operation: ExpandOperation = ExpandOperation {
217225 cart_line_id : line. id . clone ( ) ,
218226 expanded_cart_items : expand_relationships,
219227 price : price,
220228 } ;
221229
222- result. push ( CartOperation { expand : Some ( expand_operation) , merge : None } ) ;
230+ result. push ( CartOperation {
231+ expand : Some ( expand_operation) ,
232+ merge : None ,
233+ } ) ;
223234 }
224235 }
225236
@@ -242,13 +253,15 @@ fn get_component_references(variant: &InputCartLinesMerchandiseOnProductVariant)
242253 return Vec :: new ( ) ;
243254}
244255
245- fn get_price_adjustment ( variant : & InputCartLinesMerchandiseOnProductVariant ) -> Option < PriceAdjustment > {
256+ fn get_price_adjustment (
257+ variant : & InputCartLinesMerchandiseOnProductVariant ,
258+ ) -> Option < PriceAdjustment > {
246259 if let Some ( price_adjustment) = & variant. price_adjustment {
247- return Some ( PriceAdjustment {
248- percentage_decrease : Some ( PriceAdjustmentValue {
249- value : price_adjustment. value . parse ( ) . unwrap ( )
250- } )
251- } ) ;
260+ return Some ( PriceAdjustment {
261+ percentage_decrease : Some ( PriceAdjustmentValue {
262+ value : price_adjustment. value . parse ( ) . unwrap ( ) ,
263+ } ) ,
264+ } ) ;
252265 }
253266
254267 return None ;
0 commit comments