Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Re: TimeQuotaExceeded

How to manage line item prices in Vitesy's cart?

NileshTejani
Shopify Partner
203 12 43
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

digitsupCA_0-1669607240327.png

@Vitesy 

- Did we solve your issue? Like & Mark As Solution to help the community

Should you need any direct help:
Get connected: Upwork | Help Center
Reply 1 (1)

jordanholmes
Shopify Partner
152 28 34

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
Jordan Holmes
Shopify Expert and Ruby on Rails Developer
Shopify Partner Directory