kalimati Posted August 19, 2022 Share Posted August 19, 2022 In the demo template, the add-to-cart triggers an ajax call via htmx. In my case the client will order one variant (training program) at a time. I would like to move the user directly to the checkout page once he clicks on add to cart. How can I achieve that? Thanks. Link to comment Share on other sites More sharing options...
flydev Posted August 19, 2022 Share Posted August 19, 2022 Just an idea as I dont have module v2. Maybe Kongondo will have a better solution. You can try adding the hx-redirect header to the request and htmx will redirect to the value of the header, eg, with custom markup: <div hx-post="{$config->urls->root}padloper/add/" hx-headers='{"hx-redirect": "{$config->urls->root}pad/checkout/"}'>Add to Cart</div> More infos: https://docs.kongondo.com/start/customise-markup.html#padloper-partial-templates-snippets https://htmx.org/attributes/hx-headers/ https://htmx.org/docs/#response-headers 1 Link to comment Share on other sites More sharing options...
kalimati Posted August 20, 2022 Author Share Posted August 20, 2022 Thanks for your response, flydev. I am generating the add to cart form using a function. $config->urls->root does not work inside it and so I am hard coding the URLs /padloper/add/ or /checkout/ where required. I tried your code using hx-redirect. It worked partially. It added the product to the cart and redirected but to the backend to a URL like http://localhost/processwire/shop/padloper/products/product-name/variant-name/?productId=1429&variationId=0&product-title=product-title%3A+attribute1-option+%2F+attribute2-option&quantity=1&totalQty=1&numberOfTitles=1&totalAmount=Rs 1.500%2C00 Link to comment Share on other sites More sharing options...
flydev Posted August 20, 2022 Share Posted August 20, 2022 Ok, then if you got redirected, it's a good thing. If you code the url, even hardcoded, you should be redirected to the checkout, but not in the admin. Link to comment Share on other sites More sharing options...
kongondo Posted September 4, 2022 Share Posted September 4, 2022 (edited) Hi @kalimati, Apologies for the late response. I wasn't able to use the excellent idea by @flydev ??, i.e. HX-Redirect. It wouldn't work for me. Nothing happened at all. However, we can use htmx:afterSettle and redirect using vanilla JavaScript. I have created a demo for the whole thing here in Demo-4 in the demos repo. See the README for more details. Please let me know if you have any questions. Next I'll work on a demo with respect to your question about a minimal checkout form. Edited September 4, 2022 by kongondo 2 Link to comment Share on other sites More sharing options...
kongondo Posted September 4, 2022 Share Posted September 4, 2022 On 8/20/2022 at 7:13 AM, kalimati said: $config->urls->root does not work inside it You cannot use $config (or other variables such as $page, $pages, etc) inside a function. They are out of scope. Use wire('config') instead. 2 Link to comment Share on other sites More sharing options...
kongondo Posted September 5, 2022 Share Posted September 5, 2022 On 9/4/2022 at 4:18 PM, kongondo said: Next I'll work on a demo with respect to your question about a minimal checkout form. Done! @kalimati Please see Demo-5. Thanks. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now