Skip to content

Commit 7702db9

Browse files
author
Ryan Workman
committed
Fix issue with merge not sending back correct quantity
1 parent 67bbd22 commit 7702db9

File tree

2 files changed

+8
-32
lines changed
  • checkout/rust/cart-transform/bundles/src
  • sample-apps/bundles-cart-transform/extensions/cart-merge-expand/src

2 files changed

+8
-32
lines changed

checkout/rust/cart-transform/bundles/src/main.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
6565
let mut result: Vec<CartOperation> = Vec::new();
6666

6767
for definition in merge_parent_defintions.iter() {
68-
let (components_in_cart, parent_variant_quantity) =
69-
get_components_in_cart(cart, definition);
68+
let components_in_cart = get_components_in_cart(cart, definition);
7069
if components_in_cart.len() == definition.component_reference.len() {
7170
let cart_lines: Vec<CartLineInput> = components_in_cart
7271
.iter()
7372
.map(|component| CartLineInput {
7473
cart_line_id: component.cart_line_id.clone(),
75-
quantity: parent_variant_quantity * component.quantity,
74+
quantity: component.quantity.clone(),
7675
})
7776
.collect();
7877

@@ -104,9 +103,8 @@ fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
104103
fn get_components_in_cart(
105104
cart: &Cart,
106105
definition: &ComponentParent,
107-
) -> (Vec<CartLineInput>, i64) {
106+
) -> Vec<CartLineInput> {
108107
let mut line_results: Vec<CartLineInput> = Vec::new();
109-
let mut maximum_available_component: Vec<i64> = Vec::new();
110108
for (reference, quantity) in definition
111109
.component_reference
112110
.iter()
@@ -127,23 +125,13 @@ fn get_components_in_cart(
127125
cart_line_id: line.id.clone(),
128126
quantity: quantity.clone(),
129127
});
130-
let maximum_available = if quantity > &0 {
131-
line.quantity / quantity
132-
} else {
133-
0
134-
};
135-
maximum_available_component.push(maximum_available);
136128
break;
137129
}
138130
}
139131
}
140132
}
141-
let parent_variant_quantity: i64 = match maximum_available_component.iter().min() {
142-
Some(available) => available.clone(),
143-
None => 0,
144-
};
145133

146-
return (line_results, parent_variant_quantity);
134+
return line_results;
147135
}
148136

149137
fn get_merge_parent_definitions(cart: &Cart) -> Vec<ComponentParent> {

sample-apps/bundles-cart-transform/extensions/cart-merge-expand/src/main.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
6565
let mut result: Vec<CartOperation> = Vec::new();
6666

6767
for definition in merge_parent_defintions.iter() {
68-
let (components_in_cart, parent_variant_quantity) =
69-
get_components_in_cart(cart, definition);
68+
let components_in_cart = get_components_in_cart(cart, definition);
7069
if components_in_cart.len() == definition.component_reference.len() {
7170
let cart_lines: Vec<CartLineInput> = components_in_cart
7271
.iter()
7372
.map(|component| CartLineInput {
7473
cart_line_id: component.cart_line_id.clone(),
75-
quantity: parent_variant_quantity * component.quantity,
74+
quantity: component.quantity.clone(),
7675
})
7776
.collect();
7877

@@ -104,9 +103,8 @@ fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
104103
fn get_components_in_cart(
105104
cart: &Cart,
106105
definition: &ComponentParent,
107-
) -> (Vec<CartLineInput>, i64) {
106+
) -> Vec<CartLineInput> {
108107
let mut line_results: Vec<CartLineInput> = Vec::new();
109-
let mut maximum_available_component: Vec<i64> = Vec::new();
110108
for (reference, quantity) in definition
111109
.component_reference
112110
.iter()
@@ -127,23 +125,13 @@ fn get_components_in_cart(
127125
cart_line_id: line.id.clone(),
128126
quantity: quantity.clone(),
129127
});
130-
let maximum_available = if quantity > &0 {
131-
line.quantity / quantity
132-
} else {
133-
0
134-
};
135-
maximum_available_component.push(maximum_available);
136128
break;
137129
}
138130
}
139131
}
140132
}
141-
let parent_variant_quantity: i64 = match maximum_available_component.iter().min() {
142-
Some(available) => available.clone(),
143-
None => 0,
144-
};
145133

146-
return (line_results, parent_variant_quantity);
134+
return line_results;
147135
}
148136

149137
fn get_merge_parent_definitions(cart: &Cart) -> Vec<ComponentParent> {

0 commit comments

Comments
 (0)