Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Hello,
I have been running a script to discount all vip members giving a discount and the script was published in the June and till now it was running fine and suddenly yesterday I got an production error saying
# If the customer is a VIP member, give them a discount on all items
DISCOUNT_PERCENT = 0
DISCOUNT_MESSAGE = ''
if !Input.cart.customer.nil?
Input.cart.customer.tags.each do |tag|
if tag.start_with?('Discount: ')
DISCOUNT_PERCENT = (tag.split('%').first).split(' ').last.to_i / 100
DISCOUNT_MESSAGE = tag.split(': ').last + ' OFF'
end
end
end
if DISCOUNT_PERCENT > 0
if Input.cart.discount_code
Input.cart.discount_code.reject(
message: "Discounts can not be used with your everyday discount."
)
end
Input.cart.line_items.each do |line_item|
if !line_item.variant.compare_at_price.nil?
if (line_item.variant.compare_at_price * line_item.quantity * (1-DISCOUNT_PERCENT)) <= line_item.line_price
line_item.change_line_price(line_item.variant.compare_at_price * line_item.quantity * (1-DISCOUNT_PERCENT),message: DISCOUNT_MESSAGE)
new_properties = line_item.properties
new_properties.merge!({"_discount_note" => DISCOUNT_MESSAGE})
line_item.change_properties(new_properties, message: "")
else
new_properties = line_item.properties
new_properties.merge!({"_discount_note" => "Sale price less than discount"})
line_item.change_properties(new_properties, message: "")
end
else
line_item.change_line_price(line_item.line_price * (1-DISCOUNT_PERCENT), message: DISCOUNT_MESSAGE)
new_properties = line_item.properties
new_properties.merge!({"_discount_note" => DISCOUNT_MESSAGE})
line_item.change_properties(new_properties, message: "")
end
end
end
Output.cart = Input.cart
You have code in place that is nth scaling. One you have something that loops over customer tags, and the other that loops over all the items in the cart.So I could see how a customer will lots or tags - or a larger cart - could push you closer to the existing limits.
I would like to see you use two tags since it looks like you're using a tag to drive a discount. A customer (that knows how) could add tags to their own account so you're opening yourself to some risk here. A second tag would give you added security, and make it harder for someone to guess what it is. Would strongly recommended you don't post the shop url here if you are not going to change that.
This is happening for us as well. And has been posted here: https://community.shopify.com/c/Script-Editor/Suddenly-got-production-error-TimeQuotaExceeded/td-p/4...
We have scripts that are very basic being applied to checkouts with only 1 item where this is occurring. Debug in editor shows 0% cpu and 6% memory. Randomly happened 5x today.
I have emailed our Shopify rep and I ll try to post here if there is any resolution.
Hi Johanson,
The reason shopify support suggested me was this time quota error occurs if the shopify's server does not recieve the response from the client side. They have set up the server timeout for the scripts to run which i forgot what was the actual number but if it falls out of range then this error is triggered and is happens very random and after certain period of time. I let the front end team to look forward to my scripts as that was in place for atleast one year and they said it is fine and to ignore this error.
Looking at your response seems like you have ran into similar issue with us where they dont have any resolution but if you came across a lot of issues then let the technical support to review your script and that way you might be able to find out the resolution.