Everything is working, the correct amount is getting passed, but I'm trying to get it to show the individual items by Item Name. As you can see I've used "profile.scart.total" to ass the monetary total, which is fine it works. But the items appear as a single
purchase with an item name of "system.collections.generic.list". Any thoughts on why this may be?
It looks like Profile.SCart.Items is a list so when it's converted to a string it displays the class name (system.collections.generic.list). If SCart is a class you created it might be worth adding a property that returns a URL encoded string to pass into
the URL instead.
I do have a cart class that defines the shopping cart. I don't really remember where I go it. I've been working on this project off and on for about a year now and this is so far partially successful. I'm not sure how to do what you say, adding a property
to encode the return value. Would I still use the <%=Profile.SCart.Items %> name, or would it be something different? I'm not all that smart with encoding and returning values.
Here is my class if it helps to see what I'm working with.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ShoppingCartExample
{
[Serializable]
public class CartItem
{
private int _Id;
private string _Genre;
private string _Title;
private string _Description;
private int _Quantity;
private double _Price;
private double _subTotal;
public CartItem()
{
}
public CartItem(int Id, string Genre, string Title, string Description, int Quantity, double Price)
{
_Id = Id;
_Genre = Genre;
_Title = Title;
_Description = Description;
_Quantity = Quantity;
_Price = Price;
_subTotal = Quantity * Price;
}
public int Id
{
get { return _Id; }
set { _Id = value; }
}
public string Genre
{
get { return _Genre; }
set { _Genre = value; }
}
public string Title
{
get { return _Title; }
set { _Title = value; }
}
public string Description
{
get { return _Description; }
set { _Description = value; }
}
public int Quantity
{
get { return _Quantity; }
set { _Quantity = value; }
}
public double Price
{
get { return _Price; }
set { _Price = value; }
}
public double subTotal
{
get { return _Quantity * _Price; }
}
}
[Serializable]
public class Cart
{
private DateTime _dateCreated;
private DateTime _lastUpdate;
private List<CartItem> _items;
public Cart()
{
if (this._items == null)
{
this._items = new List<CartItem>();
this._dateCreated = DateTime.Now;
}
}
public List<CartItem> Items
{
get { return _items; }
set { _items = value; }
}
public void Insert(int Id, double Price, int Quantity, string Title)
{
int ItemIndex = ItemIndexofID(Id);
if (ItemIndex == -1)
{
CartItem NewItem = new CartItem();
NewItem.Id = Id;
NewItem.Quantity = Quantity;
NewItem.Price = Price;
NewItem.Title = Title;
_items.Add(NewItem);
}
else
{
_items[ItemIndex].Quantity += 1;
}
_lastUpdate = DateTime.Now;
}
public void Update(int RowID, int Id, int Quantity, double Price)
{
CartItem Item = _items[RowID];
Item.Id = Id;
Item.Quantity = Quantity;
Item.Price = Price;
_lastUpdate = DateTime.Now;
}
public void DeleteItem(int rowID)
{
_items.RemoveAt(rowID);
_lastUpdate = DateTime.Now;
}
private int ItemIndexofID(int Id)
{
int index = 0;
foreach (CartItem item in _items)
{
if (item.Id == Id)
{
return index;
}
index += 1;
}
return -1;
}
public double Total
{
get
{
double t = 0;
if (_items == null)
{
return 0;
}
foreach (CartItem Item in _items)
{
t += Item.subTotal;
}
return t;
}
}
}
}
But the items appear as a single purchase with an item name of "system.collections.generic.list". Any thoughts on why this may be?
The reason is that Profile.SCart.Items is a list which can't be converted to a string. According to your description, you can try to pass the
Profile.SCart.Items[index] to PayPal. I am not sure whether I have understood your meaning correctly. If I am wrong, please feel free to let me know.
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
AsPxFrK
Member
232 Points
93 Posts
PayPal in web form - System.Collections.Generic.List
Aug 20, 2012 07:08 PM|LINK
Hi all. I'm integrating a PayPal button in my site that's storing product info in the profile and passing it to PayPal. Below is the code I'm using:
Everything is working, the correct amount is getting passed, but I'm trying to get it to show the individual items by Item Name. As you can see I've used "profile.scart.total" to ass the monetary total, which is fine it works. But the items appear as a single purchase with an item name of "system.collections.generic.list". Any thoughts on why this may be?
meshent
Member
86 Points
14 Posts
Re: PayPal in web form - System.Collections.Generic.List
Aug 20, 2012 08:03 PM|LINK
It looks like Profile.SCart.Items is a list so when it's converted to a string it displays the class name (system.collections.generic.list). If SCart is a class you created it might be worth adding a property that returns a URL encoded string to pass into the URL instead.
AsPxFrK
Member
232 Points
93 Posts
Re: PayPal in web form - System.Collections.Generic.List
Aug 20, 2012 08:37 PM|LINK
I do have a cart class that defines the shopping cart. I don't really remember where I go it. I've been working on this project off and on for about a year now and this is so far partially successful. I'm not sure how to do what you say, adding a property to encode the return value. Would I still use the <%=Profile.SCart.Items %> name, or would it be something different? I'm not all that smart with encoding and returning values.
Here is my class if it helps to see what I'm working with.
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ShoppingCartExample { [Serializable] public class CartItem { private int _Id; private string _Genre; private string _Title; private string _Description; private int _Quantity; private double _Price; private double _subTotal; public CartItem() { } public CartItem(int Id, string Genre, string Title, string Description, int Quantity, double Price) { _Id = Id; _Genre = Genre; _Title = Title; _Description = Description; _Quantity = Quantity; _Price = Price; _subTotal = Quantity * Price; } public int Id { get { return _Id; } set { _Id = value; } } public string Genre { get { return _Genre; } set { _Genre = value; } } public string Title { get { return _Title; } set { _Title = value; } } public string Description { get { return _Description; } set { _Description = value; } } public int Quantity { get { return _Quantity; } set { _Quantity = value; } } public double Price { get { return _Price; } set { _Price = value; } } public double subTotal { get { return _Quantity * _Price; } } } [Serializable] public class Cart { private DateTime _dateCreated; private DateTime _lastUpdate; private List<CartItem> _items; public Cart() { if (this._items == null) { this._items = new List<CartItem>(); this._dateCreated = DateTime.Now; } } public List<CartItem> Items { get { return _items; } set { _items = value; } } public void Insert(int Id, double Price, int Quantity, string Title) { int ItemIndex = ItemIndexofID(Id); if (ItemIndex == -1) { CartItem NewItem = new CartItem(); NewItem.Id = Id; NewItem.Quantity = Quantity; NewItem.Price = Price; NewItem.Title = Title; _items.Add(NewItem); } else { _items[ItemIndex].Quantity += 1; } _lastUpdate = DateTime.Now; } public void Update(int RowID, int Id, int Quantity, double Price) { CartItem Item = _items[RowID]; Item.Id = Id; Item.Quantity = Quantity; Item.Price = Price; _lastUpdate = DateTime.Now; } public void DeleteItem(int rowID) { _items.RemoveAt(rowID); _lastUpdate = DateTime.Now; } private int ItemIndexofID(int Id) { int index = 0; foreach (CartItem item in _items) { if (item.Id == Id) { return index; } index += 1; } return -1; } public double Total { get { double t = 0; if (_items == null) { return 0; } foreach (CartItem Item in _items) { t += Item.subTotal; } return t; } } } }AsPxFrK
Member
232 Points
93 Posts
Re: PayPal in web form - System.Collections.Generic.List
Aug 20, 2012 08:57 PM|LINK
This is where I got the above code from.
http://csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: PayPal in web form - System.Collections.Generic.List
Aug 27, 2012 08:47 AM|LINK
Hi, .
The reason is that Profile.SCart.Items is a list which can't be converted to a string. According to your description, you can try to pass the Profile.SCart.Items[index] to PayPal. I am not sure whether I have understood your meaning correctly. If I am wrong, please feel free to let me know.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
AsPxFrK
Member
232 Points
93 Posts
Re: PayPal in web form - System.Collections.Generic.List
Sep 03, 2012 03:27 PM|LINK
I tried to use [index] but I got an error that says it does not exist in the current context.
This is where the list comes from in the code page:
public List<CartItem> Items { get { return _items; } set { _items = value; } }Somehow I think I need to convert the List to array? I'm not sure how though.