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
convert above script to shopify function
@NileshTejani Here is the converted code into Shopify Liquid code
{% for line_item in cart.line_items %}
{% if line_item.line_price_changed? == false %}
{% assign product = line_item.variant.product %}
{% if line_item.properties._item_type %}
{% assign mainGroupID = "" %}
{% if line_item.properties._item_type == "main" %}
{% assign mainGroupID = line_item.properties._group_id %}
{% for line_item_inner in cart.line_items %}
{% if line_item_inner.properties._item_type and line_item_inner.properties._item_type == "subitem" %}
{% if line_item_inner.properties._group_id and line_item_inner.properties._group_id == mainGroupID %}
{% assign new_price = 0 %}
{% assign message = "" %}
{% assign line_price = line_item_inner.line_price %}
{% assign updated_line_price = line_price | times: new_price %}
{% assign line_price_difference = line_price | minus: updated_line_price %}
{% assign line_price_difference_abs = line_price_difference | abs %}
{% assign message = "Adjusted price to $0.00 for group " | append: mainGroupID %}
{% assign line_item_inner = line_item_inner.change_line_price(updated_line_price, message: message) %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% assign output_cart = cart %}
You have to modify little bit variable or syntax to work this code, i have just converted into liquid syntax.
Please like and mark as solve!
but this will work where i add this code?
@saim007 i need input graph ql query for this
https://prnt.sc/pNzjKz9bsLPl
@Nick_Wesselman could you help me on it
At the moment the Discounts API doesn’t support line item discounts, but you might see if a product discount can meet your requirements.
https://shopify.dev/docs/apps/selling-strategies/discounts/experience
https://shopify.dev/docs/api/functions/reference/product-discounts
@Nick_Wesselman yes i need help to convert my ruby script to input query like this could you help me
query Input {
cart {
lines {
id
merchandise {
id
}
}
}
}
@Nick_Wesselman could you tell me what input query i need to write for this
query Input {
cart {
lines {
quantity
attribute{
key
value
}
merchandise {
__typename
…on ProductVariant {
id
}
}
}
}
discountNode {
metafield1:metafield(namespace: “$app:volume-discount”, key: “function-configuration”) {
value
}
metafield2: metafield(namespace: “$app:volume-discount”, key: “key2”) {
value
}
}
}
how i get all line item property and apply discount when it has property
could you give me full code cart terraform api ?