Input.cart.line_items.each do |line_item|
if line_item.line_price_changed? == false
product = line_item.variant.product
if line_item.properties.has_key?("_item_type")
mainGroupID="";
if line_item.properties["_item_type"] == "main"
mainGroupID=line_item.properties["_group_id"]
Input.cart.line_items.each do |line_item_inner|
if line_item_inner.properties.has_key?("_item_type") and line_item_inner.properties["_item_type"]=="subitem"
if line_item_inner.properties.has_key?("_group_id") and line_item_inner.properties["_group_id"]==mainGroupID
line_item_inner.change_line_price(line_item_inner.line_price * 0, message: "")
end
end
end
end
end
end
end
Output.cart = Input.cart
Hello,
Maybe try to pull out the line items that you need rather than run through all. This is not tested so you might need to tweak
line_items = Input.cart.line_items.select {|li| li.properties["_item_type"] == "main" }
line_items.each do |line_item|
next if line_item.line_price_changed?
sub_items = Input.cart.line_items.select {|li| (li.properties["_item_type"] == "subitem") && (li.properties["_group_id"] == line_item.properties["_group_id"] ) }
sub_items.each do |item| item.change_line_price(Money.zero, message: "") end
end
Output.cart = Input.cart