Populating cart via curl or guzzle

Hi,

We have a need to recreate certain orders for our customers and then allow them to go directly to the checkout page where they can then pay for that order.

I can grab the previous order from the api and use that data to recreate the order, but how can I populate the cart on behalf of the customer so I can send them directly to a checkout page bypassing the cart stage?

my thought was to submit the cart via guzzle and then redirect to the checkout page, but that doesn't seem to work as the checkout is always empty.

is there a way I can make this happen? Basically we want an admin on our side to generate a new order and send a link to their customer, when the customer clicks the link, our logic populates the foxy cart with the order and redirects them to a checkout page where they can then pay for the order.

I'm sure I could send them to a custom form which they could review and click checkout which would then take them to the checkout form, but I'm trying to save a step and go directly to the prepopulated checkout form.

also I know I could do this with just a get request and a query string, but the URL will be ridiculously long in certain cases so I really want to do this with a post request if possible

thanks for any suggestions!

Comments
  • fc_adamfc_adam FoxyCart Team
    @freshjones,

    Good question. My first suggestion was going to be building out the add to cart link and simply send that to the customer - but you mentioned that sometimes there could be a significantly sized cart, so that covers that!

    The approach you've taken can definitely work - creating the cart serverside using cURL requests to add each product. Based on your description - it sounds like the issue is that the same cart session (using the fcsid) isn't being used for creating the cart and loading it in the browser.

    If you ensure that whatever session ID is returned for the initial cart request is used for all subsequent cart requests for that instance, and that same session ID is used for the cart?cart=checkout URL you redirect the customer to, that should work.

    It's also worth noting that the cart session will only last as long as your store sessions are configured to - which is currently a maximum of 3 days. You can set this on the "advanced" settings page in your store's Foxy administration. I mention as if you create the cart session and then email the customer a link - if they don't interact with that link within the session lifetime window - they'll see an empty cart when they click the link. To counteract that - the link you send the customer could be to a script on your side which re-creates the cart dynamically then, and redirects the customer on to the cart=checkout link. It sounds like that may be what you're doing already - but just in case it wasn't, I thought I'd bring it up.

    Just in case you haven't seen our new API - as part of that, you can create a new cart and populate it with all of the items at once - or add items one at a time if needed too from the cart resource. You can then generate a new cart session by POSTing to the create_session link relationship on the cart resource. You'll get a cart session back in the response that you can then redirect the customer to.

    I hope that helps! Let us know if you run into any other issues
  • brettbrett FoxyCart Team
    Quick extra note: The "use the API to create a cart, create a session, and pass the customer to the checkout" approach, using the API, is becoming more widely used. One of our largest users (with multiple stores) has been doing this for the past year. (They also actually charge the customer via the API as well, as part of their automation.)
  • ok awesome guys thanks I'll see what I can come up with, sounds like using the API would be the cleanest approach, so I'll give it a go.
Sign In or Register to comment.