get the total nb of products (including quantities)

11 views
Skip to first unread message

ZaR

unread,
Nov 12, 2008, 12:09:30 PM11/12/08
to Open Shopping Cart
Hello,

Is there a quick way to get the count of products including
quantities ?

Example :
in cart : 2 products A + 1 products B -> get the count=3 (and not 2 as
in "You have <%#Container.Count%> products." in
<manyitemscartitemtemplate>.)

Thanks

Marc Chouteau

unread,
Nov 12, 2008, 12:34:33 PM11/12/08
to open-shop...@googlegroups.com
Hi,
 

You can for example add this method in class cartprovider:

 
  public int DistinctProductCount
  {
   get
   {
    if (List != null)
    {
     return List.Select(i => i.ProductId).Distinct().Count();
    }
    return 0;
   }
  }
 
I have just add it in the code that you can find on GoogleCode
 
Marc
 
2008/11/12 ZaR <cesar.o...@gmail.com>
Message has been deleted

ZaR

unread,
Nov 13, 2008, 3:56:13 AM11/13/08
to Open Shopping Cart
Thanks.
I see no update on Google Code.
So I'm trying to update the CartProvider class, but I get the
following build error :

Erreur 2
'System.Collections.Generic.List<ShoppingCart.CartItem>' ne
contient pas une définition pour 'Select' et aucune méthode
d'extension 'Select' acceptant un premier argument de type
'System.Collections.Generic.List<ShoppingCart.CartItem>' n'a été
trouvée (une directive using ou une référence d'assembly est-elle
manquante ?)


(for english readers : no definition for 'Select' method, using /
assembly reference may be missing)


I've tried to add System.Data.Linq.
No change.
Any idea?


;)


On 12 nov, 18:34, "Marc Chouteau" <chout...@gmail.com> wrote:
> Hi,
>
> You can for example add this method in class cartprovider:
>
>   public int DistinctProductCount
>   {
>    get
>    {
>     if (List != null)
>     {
>      return List.Select(i => i.ProductId).Distinct().Count();
>     }
>     return 0;
>    }
>   }
>
> I have just add it in the code that you can find on GoogleCode
>
> Marc
>
> 2008/11/12 ZaR <cesar.outre...@gmail.com>
>
>
>
>
>
> > Hello,
>
> > Is there a quick way to get the count of products including
> > quantities ?
>
> > Example :
> > in cart : 2 products A + 1 products B -> get the count=3 (and not 2 as
> > in  "You have <%#Container.Count%> products." in
> > <manyitemscartitemtemplate>.)
>
> > Thanks- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

Marc Chouteau

unread,
Nov 13, 2008, 4:05:23 AM11/13/08
to open-shop...@googlegroups.com
I did not yet Commited the code, it is good now.
 
The using for use the method "Select" is System.Linq
 
Marc


2008/11/13 ZaR <cesar.o...@gmail.com>

Thanks.
I see no update on Google Code.
So I'm trying to update the CartProvider class, but I get the
following build error :

Erreur  2       'System.Collections.Generic.List<ShoppingCart.CartItem>' ne
contient pas une définition pour 'Select' et aucune méthode
d'extension 'Select' acceptant un premier argument de type
'System.Collections.Generic.List<ShoppingCart.CartItem>' n'a été
trouvée (une directive using ou une référence d'assembly est-elle
manquante ?)    C:\SVN\OL\eCommerce\trunk\OLFidelite\ShoppingCart
\CartProvider.cs        122     33      ShoppingCart


(for english readers : no definition for 'Select' method, using /
assembly reference may be missing)

I've tried to add System.Data.Linq.
No change.
Any idea?

;)

On 12 nov, 18:34, "Marc Chouteau" <chout...@gmail.com> wrote:
> Hi,
>
> You can for example add this method in class cartprovider:
>
>   public int DistinctProductCount
>   {
>    get
>    {
>     if (List != null)
>     {
>      return List.Select(i => i.ProductId).Distinct().Count();
>     }
>     return 0;
>    }
>   }
>
> I have just add it in the code that you can find on GoogleCode
>
> Marc
>
> 2008/11/12 ZaR <cesar.outre...@gmail.com>

>
>
>
>
>
> > Hello,
>
> > Is there a quick way to get the count of products including
> > quantities ?
>
> > Example :
> > in cart : 2 products A + 1 products B -> get the count=3 (and not 2 as
> > in  "You have <%#Container.Count%> products." in
> > <manyitemscartitemtemplate>.)
>

ZaR

unread,
Nov 13, 2008, 4:06:46 AM11/13/08
to Open Shopping Cart
To get the thing done, here is my code :

---
CartProvider:

public int DistinctProductCount
{
get
{
if (List != null)
{
int intDistinctProductCount = 0;
foreach (var i in List)
{
intDistinctProductCount += i.Quantity;
}
return intDistinctProductCount;
}
return 0;
}
}

---
Cart:
public static int DistinctProductCount
{
get
{
return Provider.DistinctProductCount;
}
}

---
CartInformations:
[Bindable(true)]
[Category("Information")]
[Description("How many distinct items in cart")]
public int DistinctProductCount
{
get { return Cart.DistinctProductCount; }
}

---
Usage in <CART:Informations>:
<OneItemCartItemTemplate>...<%#Container.DistinctProductCount%> product
(s)...</oneitemcartitemtemplate>
<ManyItemsCartItemTemplate>...<%#Container.DistinctProductCount%>
products...</manyitemscartitemtemplate>

++
> > - Afficher le texte des messages précédents -- Masquer le texte des messages précédents -
Reply all
Reply to author
Forward
0 new messages