Alexander Yushchenko
Guest
|
Posted:
Fri Sep 02, 2005 8:52 pm Post subject:
OrderTemplate.Save problem |
|
|
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 |
|
Alexander Yushchenko
Guest
|
Posted:
Mon Sep 05, 2005 8:51 pm Post subject:
Some details. |
|
|
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
}
} |
|
|