I am needing to go directly to checkout after 'cart-submit' event without triggering the side car

enmincenminc Member
1) If I add cart=checkout to the params.url within the cart-submit event function it doesn't work and in fact the call breaks.

Closest solution I have come up with is using the 'cart-submit.done' but sidecar still triggers and loads side car before changing pages.

function cartSubmitDoneHandler(params, next) {
console.info('onsubmit.done');
window.location.href = "https://" + FC.json.config.store_domain + "/cart?cart=checkout";
}
Comments
  • fc_adamfc_adam FoxyCart Team
    @enminc,

    Thanks for detailing what you've tried there. Is there any reason you can't add the cart=checkout parameter to the URL directly instead of needing to handle it in the javascript? The cart-submit event will still be run before the checkout redirect occurs - but only the pre event, the cart-submit.done event won't be run.

    If you do need to handle it in javascript, you'll need to approach it with the pre event like this:
    FC.client.on("cart-submit", function(params) {
    params.data.cart = "checkout";
    });
    You were close with altering the params.url string, but our javascript detects it off of the params.data object which is built when the add to cart is clicked instead. I hope that helps!
  • It needs to be in the JS as I understand it because not all the form elements exist at the time of form.submit() and are dynamically created on('cart-submit').

    Thank you for your suggestion but it's not working for me. I have tried every possible combination along with some additional wild guesses, but not working all together as needed.

    With your suggestion I can get it to go to the checkout directly but only if I do not pass the params.data on the params.url. However, when doing that I get to the checkout with an empty cart.

    And if I pass params.data on to params.url then cart=checkout is also in that and it breaks things and nothing goes to the cart just sidecar works.

    I may just have to go a non-js way as you suggest. It just seems as though it should not be this difficult.
  • fc_adamfc_adam FoxyCart Team
    @enminc,

    Could you perhaps share the code you're attempting that isn't working and we can take a look? The approach I mentioned above works for me, adding the product into the cart and redirecting straight to the checkout. If you'd prefer to keep it private, feel free to whisper it too.

    If you need to only conditionally push the customer direct to checkout based on logic that needs to be in the javascript, then the approach you're trying to take will be the way to go, and we can help you get that working. If that product will always go to checkout though, then including it as a parameter in the actual add to cart will be a clearer way to go.
  • Thanks for your support. Since the particular need is one-off art the moment I decided to just strip out the pieces that I needed and put it all back to a more traditional "static" form format with little js. It seems to be working now. I will be revisiting this again in the future and hopefully have better luck then. Thanks again for the quick turn around on the support
Sign In or Register to comment.