I'm looking for a more elegant solution to set the price of a product based on a percentage of cart $ size.
Here's what I have working so far. In this Shopify Plus store, https://www.bullets2bandages.org/cart/add?id=19593494467, we have a Rush upsell in the cart. The upsell snippet in the cart adds the Rush Order Upgrade product to the cart. Then the cart script sets the price for the Rush product to be 20% of the cart. The script for setting the Rush price is:
# Rush Order
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next unless product.id == 12097978371
subtotal_without_item = Input.cart.subtotal_price_was - line_item.line_price
line_item.change_line_price(subtotal_without_item * 0.2, message: "Rush Order fee is 20%")
end
# end Rush Order
This works but not as elegantly as I'd like. Here are my issues:
So, my question is does anyone know of a more elegant solution? Ideas include:
Thanks for any help.