|
Home > Archive > Commerce Server General > October 2005 > Discounts in basket
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Discounts in basket
|
|
|
| Hi there i know this has been covered before, but we're still not quite
getting there.
We found the following post
http://blogs.msdn.com/yuxiangxu/arc.../29/169123.aspx on Andy
Xu's blog. However we tried to do a quick code translation from VB.NET
to C# - and we may have got this wrong. But the code does not work as
expected.
Taking the code in Andy's blog post, we have come up with the following
code, and when run we get an invalid cast exception. Any ideas please?:
OrderForm cartOrderForm = basket.OrderForms[0];
ISimpleList discountApplicationRecords;
int campaignItemID;
decimal discountAmount;
//assume basket pipeline is exeecuted and we get the orderForm in
variable cartOrderForm
discountAmount = 0;
foreach(LineItem item in cartOrderForm.LineItems)
{
if(!(item["_itemlevel_discounts_applied"].Equals(System.DBNull.Value)))
{
discountApplicationRecords =
(ISimpleList)item["_itemlevel_discounts_applied"];
foreach(System.Collections.IDictionary discountApplicationRecord in
discountApplicationRecords)
{
campaignItemID = (int)discountApplicationRecord["discount_id"];
if(campaignItemID == 1)
{
discountAmount +=
(decimal)discountApplicationRecord["cy_discount_amount"];
}
}
}
}
return discountAmount;
| |
| Nihit Kaul [MSFT] 2005-09-30, 5:53 pm |
| What line are you getting the case exception on?
Thanks,
Nihit Kaul[MSFT]
Commerce Server
http://blogs.msdn.com/nihitk
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
From: "adam" <adam.stewart@framfab.com>
Newsgroups: microsoft.public.commerceserver.general
Subject: Discounts in basket
Date: 29 Sep 2005 10:29:26 -0700
Organization: http://groups.google.com
Lines: 45
Message-ID: <1128014966.689065.133700@g47g2000cwa.googlegroups.com>
NNTP-Posting-Host: 194.201.25.93
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1128014972 29573 127.0.0.1 (29 Sep 2005
17:29:32 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 29 Sep 2005 17:29:32 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET
CLR 1.1.4322; .NET CLR 1.0.3705),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g47g2000cwa.googlegroups.com; posting-host=194.201.25.93;
posting- account=kf8PqA0AAABDDcmuKIAt7Lb0CIx3Qjd_
Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!ne
wsfeed1.ip.tiscali.net!news.glorb.com!postnews.google.com!g47g2000cwa.google
groups.com!not-for-mail
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.commerceserver.general:3608
X-Tomcat-NG: microsoft.public.commerceserver.general
Hi there i know this has been covered before, but we're still not quite
getting there.
We found the following post
http://blogs.msdn.com/yuxiangxu/arc.../29/169123.aspx on Andy
Xu's blog. However we tried to do a quick code translation from VB.NET
to C# - and we may have got this wrong. But the code does not work as
expected.
Taking the code in Andy's blog post, we have come up with the following
code, and when run we get an invalid cast exception. Any ideas please?:
OrderForm cartOrderForm = basket.OrderForms[0];
ISimpleList discountApplicationRecords;
int campaignItemID;
decimal discountAmount;
//assume basket pipeline is exeecuted and we get the orderForm in
variable cartOrderForm
discountAmount = 0;
foreach(LineItem item in cartOrderForm.LineItems)
{
if(!(item["_itemlevel_discounts_applied"].Equals(System.DBNull.Value)))
{
discountApplicationRecords =
(ISimpleList)item["_itemlevel_discounts_applied"];
foreach(System.Collections.IDictionary discountApplicationRecord in
discountApplicationRecords)
{
campaignItemID = (int)discountApplicationRecord["discount_id"];
if(campaignItemID == 1)
{
discountAmount +=
(decimal)discountApplicationRecord["cy_discount_amount"];
}
}
}
}
return discountAmount;
| |
|
| Sorry, i should have said where this error was happening !!
its the cast to IDictionary of the foreach part where the cast
exception occurs.
TIA
Adam
Nihit Kaul [MSFT] wrote:
> What line are you getting the case exception on?
>
> Thanks,
>
> Nihit Kaul[MSFT]
> Commerce Server
> http://blogs.msdn.com/nihitk
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> --------------------
> From: "adam" <adam.stewart@framfab.com>
> Newsgroups: microsoft.public.commerceserver.general
> Subject: Discounts in basket
> Date: 29 Sep 2005 10:29:26 -0700
> Organization: http://groups.google.com
> Lines: 45
> Message-ID: <1128014966.689065.133700@g47g2000cwa.googlegroups.com>
> NNTP-Posting-Host: 194.201.25.93
> Mime-Version: 1.0
> Content-Type: text/plain; charset="iso-8859-1"
> X-Trace: posting.google.com 1128014972 29573 127.0.0.1 (29 Sep 2005
> 17:29:32 GMT)
> X-Complaints-To: groups-abuse@google.com
> NNTP-Posting-Date: Thu, 29 Sep 2005 17:29:32 +0000 (UTC)
> User-Agent: G2/0.2
> X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET
> CLR 1.1.4322; .NET CLR 1.0.3705),gzip(gfe),gzip(gfe)
> Complaints-To: groups-abuse@google.com
> Injection-Info: g47g2000cwa.googlegroups.com; posting-host=194.201.25.93;
> posting- account=kf8PqA0AAABDDcmuKIAt7Lb0CIx3Qjd_
> Path:
> TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!ne
> wsfeed1.ip.tiscali.net!news.glorb.com!postnews.google.com!g47g2000cwa.google
> groups.com!not-for-mail
> Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.commerceserver.general:3608
> X-Tomcat-NG: microsoft.public.commerceserver.general
>
> Hi there i know this has been covered before, but we're still not quite
> getting there.
>
> We found the following post
> http://blogs.msdn.com/yuxiangxu/arc.../29/169123.aspx on Andy
> Xu's blog. However we tried to do a quick code translation from VB.NET
> to C# - and we may have got this wrong. But the code does not work as
> expected.
>
> Taking the code in Andy's blog post, we have come up with the following
> code, and when run we get an invalid cast exception. Any ideas please?:
>
> OrderForm cartOrderForm = basket.OrderForms[0];
> ISimpleList discountApplicationRecords;
> int campaignItemID;
> decimal discountAmount;
>
> //assume basket pipeline is exeecuted and we get the orderForm in
> variable cartOrderForm
>
> discountAmount = 0;
> foreach(LineItem item in cartOrderForm.LineItems)
> {
>
> if(!(item["_itemlevel_discounts_applied"].Equals(System.DBNull.Value)))
> {
> discountApplicationRecords =
> (ISimpleList)item["_itemlevel_discounts_applied"];
>
> foreach(System.Collections.IDictionary discountApplicationRecord in
> discountApplicationRecords)
> {
> campaignItemID = (int)discountApplicationRecord["discount_id"];
>
> if(campaignItemID == 1)
> {
> discountAmount +=
> (decimal)discountApplicationRecord["cy_discount_amount"];
> }
> }
> }
> }
>
> return discountAmount;
| |
|
| Anyone? this is getting to be quite important now?!
Please.
|
|
|
|
|