basket guest
Code from retail2002.
Good luck,
-Max
//================================================== ========================
===
// FileName : BasketMerger.cs
// Description : Component level helper Class to implement basket
merging when anonymous user signs
// on to different identity (userid has changed) and hence needs to
merge his old basket with the new basket.
//
// This file is part of the Microsoft Commerce Server 2002 SDK
//
// Copyright (c) Microsoft Corporation. All Rights Reserved.
//
// This source code is intended only as a supplement to Microsoft
// Commerce Server 2002 and/or on-line do***entation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
//================================================== ========================
===
#region Namespaces
using System;
using System.Web;
using Microsoft.CommerceServer.Runtime;
using Microsoft.CommerceServer.Runtime.Orders;
#endregion
namespace Microsoft.CommerceServer.Site.Components
{
/// <summary>
/// Summary description for BasketMerger.
/// </summary>
public class BasketMerger
{
#region Methods
//================================================== ========================
===
// METHOD: MoveItemsFromAnonymousToAuthenticatedBasket
//
// <doc>
// <desc>Public Method</desc>
// <remarks>
// This method is used to merge basket contents
// when a transition from Anonymous to Authenticated user's
state takes place
// (through a previous delete cookies operation).
// </remarks>
// </doc>
//
//================================================== ========================
===
static public void
MoveItemsFromAnonymousToAuthenticatedBasket(System .Guid anonymousGuid,
System.Guid authenticatedGuid)
{
OrderTemplate anonymousOrderTemplate;
Basket authenticatedBasket;
try
{
//
// Proceed only if the userIDs are different...
//
if (!anonymousGuid.Equals(authenticatedGuid))
{
// Retrieve the respective anon and auth baskets now..
anonymousOrderTemplate =
CommerceContext.Current.OrderSystem.GetOrderTempla te(anonymousGuid,
anonymousGuid);
//
// Proceed only if there existed a basket with the
anonymous user..
//
if (anonymousOrderTemplate != null)
{
authenticatedBasket =
CommerceContext.Current.OrderSystem.GetBasket(auth enticatedGuid);
// Merge them now..
authenticatedBasket.Add(anonymousOrderTemplate);
authenticatedBasket.Save();
// delete the anon basket as this user doesnt need
it anymore..
anonymousOrderTemplate.Delete();
}
}
}
catch (Exception)
{
//
// Exception handling yet to be done..
//
}
}
#endregion
}
}
|