OrderTemplate.Save problem
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
OrderTemplate.Save problem

 
Post new topic   Reply to topic    Windows Server Forum Index -> Commerce Server
Author Message
Alexander Yushchenko
Guest





Posted: Fri Sep 02, 2005 8:52 pm    Post subject: OrderTemplate.Save problem Reply with quote

I use MSCS2002 + SP3 + FP1.

I try to use OrderTemplate class to store "wish list" for a user -
something like shopping cart but without quantities and checkout (it's
like favourites in internet explorer, used to "bookmark" some products).

I have created the WishList class attached.

I use the following code to add product to wish list:

wishList.AddProduct (this.ProductID);
wishList.Save();

Everything is ok, in debugger I can see that the product is added.

But on the next postback of the same aspx page it is empty! It
seems like it was not saved successfully.

Please, advice.

--
Yours faithfully,
Alexander Yushchenko
Back to top
Alexander Yushchenko
Guest





Posted: Mon Sep 05, 2005 8:51 pm    Post subject: Some details. Reply with quote

After debugging it for a while, I found out that even the order
form is not saved - on next postback when OrderTemplate is retrieved it
contains no order forms.

Please, advice.

--
Yours faithfully,
Alexander Yushchenko


Alexander Yushchenko wrote:
Quote:
I use MSCS2002 + SP3 + FP1.

I try to use OrderTemplate class to store "wish list" for a user -
something like shopping cart but without quantities and checkout (it's
like favourites in internet explorer, used to "bookmark" some products).

I have created the WishList class attached.

I use the following code to add product to wish list:

wishList.AddProduct (this.ProductID);
wishList.Save();

Everything is ok, in debugger I can see that the product is added.

But on the next postback of the same aspx page it is empty! It seems
like it was not saved successfully.

Please, advice.


------------------------------------------------------------------------

#region Namespaces

using System;
using Microsoft.CommerceServer.Runtime;
using Microsoft.CommerceServer.Runtime.Orders;

#endregion

namespace Excis.BizClasses
{
/// *******************************************************************
/// <summary
/// This class helps to work with wish list.
/// </summary
/// *******************************************************************
public class WishList
{
#region Constructors

/// <summary
/// This is the default constructor for this class.
/// </summary
internal WishList()
{
if ((this.fieldCommerceContext.UserID == null) ||
(this.fieldCommerceContext.UserID.Length == 0))
throw new ApplicationException();

// retreive the current user ID
Guid currUserGuid = new Guid(this.fieldCommerceContext.UserID);

// retrieve wish list OrderTemplate
object WishListOrderTemplateIDObject =
fieldTransactionContext.Cart["WishListGuid"];
if (WishListOrderTemplateIDObject is Guid)
{
this.fieldOrderTemplate =
fieldCommerceContext.OrderSystem.GetOrderTemplate
(currUserGuid, (Guid)WishListOrderTemplateIDObject);
}
else
{
this.fieldOrderTemplate =
fieldCommerceContext.OrderSystem.CreateOrderTemplate(currUserGuid);
fieldTransactionContext.Cart["WishListGuid"] =
this.fieldOrderTemplate.TemplateID;
}

this.fieldOrderForm =
this.fieldOrderTemplate.OrderForms[WishList.DefaultOrderFormKeyName];
if (this.fieldOrderForm == null)
{
//Create New OrderForm
this.fieldOrderForm = new OrderForm(WishList.DefaultOrderFormKeyName);
this.fieldOrderTemplate.OrderForms.Add(this.fieldOrderForm);
}
}

#endregion

#region Fields

private OrderForm fieldOrderForm = null;
private OrderTemplate fieldOrderTemplate = null;
private CommerceContext fieldCommerceContext = CommerceContext.Current;
private TransactionContext fieldTransactionContext = TransactionContext.Current;

private const string DefaultOrderFormKeyName = "default";

#endregion

#region Properties

/// <summary
/// This read-only Boolean property is true if LineItem.Count == 0.
/// </summary
public bool IsEmpty
{
get{return (this.fieldOrderForm.LineItems.Count == 0);}
}

/// <summary
/// This read-only property exposes the Basket (OrderForm) object
/// LineItems property.
/// </summary
public LineItemCollection LineItems
{
get{return this.fieldOrderForm.LineItems;}
}

/// <summary
/// This read-only property returns the OrderForm for debugging purposes.
/// </summary
public OrderForm OrderForm
{
get{return this.fieldOrderForm;}
}

#endregion

#region Methods

/// <summary
/// Retrieves info from MCS Catalog and puts it into line items.
/// The following information is retrieved:
/// - product name
/// - product image
/// - product details page url
/// </summary
public void SetLineItemInfo()
{
//ToDo: implement this method
throw new NotImplementedException();
}


/// <summary
/// This method adds SKU to wish list.
/// Does nothing if SKU is already in wish list.
///
/// Throws an ArgumentNullException if SKU is mull
/// Throws an ArgumentException if SKU is empty string
/// </summary
/// <param name="SKU"> Product SKU (cannot be null). </param
public void AddProduct(string SKU)
{
if (SKU == null) throw new ArgumentNullException("SKU");
if (SKU.Length == 0) throw new ArgumentException("SKU");

foreach (LineItem li in this.LineItems)
if (li.ProductID==SKU) return;

LineItem lineItem = new LineItem();
lineItem.ProductID = SKU;
lineItem.Quantity = 1;
this.fieldOrderForm.LineItems.Add(lineItem);
}


/// <summary
/// This method removes SKU from wish list.
/// Does nothing if SKU is not in wish list.
///
/// Throws an ArgumentNullException if SKU is mull
/// Throws an ArgumentException if SKU is empty string
/// </summary
/// <param name="SKU"> Product SKU (cannot be null). </param
public void RemoveProduct(string SKU)
{
if (SKU == null) throw new ArgumentNullException("SKU");
if (SKU.Length == 0) throw new ArgumentException("SKU");

foreach (LineItem li in this.LineItems)
if (li.ProductID==SKU)
{
this.fieldOrderForm.LineItems.Remove(li);
return;
}
}

/// <summary> Removes all products from wish list. </summary
public void Clear()
{
this.fieldOrderForm.Clear();
}

/// <summary> Saves changes to wish list. </summary
public void Save()
{
this.fieldOrderTemplate.Save();
}

#endregion
}
}
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Commerce Server All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB