Personalized checkout and custom promotions with Shopify Scripts
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
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024