take must be between 1 and 0 script error

Shopify Partner
37 1 9

I have created shopify promo script that adds a free gift if you buy a certain product.
The number of free gifts depends on the number of promotional items. 
The script contains such a condition

    Input.cart.line_items.each do |line_item|
        product = line_item.variant

        if economy_seen && product.id == 26758977847360 && economy_gift_ready
            if line_item.quantity > economy_frames
                new_line_item = line_item.split(take: economy_frames)
                new_line_item.change_line_price(Money.zero, message: "Economy Standing Desk Gift")
                Input.cart.line_items << new_line_item
                line_item.change_line_price(Money.zero, message: "Economy Standing Desk Gift")
            economy_gift_ready = false

economy_seen - promotional product;

product.id == 26758977847360 - free gift;

economy_frames - number of promotional products in cart.. 

script works but I have errors - "take must be between 1 and 0 script' ...

new_line_item = line_item.split(take: economy_frames) -  here I split how many gifts in cart with zero price. 
Why is there an error? Thanks

Replies 2 (2)

Shopify Partner
2 0 0

HI I have same problem did you find solution ?


Shopify Partner
37 1 9

no. I didn't find a solution. But despite the errors, the script works correctly and provides a discount. According to my observations, errors did not affect performance