Welcome to Vortx Community Forum, where you can ask questions and receive answers from the staff at Vortx and other members of the community.

If you had a user account on our previous forums website, you will need to register a new account here.

Learn more about...

AspDotNetStorefront
DotFeed

Setting new CustomerId prior to redirect

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?

Thanks

Abbott

 

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.
asked Nov 3, 2015 in MultiStore by AbbottF (370 points)
closed Dec 9, 2015 by AbbottF

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.
answered Nov 3, 2015 by Vortx ScottS (13,500 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.
Abbott

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);
                        ThisCustomer.RequireCustomerRecord();
                    }
                }
}

Thanks again for your help.

Abbott

...