Skip to Content
Former Member
Mar 31, 2009 at 04:12 PM

Add Item To Current User's Cart Using API


I'm using Web Tools v625. I'm looking to use the API to add a part to the user's cart, but I can't figure out how to do it. I have a quick example below:

// (Account ID, Order Type)
netpoint.api.commerce.NPOrder cart =
  new netpoint.api.commerce.NPOrder("MyAccountID", netpoint.api.CartType.Cart);
netpoint.api.catalog.NPPartPricingMaster priceList =
  new netpoint.api.catalog.NPPartPricingMaster("MyPriceList");
// (Part Number, Quantity, Catalog Code, Category Code, Price List)
cart.AddPart("MyPartNo", 1, "MyCatalogCode", "MyCategoryCode", priceList);

It seems that this should work, except that I need the user to be logged in. I looked at the data in OrderMaster, and there is a field for both AccountID and UserID, but many of the records do not contain any values in these fields. Instead, there is a consistently unique hash value in the CustKey field, which I'm guessing is how each cart is differentiated on a per-user basis, regardless of login status.

I'm a little confused on the constructor. It seems that no matter which one I use, it requires a UserID or AccountID, and some even require the CustKey, which, according to the API documentation, is the Session ID. How do I load the current user's cart via the constructor? Additionally, how can I obtain the current user's CustKey/SessionID?