In the Shopify Script Editor, it is a common use case to “split” cart lines/rows when running a “2 for $25” sale.
Products can have different prices, but in bundles of two they need to be obviously, $12.50 each so the Cart Transform not Discount Function would need to be called.
A sample cart can have two cart lines of eligible products, one with quantity 3, another with quantity 2. Thus the cart would need to have an additional line added, and one of the lines quantity reduced. Is this possible or is their something like the “split” function in the Shopify Script editor?
Example from Shopify Github repo for Script Editor below:
cart.line_items.each do |line_item|
product = line_item.variant.product
# If not perfect, split the cart with elgible items into QTY of 1
if line_item.quantity > 1 && !product.gift_card? && product.tags.include?(promo_code)
item = line_item.split(take: line_item.quantity-1)
# Insert the newly-created item in the cart, right after the original item
position = cart.line_items.find_index(line_item)
cart.line_items.insert(position + 1, item)
end
end
Again, I can’t use the Discount API as product prices might be $20 for one product and $25 for another if eligible they would need to be reduced to $12.50, and I might need to the split as above (Production script for $2 for 25 promo.
Is this possible?
Thanks.