Developer forum
E-mail notifications
ProductListTemplateExtender: Euro and DKK prices
I want to use DKK as default on all language products and add a additional EURO price to the template.
Cant find any documentation for ProductListTemplateExtender ?
Replies
Found the solution:
public class StampsProductTemplate : Dynamicweb.eCommerce.Products.ProductTemplateExtender
{
public override void ExtendTemplate(Dynamicweb.Templatev2.Template Template)
{
if (HttpContext.Current.Cache["eurorate"] == null)
{
HttpContext.Current.Cache.Insert("eurorate", NationalBanken.GetCurrencyRate("EUR"), null, DateTime.Now.AddMinutes(2), TimeSpan.Zero);
}
double priceineuroWithoutVAT = Math.Round(this.Product.Price.PriceWithoutVAT / Base.ChkDouble(HttpContext.Current.Cache["eurorate"]), 2);
double priceineuro = Math.Round(this.Product.Price.Price / Base.ChkDouble(HttpContext.Current.Cache["eurorate"]), 2);
string sPriceInEuroWithoutVAT = priceineuroWithoutVAT.ToString();
if (sPriceInEuroWithoutVAT.IndexOf(",") == (sPriceInEuroWithoutVAT.Length - 2)) { sPriceInEuroWithoutVAT += "0"; }
string sPriceInEuro = priceineuro.ToString();
if (sPriceInEuro.IndexOf(",") == (sPriceInEuro.Length - 2)) { sPriceInEuro += "0"; }
Template.SetTag("Ecom:Product.EuroRate", Base.ChkDouble(HttpContext.Current.Cache["eurorate"]).ToString());
if (Base.ChkDouble(HttpContext.Current.Cache["eurorate"]) != 0)
{
Template.SetTag("Ecom:Product.Price.EuroWithoutVAT", "€" + sPriceInEuroWithoutVAT);
Template.SetTag("Ecom:Product.Price.Euro", "€" + sPriceInEuro);
}
else
{
Template.SetTag("Ecom:Product.Price.EuroWithoutVAT", "");
Template.SetTag("Ecom:Product.Price.Euro", "");
}
base.ExtendTemplate(Template);
}
}
public class NationalBanken
{
public static double GetCurrencyRate(string countrycode)
{
System.Net.WebRequest myRequest = System.Net.WebRequest.Create("http://www.nationalbanken.dk/dndk/valuta.nsf/valuta.xml");
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream rssStream = myResponse.GetResponseStream();
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();
rssDoc.Load(rssStream);
//"exchangerates/dailyrates/currency"
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("exchangerates/dailyrates/currency");
//"exchangerates/dailyrates"
System.Xml.XmlNodeList rssHead = rssDoc.SelectNodes("exchangerates/dailyrates");
DateTime dt = new DateTime();
dt = DateTime.Now;
//i.e. country codes: USD, GBP, SEK, NOK, EUR, JPY, CHF
for (int i = 0; i < rssItems.Count; i++)
{
if(rssItems.Item(i).Attributes["code"].InnerText.Equals(countrycode))
{
double value = Base.ChkDouble(rssItems.Item(i).Attributes["rate"].InnerText) / 100;
return value;
}
}
return 0d;
}
}
You must be logged in to post in the forum