I have created a cart transform function to create a bundle structure on cart which was working fine and I had a field “Fixture type” that I was storing in lineitem properties when adding to cart
This field can also be edited on the cart page so i used cart change api to modify it on cart page
this is my Cart transform functon in rust
use shopify_function::prelude::*;
use shopify_function::Result;
use std::collections::HashMap;
#[allow(clippy::upper_case_acronyms)]
type URL = String;
#[shopify_function_target(query_path = "src/run.graphql", schema_path = "schema.graphql")]
fn run(_input: input::ResponseData) -> Result<output::FunctionRunResult> {
let mut bundle_map = HashMap::new();
// Group line items by bundleId
for line in &_input.cart.lines {
if let Some(bundle_id) = &line.bundle_id {
bundle_map.entry(bundle_id.value.clone())
.or_insert_with(Vec::new)
.push(line);
}
}
// Create merge operations for each bundle group
let operations: Vec<output::CartOperation> = bundle_map.into_iter().map(|(_, lines)| {
let parent_variant_id = lines[0].parent_product.as_ref()
.and_then(|attr| {
attr.value.as_ref().and_then(|value| {
// Replace `=>` with `:` to make the string valid JSON
let fixed_value = value.replace("=>", ":");
// Try to parse the fixed JSON string
if let Ok(parsed_value) = serde_json::from_str::<serde_json::Value>(&fixed_value) {
parsed_value.get("defaultVariantId")?.as_str().map(|s| s.to_string())
} else {
None
}
})
})
.unwrap_or_default();
let parent_image_url = lines[0].parent_product.as_ref()
.and_then(|attr| {
attr.value.as_ref().and_then(|value| {
let fixed_value = value.replace("=>", ":");
// Try to parse the fixed JSON string
if let Ok(parsed_value) = serde_json::from_str::<serde_json::Value>(&fixed_value) {
parsed_value.get("imageUrl")?.as_str().map(|s| s.to_string())
} else {
None
}
})
});
let fixture_type = lines[0]
.fixture_type
.as_ref()
.and_then(|fixture| fixture.value.clone())
.unwrap_or_default();
let attributes = if !fixture_type.is_empty() {
let mut combined_attributes = Vec::new();
if !fixture_type.is_empty() {
combined_attributes.push(output::AttributeOutput {
key: "Fixture Type".to_string(),
value: fixture_type,
});
}
Some(combined_attributes)
} else {
None
};
let cart_lines = lines.iter().map(|line| {
output::CartLineInput {
cart_line_id: line.id.clone(),
quantity: 1,
}
}).collect();
output::CartOperation::Merge(output::MergeOperation {
cart_lines,
parent_variant_id: parent_variant_id,
title: None,
attributes,
image: match parent_image_url {
Some(url) if !url.is_empty() => Some(output::ImageInput { url }),
_ => None, // Explicitly handle None or empty string
},
price: None,
})
}).collect();
Ok(output::FunctionRunResult { operations })
}
and this is my graphql file
query Input {
cart {
lines {
id
bundleId : attribute(key: "_bundleId"){
value
}
parentProduct : attribute(key: "_parentProduct"){
value
}
fixtureType : attribute(key: "Fixture Type"){
value
}
itemClass : attribute(key: "_className"){
value
}
itemSku : attribute(key: "PRODUCT SKU"){
value
}
}
}
}
this is how a bundle looks on cart page
change.js api payload to modify the properties for the relevent lineitem
route : /cart/change.js
{
"line": "1",
"properties": {
"Fixture Type": "12323"
}
}
cart.json response before and after hitting the change.js api
this was working totally fine 3 to 4 days ago but suddenly on friday this api broke the bundle structure
it seems before it broke it was modifying the lineitem properties of the parent item that was part of the bundle
but now it is somehow modifying the lineitem properties for the bundle child items that could be the reason why the script is breaking because the bundle id and rest of the lineitem properties are not there anymore in child items
But this was working fine a while ago
Can anyone assist me in this , is this something wrong with the api assuming the recent new release from shopify or is there some issue in the code that i am not able to identify
Any support is Appreciated
Best Regards