MVC, WebRequests, CookieContainers, and Americart

201 views Asked by At

I want to send the contents of a user's shopping cart to a third-party cart (Americart), and I want to do this in my ActionResult method using the WebRequest class.

But, Americart expects me to put a form in the View and have the user submit the form directly to Americart when the user clicks "add to cart."

I find this clumsy on many levels, and would prefer that the user stay on my site, complete shopping, and let me transfer contents of my cart to Americart when the user clicks "checkout".

So, it seemed like a no-brainer to set up an ActionResult "Checkout", and in that method: (1) send the contents of the my cart to Americart using WeRequest, and (2) when done redirect the user to the Americart checkout page.

But, when the user arrives at the Americart checkout page it says the cart is empty. It quickly dawned on me that Americart never had the opportunity to cookie the user, as the WebRequest object did the "adding to cart," not the user. So the user arrives with no cookie, and no items in cart.

So, I want to get the cookies that Americart is assigning and store them in the CookieContainer of the WebRequest object, and I want to transfer the cookies out of the CookiContainer and assign them to the User BEFORE I redirect them to Americart. I want the Americart site to be able to read the cookies as if they had done the assigning of the cookies directly to the user.

Can this be done? I am doubtful, but hopeful enough to ask.

1

There are 1 answers

0
Gerry On

You can do that, but it would require you to make some changes to your account set up, the option to not show the cart on add to cart ( this may be a setting they need to change) then when your shopper is down, simply loop through the items in the cart and pass the Americart add to cart string to cart.cgi, then submit to checkout.