Thanks for the reminder… Jake O from the Shopify Script Editor team got back to me yesterday from a separate ticket I opened. Jake informed me that I wasn’t using my boolean logic in a way that Ruby wanted me to (I’m new to Ruby). So, I changed my code to reflect that change any everything worked perfectly. Also, there was NO browser session issue… my code only made it appear as such.
This code is really only in an inefficient quick-test state(more looping than needed), but here is the updated code regardless. Thanks!
new logic: spell out boolean “true/false” don’t use 0/1.
#create array of membership product IDs
arry_membership_prodIDs = [4810694164558,4836276764750,6132834468020]
#set indicator for membership exists in the cart
cart_contains_membership = false
Input.cart.line_items.each do |line_item|
#loop over cart items to see if a membership product ID exists
product = line_item.variant.product
next if product.gift_card?
next unless arry_membership_prodIDs.include?(product.id)
#this product exists in the array of membership IDs, set the cart indicator
cart_contains_membership = true
end
if cart_contains_membership == true
#loop over all products again and only discount those products that DO NOT exist in
#the array of membership product IDs
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
if arry_membership_prodIDs.include?(product.id) == false
line_item.change_line_price(line_item.line_price * 0.90, message: "Member Discount")
end
end
end
Output.cart = Input.cart