Hey Replo people, I have a question regarding repl...
# replo-help
w
Hey Replo people, I have a question regarding replo interaction chaining. We had some somewhat rare but weird page behavior and I'm trying to clarify some things. We got a simple interaction chain on a page that Clears Cart > Adds Product to Cart > Runs Javascript (script fetches cart.js and adds gift items based on what product variant has just been added, then sends customer to checkout). My question would be if it is possible that replo executes the "Run Javascript" interaction BEFORE the product has actually been added to cart by the "Add Product to Cart" (as in received the HTTP response from the shopify API)? That would explain the issue we've been having where on a rare occasion it looks like the JS is executed too early and cart data from cart.js fetched by the script doesn't not include the item that was supposed to be added by the "Add Product to Cart" interaction.
p
Hey there! Andres here from the Replo team! Please let me understand this and search for the best solution here!
Ok, so you want to re-arrange the interactions ​*Clear cart >> Run JS >> Add product to cart >> checkout *​right? Note that the ​*Add product to cart *​contains a "go to checkout" after, which can be used as well to redirect your visitors to the checkout. So the redirect to checkout shouldn't be on the ​*Run JS *​ But yeah, this can be achieved by following the steps here https://support.replo.app/articles/1713116416-interactions
If you want I can also show in a short video how to reorder the interactions
w
Hey Andres, no I don't want to re-arrange the interactions. That's how they should be by design. Product is added by "Add product to cart" interaction, then I add extra gift items based on what product variant has just been added.
So I need to use javascript for that, which fetches cart.js to check what specific variant/option the customer has added. This seems to work fine 99% of the time. But sometimes it does fail.
p
Hmmm I see. May I take a look at your page so I can understand what the code does? Perhaps this is something to do with some function not waiting enough kind of thing
Normally we are not supposed to check custom code, but I liked the way you interacted with me, so I'm gonna go off road for this time :)
w
I appreciate it. Is it alright if I DM you the link?
p
Yeah, I just need the Replo editor URL to check
You can send it over here
The script is pretty simple and uses promises. I had similar (but also very rare) problems when adding extra items with JS on a completely different store too.
If you can confirm that "Add Product to Cart" interaction does indeed wait for the shopify API response before moving onto the next step I won't have any more questions for you 🙂
p
Well, I've checked the code, and it looks really neat to me, maybe what could you implement is async/await as I do not see any new Promise though... Also, as far as I know yes it does, since when setting the ATC button to go to checkout directly the products are already on the cart by that time
w
Yeah, I'm certain that replo waits for the API response when this option is enabled. But I'm not so certain that it does when it's disabled.
Also the JS code uses promise chaining with .then()
p
Let me ask the engenieering team this and I'll be right back!
❤️ 1
Ohhh yeah, you're right, haven't looked at a JS code in a long time than I forgot about how promises are handled lol
Ok, I've asked the team about this, just waiting confirmation!
w
Awesome, thank you so much man. This has been a real headscratcher
p
Random suggestion, what if you add before the redirect to checkout a timer of, idk <1s so the products are indeed added to the cart?
Ok, I've got confirmation of the engenieering team, and they've confirmed that it does in fact wait for the API response before moving on!
w
Yeah, I'll probably have to do something along the lines of that. I had an extra check in there for a little while that checks if the product_id that is added by "Add Product to Cart" exists. But when testing we found other possible edge case where if a customer comes back from checkout (so this item now exists in cart) the purchase flow can break again in weird ways.
Welp, that's very odd then. I'll try and figure something out. Thank you for your help.
p
Hmmm yeah, if we can be of any help don't doubt messaging us from the in-app chat!!
w
Looks like I might've found the culprit, the "Intelligems" app
p
That makes sense haha
w
If you're curious it looks like intelligems calls the update.js to add some custom ID attribute to cart. Replo then calls add.js. But if request timing isn't instant a weird thing can happen where cart.js request marked by number 4 has 0 cart items and only contains that cart attribute from intelligems heh. Just in case someone else comes to you with similar problems.
p
Hmmmmm interesting, thanks for the info!!