ASPX templates
Version 5.x > ASPX templates > How to create a new shopping cart in code View modes: 
User avatar
Member
Member
LukeB - 8/24/2010 9:13:20 PM
   
How to create a new shopping cart in code
Just wondering if anyone knows how to create a new shopping cart from code where the shopping cart is NOT linked to the current user.

I basically need to create a new order in the ecommerce module from a scheduled task in kentico. I've created a new customer and linked it to the relevent user. Now I am stuck triing to create a shopping cart. My code is as follows:
// create customer (if they dont already exist)
var custInfo = CustomerInfoProvider.GetCustomerInfoByUserId(myUserID);
if (custInfo == null)
{
custInfo = new CustomerInfo();
custInfo.CustomerUserID = buyer.UserID;
custInfo.CustomerFirstName = myFirstName;
custInfo.CustomerLastName = myLastName;
custInfo.CustomerEnabled = true;
CustomerInfoProvider.SetCustomerInfo(custInfo);
}

// create cart, add product to cart
var cartInfo = ShoppingCartInfoProvider.CreateShoppingCartInfo(CMSContext.CurrentSiteID);
cartInfo.ShoppingCartUserID = myUserID; // this fails - ShoppingCartUserID is readonly

If I can link the shopping cart to the required user I think the rest should be pretty easy.

Any ideas?

Thanks in advance!

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/26/2010 5:33:55 AM
   
RE:How to create a new shopping cart in code
Hi,

You need to use ShoppingCartCustomerID instead of ShoppingCartUserID. Or you can use this to initialize the user info:

ShoppingCartInfo.UserInfoObj = UserInfo;


I hope it will help.

Best regards,
Juraj Ondrus