|
Home > Archive > Commerce Server General > October 2005 > How to Save then Retrieve a basket
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to Save then Retrieve a basket
|
|
| Susan H 2005-10-06, 5:57 pm |
| I am using Commerce Server 2002 FP1, CMS 2002, and MSIB 2.5
I am trying to simply save a user's shopping cart in such a way that it is
not an order, and I can retrieve this cart later given the user's email
address.
Currently, I am trying
GetOrderTemplate(new Guid(UserObject.CurrentUser.UserID), new
Guid(UserObject.CurrentUser.UserID));
but this does not seem to be working. I was wondering if there's a common
way to do this.
| |
| Marcelo 2005-10-07, 2:55 am |
| Hi Susan,
In Commerce Help documentatio you have a example of you can do that, see
"Code to Manipulate a Basket on an ASP.NET Web Form"
void UpdateBasket() {
OrderContext orders = CommerceContext.Current.OrderSystem;
// This requires that the CommerceContext.UserID property already
// be set. It can either be set dynamically if using Commerce Server
// authentication, or manually.
Basket shoppingCart =
orders.GetBasket(new System.Guid(CommerceContext.Current.UserID));
// If the shopping cart has just been created, no order forms
// will exist and thus, it is unusable. So a new, default
// order form must be added.
if (shoppingCart.OrderForms.Count == 0) {
shoppingCart.OrderForms.Add(new OrderForm("default"));
}
// Execute the product pipeline to ensure we have the latest product
// information in the basket.
shoppingCart.RunPipeline(new PipelineInfo("basket"));
// Bind the default order form to the Repeater control used for
// displaying its contents.
BasketListing.DataSource =
shoppingCart.OrderForms["default"].LineItems;
BasketListing.DataBind();
// Update information about the order.
SubTotal.Text = String.Format("{0:C}", shoppingCart.SubTotal);
// This data will not be available after running the basket pipeline
// alone.
Tax.Text = String.Format("{0:C}", shoppingCart.TaxTotal);
Total.Text = String.Format("{0:C}", shoppingCart.Total);
shoppingCart.Save();
}
Regards
Marcelo SWánchez Lujambio
"Susan H" wrote:
> I am using Commerce Server 2002 FP1, CMS 2002, and MSIB 2.5
>
> I am trying to simply save a user's shopping cart in such a way that it is
> not an order, and I can retrieve this cart later given the user's email
> address.
>
> Currently, I am trying
>
> GetOrderTemplate(new Guid(UserObject.CurrentUser.UserID), new
> Guid(UserObject.CurrentUser.UserID));
>
> but this does not seem to be working. I was wondering if there's a common
> way to do this.
| |
| Susan H 2005-10-07, 6:03 pm |
| Thank you for your reply. Unfortunately, this is not what I meant.
I have been able to succesfully construct and save a basket, and if I call
cart.SaveAsOrder() I properly get a new order (PurchaseOrder) that I expect.
What I'm trying to do is save the basket in a "saved" state, where the order
form object is in a status of "2", in such a way that I can later, in a
different session, re-retrieve that same basket using the person's email
address. Basically, what we have is a customer service section, where the
CSR's place orders for customers; if the customer's credit card doesn't work,
they need to check on it and call back, so instead of re-placing the whole
order, the intention is to "save" the order for later retrieval.
I was using GetOrderTemplate(new Guid(UserObject.CurrentUser.UserID), new
Guid(UserObject.CurrentUser.UserID)) but that does not seem to work.
Thanks again for your reply.
| |
| Jeff Lynch 2005-10-09, 8:49 pm |
| Try something like this code:
/// <summary> /// The <b>SaveAsTemplate</b> method allows the
user to save the current Basket as a /// Template for later use.
/// </summary> /// <param name="TemplateName">The name of the
template.</param> public void SaveAsTemplate(string TemplateName)
{ // Create a new OrderTemplate from the Basket
OrderTemplate template =
CommerceContext.Current.OrderSystem.CreateOrderTemplate(_Basket.BasketID);
// Add the OrderForms to the Template template.OrderForms.Add(new
OrderForm("default")); foreach (LineItem item in
_Basket.OrderForms["default"].LineItems) {
template.OrderForms["default"].LineItems.Add(item); }
// Run the pipeline
template.RunPipeline(GetBasketPipelineInfo()); // Save the
template template.Save(TemplateName); // Empty the
Basket EmptyBasket(); }
private PipelineInfo GetBasketPipelineInfo() {
PipelineInfo info = new PipelineInfo("basket");
info["catalog_language"] = Utility.EnglishLanguage;
info.Profiles.Add("User", CommerceContext.Current.UserProfile);
info.Language = Utility.EnglishLanguage; return info; }
--
Jeff Lynch
"A BizTalk Enthusiast"
http://codebetter.com/blogs/jeff.lynch
"Susan H" <susanjane@newsgroups.nospam> wrote in message
news:EEB42BD7-FC47-414B-A0EA-679995683133@microsoft.com...
> Thank you for your reply. Unfortunately, this is not what I meant.
>
> I have been able to succesfully construct and save a basket, and if I call
> cart.SaveAsOrder() I properly get a new order (PurchaseOrder) that I
> expect.
>
> What I'm trying to do is save the basket in a "saved" state, where the
> order
> form object is in a status of "2", in such a way that I can later, in a
> different session, re-retrieve that same basket using the person's email
> address. Basically, what we have is a customer service section, where the
> CSR's place orders for customers; if the customer's credit card doesn't
> work,
> they need to check on it and call back, so instead of re-placing the whole
> order, the intention is to "save" the order for later retrieval.
>
> I was using GetOrderTemplate(new Guid(UserObject.CurrentUser.UserID), new
> Guid(UserObject.CurrentUser.UserID)) but that does not seem to work.
>
> Thanks again for your reply.
| |
| Jeff Lynch 2005-10-10, 7:52 am |
| Sorry about the formatting on my last message. Ping me via my blog and I'll
email you the source code.
--
Jeff Lynch
"A BizTalk Enthusiast"
http://codebetter.com/blogs/jeff.lynch
"Jeff Lynch" <jeff.lynch@newsgroup.nospam> wrote in message
news:OiYvg3SzFHA.736@tk2msftngp13.phx.gbl...
> Try something like this code:
>
> /// <summary> /// The <b>SaveAsTemplate</b> method allows
> the user to save the current Basket as a /// Template for later
> use. /// </summary> /// <param name="TemplateName">The name of the
> template.</param> public void SaveAsTemplate(string TemplateName)
> { // Create a new OrderTemplate from the Basket OrderTemplate
> template =
> CommerceContext.Current.OrderSystem.CreateOrderTemplate(_Basket.BasketID);
> // Add the OrderForms to the Template
> template.OrderForms.Add(new OrderForm("default")); foreach
> (LineItem item in _Basket.OrderForms["default"].LineItems) {
> template.OrderForms["default"].LineItems.Add(item); } // Run
> the pipeline template.RunPipeline(GetBasketPipelineInfo()); //
> Save the template template.Save(TemplateName); //
> Empty the Basket EmptyBasket(); }
> private PipelineInfo GetBasketPipelineInfo() { PipelineInfo info =
> new PipelineInfo("basket"); info["catalog_language"] =
> Utility.EnglishLanguage; info.Profiles.Add("User",
> CommerceContext.Current.UserProfile); info.Language =
> Utility.EnglishLanguage; return info; }
>
> --
> Jeff Lynch
> "A BizTalk Enthusiast"
> http://codebetter.com/blogs/jeff.lynch
> "Susan H" <susanjane@newsgroups.nospam> wrote in message
> news:EEB42BD7-FC47-414B-A0EA-679995683133@microsoft.com...
>
>
| |
| Susan H 2005-10-10, 6:00 pm |
| Jeff:
Thank you for your reply. This looks like what I'm looking for. I'm going
to try this and then I'll get back to you. Don't worry about the formatting,
I've got it :-)
Thanks
Sue
"Jeff Lynch" wrote:
> Try something like this code:
>
> /// <summary> /// The <b>SaveAsTemplate</b> method allows the
|
|
|
|
|