Example #1
0
        public void Process(StringBuilder output,
                            MerchantTribe.Commerce.MerchantTribeApplication app,
                            dynamic viewBag,
                            ITagProvider tagProvider,
                            ParsedTag tag,
                            string innerContents)
        {
            string mode  = tag.GetSafeAttribute("mode");
            string href  = string.Empty;
            string sysid = tag.GetSafeAttribute("sysid");

            switch (mode.Trim().ToLowerInvariant())
            {
            case "home":
                href = app.CurrentStore.RootUrl();
                break;

            case "checkout":
                href = app.CurrentStore.RootUrlSecure() + "checkout";
                if (innerContents == string.Empty)
                {
                    innerContents = "<span>Checkout</span>";
                }
                break;

            case "cart":
                href = app.CurrentStore.RootUrl() + "cart";
                if (innerContents == string.Empty)
                {
                    string itemCount = "0";
                    string subTotal  = "$0.00";

                    if (SessionManager.CurrentUserHasCart(app.CurrentStore))
                    {
                        itemCount = SessionManager.GetCookieString(WebAppSettings.CookieNameCartItemCount(app.CurrentStore.Id), app.CurrentStore);
                        subTotal  = SessionManager.GetCookieString(WebAppSettings.CookieNameCartSubTotal(app.CurrentStore.Id), app.CurrentStore);
                        if (itemCount.Trim().Length < 1)
                        {
                            itemCount = "0";
                        }
                        if (subTotal.Trim().Length < 1)
                        {
                            subTotal = "$0.00";
                        }
                    }

                    innerContents = "<span>View Cart: " + itemCount + " items</span>";
                }
                break;

            case "carttotal":
                href = app.CurrentStore.RootUrl() + "cart";
                if (innerContents == string.Empty)
                {
                    string subTotal = "$0.00";

                    if (SessionManager.CurrentUserHasCart(app.CurrentStore))
                    {
                        subTotal = SessionManager.GetCookieString(WebAppSettings.CookieNameCartSubTotal(app.CurrentStore.Id), app.CurrentStore);
                        if (subTotal.Trim().Length < 1)
                        {
                            subTotal = "$0.00";
                        }
                    }

                    innerContents = "<span>" + subTotal + "</span>";
                }
                break;

            case "category":
                Category cat = app.CatalogServices.Categories.Find(sysid);
                href = app.CurrentStore.RootUrl() + cat.RewriteUrl;
                break;

            case "product":
                Product p = app.CatalogServices.Products.Find(sysid);
                href = app.CurrentStore.RootUrl() + p.UrlSlug;
                break;

            case "":
                string temp = tag.GetSafeAttribute("href");
                if (temp.StartsWith("http://") || temp.StartsWith("https://"))
                {
                    href = temp;
                }
                else
                {
                    href = app.CurrentStore.RootUrl() + temp.TrimStart('/');
                }
                break;

            case "myaccount":
                href = app.CurrentStore.RootUrlSecure() + "account";
                if (innerContents == string.Empty)
                {
                    innerContents = "<span>My Account</span>";
                }
                break;

            case "signin":
                string currentUserId = app.CurrentCustomerId;
                if (currentUserId == string.Empty)
                {
                    href = app.CurrentStore.RootUrlSecure() + "signin";
                    if (innerContents == string.Empty)
                    {
                        innerContents = "<span>Sign In</span>";
                    }
                }
                else
                {
                    href = app.CurrentStore.RootUrlSecure() + "signout";
                    if (innerContents == string.Empty)
                    {
                        innerContents = "<span>Sign Out</span>";
                    }
                }

                break;
            }

            //if (href.Trim().Length > 0)
            //{
            output.Append("<a href=\"" + href + "\"");
            PassAttribute(ref output, tag, "id");
            PassAttribute(ref output, tag, "title");
            PassAttribute(ref output, tag, "style");
            PassAttribute(ref output, tag, "class");
            PassAttribute(ref output, tag, "dir");
            PassAttribute(ref output, tag, "lang");
            PassAttribute(ref output, tag, "target");
            PassAttribute(ref output, tag, "rel");
            PassAttribute(ref output, tag, "media");
            PassAttribute(ref output, tag, "hreflang");
            PassAttribute(ref output, tag, "type");
            PassAttribute(ref output, tag, "name");
            output.Append(">");

            // Process any inner tags
            Processor proc = new Processor(app, viewBag, innerContents, tagProvider);

            proc.RenderForDisplay(output);

            output.Append("</a>");
            //}
        }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            //Cart Count
            string itemCount = "0";
            string subTotal  = "$0.00";

            if (SessionManager.CurrentUserHasCart(MTApp.CurrentStore))
            {
                itemCount = SessionManager.GetCookieString(WebAppSettings.CookieNameCartItemCount(MTApp.CurrentStore.Id), MTApp.CurrentStore);
                subTotal  = SessionManager.GetCookieString(WebAppSettings.CookieNameCartSubTotal(MTApp.CurrentStore.Id), MTApp.CurrentStore);
                if (itemCount.Trim().Length < 1)
                {
                    itemCount = "0";
                }
                if (subTotal.Trim().Length < 1)
                {
                    subTotal = "$0.00";
                }
            }
            ViewData["CurrentCartItemCount"] = itemCount;
            this.MTApp.CurrentRequestContext.CartItemCount = itemCount;

            ViewData["CurrentCartSubTotal"] = subTotal;
            this.MTApp.CurrentRequestContext.CartSubtotal = subTotal;

            // style sheet
            ThemeManager themes = MTApp.ThemeManager();

            ViewBag.Css = themes.CurrentStyleSheet(MTApp, System.Web.HttpContext.Current.Request.IsSecureConnection);

            // Add Google Tracker to Page
            if (MTApp.CurrentStore.Settings.Analytics.UseGoogleTracker)
            {
                ViewData["analyticstop"] = MerchantTribe.Commerce.Metrics.GoogleAnalytics.RenderLatestTracker(MTApp.CurrentStore.Settings.Analytics.GoogleTrackerId);
            }

            // Additional Meta Tags
            ViewData["AdditionalMetaTags"] = MTApp.CurrentStore.Settings.Analytics.AdditionalMetaTags;

            // Bottom Analytics Tags
            this.ViewData["analyticsbottom"] = MTApp.CurrentStore.Settings.Analytics.BottomAnalytics ?? string.Empty;

            // JQuery
            ViewBag.JqueryInclude = Helpers.Html.JQueryIncludes(Url.Content("~/scripts"), this.Request.IsSecureConnection);

            // header and footer
            string header = MerchantTribe.Commerce.Storage.DiskStorage.ReadCustomHeader(MTApp.CurrentStore.Id, MTApp.CurrentStore.Settings.ThemeId);
            string footer = MerchantTribe.Commerce.Storage.DiskStorage.ReadCustomFooter(MTApp.CurrentStore.Id, MTApp.CurrentStore.Settings.ThemeId);

            if ((header.Trim().Length < 1))
            {
                header = MerchantTribe.Commerce.Utilities.HtmlRendering.StandardHeader();
            }
            ViewData["siteheader"] = MerchantTribe.Commerce.Utilities.TagReplacer.ReplaceContentTags(header, MTApp, itemCount, Request.IsSecureConnection);
            if ((footer.Trim().Length < 1))
            {
                footer = MerchantTribe.Commerce.Utilities.HtmlRendering.StandardFooter(MTApp);
            }
            footer = footer + MerchantTribe.Commerce.Utilities.HtmlRendering.PromoTag();
            ViewData["sitefooter"] = MerchantTribe.Commerce.Utilities.TagReplacer.ReplaceContentTags(footer, MTApp, itemCount, Request.IsSecureConnection);

            //log affiliate request
            if (!((string)Request.Params[WebAppSettings.AffiliateQueryStringName] == null))
            {
                string affid = string.Empty;
                try
                {
                    affid = Request.Params[WebAppSettings.AffiliateQueryStringName];
                    string referrerURL = Request.UrlReferrer.AbsoluteUri;
                    if (referrerURL == null)
                    {
                        referrerURL = string.Empty;
                    }
                    MTApp.ContactServices.RecordAffiliateReferral(affid, referrerURL, MTApp);
                }
                catch (System.Exception ex)
                {
                    EventLog.LogEvent("BaseStorePage - Page_Init", "Error loading affiliate " + ex.Message, MerchantTribe.Web.Logging.EventLogSeverity.Warning);
                }
            }

            //If this is a private store, force login before showing anything.
            if (MTApp.CurrentStore.Settings.IsPrivateStore == true)
            {
                if (SessionManager.IsUserAuthenticated(this.MTApp) == false)
                {
                    string nameOfPage = Request.AppRelativeCurrentExecutionFilePath;
                    // Check to make sure we're not going to end up in an endless loop of redirects
                    if ((!nameOfPage.ToLower().StartsWith("~/signin")) &&
                        (!nameOfPage.ToLower().StartsWith("~/forgotpassword.aspx")) &&
                        (!nameOfPage.ToLower().StartsWith("~/contactus.aspx")))
                    {
                        Response.Redirect("~/signin?ReturnUrl=" + HttpUtility.UrlEncode(this.Request.RawUrl));
                    }
                }
            }

            ViewBag.MetaKeywords    = MTApp.CurrentStore.Settings.MetaKeywords;
            ViewBag.MetaDescription = MTApp.CurrentStore.Settings.MetaDescription;


            // Save current URL for facebook like, etc.
            ViewBag.RawUrl     = Request.Url.ToString();
            ViewBag.CurrentUrl = MTApp.CurrentStore.RootUrl() + Request.Path.TrimStart('/');

            // Social Media Globals
            ViewBag.UseFaceBook    = MTApp.CurrentStore.Settings.FaceBook.UseFaceBook;
            ViewBag.FaceBookAdmins = MTApp.CurrentStore.Settings.FaceBook.Admins;
            ViewBag.FaceBookAppId  = MTApp.CurrentStore.Settings.FaceBook.AppId;

            ViewBag.UseTwitter              = MTApp.CurrentStore.Settings.Twitter.UseTwitter;
            ViewBag.TwitterHandle           = MTApp.CurrentStore.Settings.Twitter.TwitterHandle;
            ViewBag.TwitterDefaultTweetText = MTApp.CurrentStore.Settings.Twitter.DefaultTweetText;

            ViewBag.UseGooglePlus = MTApp.CurrentStore.Settings.GooglePlus.UseGooglePlus;

            // Culture Settings
            System.Threading.Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(MTApp.CurrentStore.Settings.CultureCode);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(MTApp.CurrentStore.Settings.CultureCode);
        }
Example #3
0
        public string Process(MerchantTribeApplication app, Dictionary <string, ITagHandler> handlers, ParsedTag tag, string contents)
        {
            StringBuilder sb = new StringBuilder();

            string mode  = tag.GetSafeAttribute("mode");
            string href  = string.Empty;
            string sysid = tag.GetSafeAttribute("sysid");

            switch (mode.Trim().ToLowerInvariant())
            {
            case "home":
                href = app.CurrentStore.RootUrl();
                break;

            case "checkout":
                href = app.CurrentStore.RootUrlSecure() + "checkout";
                if (contents == string.Empty)
                {
                    contents = "<span>Checkout</span>";
                }
                break;

            case "cart":
                href = app.CurrentStore.RootUrl() + "cart";
                if (contents == string.Empty)
                {
                    string itemCount = "0";
                    string subTotal  = "$0.00";

                    if (SessionManager.CurrentUserHasCart(app.CurrentStore))
                    {
                        itemCount = SessionManager.GetCookieString(WebAppSettings.CookieNameCartItemCount(app.CurrentStore.Id), app.CurrentStore);
                        subTotal  = SessionManager.GetCookieString(WebAppSettings.CookieNameCartSubTotal(app.CurrentStore.Id), app.CurrentStore);
                        if (itemCount.Trim().Length < 1)
                        {
                            itemCount = "0";
                        }
                        if (subTotal.Trim().Length < 1)
                        {
                            subTotal = "$0.00";
                        }
                    }

                    contents = "<span>View Cart: " + itemCount + " items</span>";
                }
                break;

            case "category":
                Catalog.Category cat = app.CatalogServices.Categories.Find(sysid);
                href = app.CurrentStore.RootUrl() + cat.RewriteUrl;
                break;

            case "product":
                Catalog.Product p = app.CatalogServices.Products.Find(sysid);
                href = app.CurrentStore.RootUrl() + p.UrlSlug;
                break;

            case "":
                string temp = tag.GetSafeAttribute("href");
                if (temp.StartsWith("http://") || temp.StartsWith("https://"))
                {
                    href = temp;
                }
                else
                {
                    href = app.CurrentStore.RootUrl() + temp.TrimStart('/');
                }
                break;

            case "myaccount":
                href = app.CurrentStore.RootUrlSecure() + "account";
                if (contents == string.Empty)
                {
                    contents = "<span>My Account</span>";
                }
                break;

            case "signin":
                string currentUserId = SessionManager.GetCurrentUserId(app.CurrentStore);
                if (currentUserId == string.Empty)
                {
                    href = app.CurrentStore.RootUrlSecure() + "signin";
                    if (contents == string.Empty)
                    {
                        contents = "<span>Sign In</span>";
                    }
                }
                else
                {
                    href = app.CurrentStore.RootUrlSecure() + "signout";
                    if (contents == string.Empty)
                    {
                        contents = "<span>Sign Out</span>";
                    }
                }

                break;
            }

            if (href.Trim().Length > 0)
            {
                sb.Append("<a href=\"" + href + "\"");

                PassAttribute(ref sb, tag, "id");
                PassAttribute(ref sb, tag, "title");
                PassAttribute(ref sb, tag, "style");
                PassAttribute(ref sb, tag, "class");
                PassAttribute(ref sb, tag, "dir");
                PassAttribute(ref sb, tag, "lang");
                PassAttribute(ref sb, tag, "target");
                PassAttribute(ref sb, tag, "rel");
                PassAttribute(ref sb, tag, "media");
                PassAttribute(ref sb, tag, "hreflang");
                PassAttribute(ref sb, tag, "type");
                PassAttribute(ref sb, tag, "name");

                sb.Append(">" + contents + "</a>");
            }
            return(sb.ToString());
        }