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.
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.
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
catch (Exception ex)BindBasketData();
}
{
// 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
Thanks for the response Jeff.
Do you know if this can be done without swithing to a gridview control.
Chris...
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