Delete Products From Basket

Can any one point me in the right direction. I would like to add either a Delete CheckBox or Button that deletes the product from the Basket rather than making the user set the Quantity to zero (to subtle).

Please Advise.

[237 byte] By [Xcel] at [2008-1-7]
# 1

Here is the code I use (not based upon the StarterSite) to delete an item from the user's basket which is displayed in a GridView control:

protected void BasketList_RowDeleting(Object sender, GridViewDeleteEventArgs e)

{

try

{

// Call the helper method to remove the item

basketHelper.RemoveBasketItem(e.RowIndex);

// Repopulate the page controls

BindBasketData();

}

catch (Exception ex)

{

// Show the Error Label and set it's text

ErrorLabel.Visible = true;

ErrorLabel.Text = ex.Message;

}

}

public void RemoveBasketItem(int Index)

{

// Remove the LineItem from the Basket using it's index

_Basket.OrderForms[OrderForm.DefaultOrderFormName].LineItems.Remove(Index);

// Update and save the Basket

UpdateBasket("basket");

}

public void UpdateBasket(string pipelinename)

{

// Dispose of the PipelineInfo object since it references COM objects

using (PipelineInfo info = new PipelineInfo(pipelinename))

{

if (CommerceContext.Current.UserProfile != null)

{

// Add the UserObject to the Discount's TargetingProfileCollection

info.Profiles.Add("UserObject", CommerceContext.Current.UserProfile);

}

// Run the pipeline

_Basket.RunPipeline(info);

// Save the Basket

_Basket.Save();

}

}

This should give you an idea of how to proceed.

Jeff Lynch

MVP Windows Server System - Commerce Server

http://codebetter.com/blogs/jeff.lynch

JeffLynch-MVP at 2007-10-2 > top of Msdn Tech,Commerce Server,Commerce Server 2007...
# 2

Thanks for the response Jeff.

Do you know if this can be done without swithing to a gridview control.

Chris...

Xcel at 2007-10-2 > top of Msdn Tech,Commerce Server,Commerce Server 2007...
# 3

If you're using the StarterSite code you'll need to look at the source code for the CommerceComponents and see what control(s) the cart uses to display the user's products.

Jeff Lynch

MVP Windows Server System - Commerce Server

http://codebetter.com/blogs/jeff.lynch

JeffLynch-MVP at 2007-10-2 > top of Msdn Tech,Commerce Server,Commerce Server 2007...