I have an ajax asmx function that creates a shopping cart. I am using :

Customer.MakeAnonCustomerRecord(out allocationParams.CustomerId, out guid);

To create a customer if non exists. Once I complette the cart generation for the customerId just created, how do I attach the customer to the current page flow so that a reditrect to the shopping cart will display the just created cart information?




Note: a prior answer by Trisha (thanks) got me this far. I changed the function from a form post to an ajax call.

closed with the note: It now works thanks to ScottS help.
in MultiStore by (380 points)
closed by

1 Answer

0 votes
You'd probably have better luck using Customer.RequireCustomerRecord() rather than MakeAnonCustomerRecord.  That method handles checking if the current customer has a record already, creating one if not, and assigning the current session to that new record for you (actually using the method you mentioned), so you don't have to deal with any of that.
by (13.5k points)
I tried that first, but the ajax call does not have context and I'm not surehow to attach the current session context to tthe ajax call. If you have any ideas, I would appreciate it.
Thanks for the fast response.

It seems that Customer.MakeAnonCustomerRecord creates a new record and "sometimes" sets the session.

In case thaat happens,  I pushed the Requires request to ShoppingCart.aspx.cs using...

// If this is from annon allocation - use annon customer
if (ThisCustomer.CustomerID == 0)
                var strCustId = Request[Constants.SACustomerIdParam];
                if ( !string.IsNullOrEmpty(strCustId))
                    var customerId = 0;
                    if (Int32.TryParse(strCustId, out customerId))
                        ThisCustomer = new Customer(customerId);

Thanks again for your help.