Created
February 1, 2014 09:24
-
-
Save netsi1964/8750028 to your computer and use it in GitHub Desktop.
Dynamicweb ASPX C# code to return Cart TotalPrice in JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="cs" AutoEventWireup="false" %> | |
<% | |
/* SHO 01/02/2014 10.21: Returns a JSON object containing JSON object with info of Cart TotalPrice formated as 2.999,95 | |
If no cart exists it contains -1 | |
It also has a soloution based counter which can be used to get a unique number. | |
It sets cache information in header to avoid client side caching of response. | |
Place it in /Admin/Public/ or use it in Razor | |
*/ | |
// Clear any previous reponse, importend in Razor scenaries | |
HttpContext.Current.Response.Clear(); | |
// Avoid caching of this response | |
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public); | |
HttpContext.Current.Response.Cache.SetMaxAge(new TimeSpan(0, 0, 0)); | |
// Set the response to be JSON | |
HttpContext.Current.Response.ContentType = "application/json"; | |
HttpContext.Current.Response.AddHeader("Content-type", "text/json"); | |
HttpContext.Current.Response.AddHeader("Content-type", "application/json"); | |
var cart = "-1"; | |
Application["BasketChanged"] = Dynamicweb.Base.ChkInteger(Application["BasketChanged"])+1; | |
if (System.Web.HttpContext.Current.Session["eComCart"]!=null) | |
{ | |
Dynamicweb.eCommerce.Orders.Order order = (Dynamicweb.eCommerce.Orders.Order) System.Web.HttpContext.Current.Session["eComCart"]; | |
// Format like this: 1.299,95 | |
cart = String.Format("{0:0,0.00}", order.TotalPrice); | |
} | |
%> | |
{"TotalPrice":"<%=cart%>","UniqueInt":<%=Application["BasketChanged"]%>} | |
<% | |
HttpContext.Current.Response.End(); | |
%> | |
<!-- SHO har rettet den 06/02/2014 08.50: This is at test --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also use the code in Razor without too much change to the code.
ASPX code block
Razor code block
ASXP Inline code
Razor inline code