コード例 #1
0
ファイル: showproduct.aspx.cs プロジェクト: lulzzz/BrandStore
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (AppLogic.AppConfigBool("GoNonSecureAgain"))
            {
                GoNonSecureAgain();
            }

            ProductID      = CommonLogic.QueryStringUSInt("ProductID");
            CategoryID     = CommonLogic.QueryStringUSInt("CategoryID");
            SectionID      = CommonLogic.QueryStringUSInt("SectionID");
            ManufacturerID = CommonLogic.QueryStringUSInt("ManufacturerID");
            DistributorID  = CommonLogic.QueryStringUSInt("DistributorID");
            GenreID        = CommonLogic.QueryStringUSInt("GenreID");
            VectorID       = CommonLogic.QueryStringUSInt("VectorID");

            int IsProductExist = 0;


            String ActualSEName = string.Empty;

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS(string.Format("select * from Product a with (NOLOCK) inner join (select a.ProductID, b.StoreID from Product a with (nolock) left join ProductStore b " +
                                                               "with (NOLOCK) on a.ProductID = b.ProductID) b on a.ProductID = b.ProductID where Deleted=0 and a.ProductID={0} and ({1}=0 or StoreID={2})", +
                                                               ProductID, CommonLogic.IIF(AppLogic.GlobalConfigBool("AllowProductFiltering") == true, 1, 0), AppLogic.StoreID()), dbconn))
                {
                    if (!rs.Read())
                    {
                        HttpContext.Current.Server.Transfer("pagenotfound.aspx");
                    }
                    else
                    {
                        bool published = DB.RSFieldBool(rs, "Published");

                        if (!published)
                        {
                            HttpContext.Current.Server.Transfer("pagenotfound.aspx");
                        }

                        if (AppLogic.AppConfigBool("ProductPageOutOfStockRedirect"))
                        {
                            bool trackInventoryBySizeAndColor = AppLogic.ProductTracksInventoryBySizeAndColor(ProductID);
                            bool outOfStock = AppLogic.ProbablyOutOfStock(ProductID, AppLogic.GetProductsDefaultVariantID(ProductID), trackInventoryBySizeAndColor, "Product");

                            if (outOfStock)
                            {
                                HttpContext.Current.Server.Transfer("pagenotfound.aspx");
                            }
                        }
                    }

                    String SENameINURL = CommonLogic.QueryStringCanBeDangerousContent("SEName");
                    ActualSEName = SE.MungeName(DB.RSField(rs, "SEName"));
                    if (ActualSEName != SENameINURL)
                    {
                        String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);

                        string QStr  = "?";
                        bool   first = true;
                        for (int i = 0; i < Request.QueryString.Count; i++)
                        {
                            string key = Request.QueryString.GetKey(i);
                            if ((key.Equals("productid", StringComparison.InvariantCultureIgnoreCase)) == false && (key.Equals("sename", StringComparison.InvariantCultureIgnoreCase)) == false)
                            {
                                if (!first)
                                {
                                    QStr += "&";
                                }
                                QStr += key + "=" + Request.QueryString[i];
                                first = false;
                            }
                        }
                        if (QStr.Length > 1)
                        {
                            NewURL += QStr;
                        }

                        HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                        Response.Status = "301 Moved Permanently";
                        Response.AddHeader("Location", NewURL);
                        HttpContext.Current.Response.End();
                    }


                    #region Vortx Mobile Xml Package Modification
                    m_XmlPackage = Vortx.MobileFramework.MobileXmlPackageController.XmlPackageHook(DB.RSField(rs, "XmlPackage").ToLowerInvariant(), ThisCustomer);
                    #endregion
                    IsAKit = DB.RSFieldBool(rs, "IsAKit");
                    //this part of code is written for kit products. there is no xml package which supports them.
                    if (IsAKit)
                    {
                        IsAKit = false;
                    }
                    //end
                    if (m_XmlPackage.Length == 0)
                    {
                        if (IsAKit)
                        {
                            m_XmlPackage = AppLogic.ro_DefaultProductKitXmlPackage; // provide a default
                        }
                        else
                        {
                            m_XmlPackage = AppLogic.ro_DefaultProductXmlPackage; // provide a default
                        }
                    }
                    RequiresReg = DB.RSFieldBool(rs, "RequiresRegistration");
                    ProductName = DB.RSFieldByLocale(rs, "Name", ThisCustomer.LocaleSetting);
                    //Get Customer Funds/Blue BuksPoint and Set BluBuks Point on popup.1 is id for BluBuks


                    int pvariantid = AppLogic.GetProductsDefaultVariantID(ProductID);
                    //Check if product already exist in shopping cart
                    SqlParameter[] spa = { DB.CreateSQLParameter("@CustomerID", SqlDbType.Int, 4, ThisCustomer.CustomerID, ParameterDirection.Input),
                                           DB.CreateSQLParameter("@ProductID",  SqlDbType.Int, 4, ProductID,               ParameterDirection.Input),
                                           DB.CreateSQLParameter("@VariantID",  SqlDbType.Int, 4, pvariantid,              ParameterDirection.Input),
                                           DB.CreateSQLParameter("@StoreID",    SqlDbType.Int, 4, ThisCustomer.StoreID,    ParameterDirection.Input),
                                           DB.CreateSQLParameter("@IsExist",    SqlDbType.Int, 4, null,                    ParameterDirection.Output) };
                    IsProductExist         = DB.ExecuteStoredProcInt("dbo.aspdnsf_IsProductExistsinShoppingCart", spa);
                    hdnIsProductExist.Text = IsProductExist.ToString();
                    hdnProductID.Text      = ProductID.ToString();
                    hdnVariantID.Text      = pvariantid.ToString();
                    hdnCustomerID.Text     = ThisCustomer.CustomerID.ToString();

                    //end check if product already exist in shopping cart

                    //Apply fund
                    decimal pvprice = AppLogic.GetVariantPrice(pvariantid);
                    hdnButtonName.Text    = "AddToCartButton_" + ProductID + "_" + pvariantid;
                    hdncustomerlevel.Text = Convert.ToString(ThisCustomer.CustomerLevelID);
                    Decimal productcategoryfund = Convert.ToDecimal(hdnProductFundAmount.Text);
                    Decimal productprice        = Convert.ToDecimal(pvprice);
                    CustomerFunds = AuthenticationSSO.GetCustomerFund(ThisCustomer.CustomerID);
                    if (CustomerFunds.Count > 0)
                    {
                        //BluBucks
                        CustomerFund tempBluBucksfund = CustomerFunds.Find(x => x.FundID == Convert.ToInt32(FundType.BLUBucks));
                        if (tempBluBucksfund != null)
                        {
                            BluBuksPoints           = CustomerFunds.Find(x => x.FundID == 1).AmountAvailable.ToString();
                            hdnBluBucktsPoints.Text = Math.Round(Convert.ToDecimal(BluBuksPoints), 2).ToString();
                            ppointscount.InnerText  = "You have " + Math.Round(Convert.ToDecimal(BluBuksPoints), 2) + " BLU™ Bucks you can use to purchase items.";
                        }
                        else
                        {
                            BluBuksPoints           = "0".ToString();
                            hdnBluBucktsPoints.Text = Math.Round(Convert.ToDecimal(BluBuksPoints), 2).ToString();
                            ppointscount.InnerText  = "You have " + Math.Round(Convert.ToDecimal(BluBuksPoints), 2) + " BLU™ Bucks you can use to purchase items.";
                        }

                        //Category Fund
                        hdnProductFundID.Text = Convert.ToString(DB.RSFieldInt(rs, "FundID"));
                        if (hdnProductFundID.Text.Trim() != "" && hdnProductFundID.Text != "0")
                        {
                            CustomerFund tempfund = CustomerFunds.Find(x => x.FundID == Convert.ToInt32(hdnProductFundID.Text));
                            if (tempfund != null)
                            {
                                hdnProductFundAmount.Text = tempfund.AmountAvailable.ToString();
                                hdnFundName.Text          = tempfund.FundName;
                                productcategoryfund       = Convert.ToDecimal(hdnProductFundAmount.Text);
                            }
                            else
                            {
                                tempfund = CustomerFunds.Find(x => x.FundID == Convert.ToInt32(FundType.SOFFunds));//for sales rep
                                if (tempfund != null)
                                {
                                    hdnProductFundAmount.Text = tempfund.AmountAvailable.ToString();
                                    hdnFundName.Text          = tempfund.FundName;
                                    productcategoryfund       = Convert.ToDecimal(hdnProductFundAmount.Text);
                                }
                                else
                                {
                                    hdnProductFundAmount.Text = "0";
                                    productcategoryfund       = Convert.ToDecimal("0.00");
                                }
                                hdnProductFundID.Text = "2";
                            }
                        }
                        else
                        {
                            CustomerFund tempfund = CustomerFunds.Find(x => x.FundID == Convert.ToInt32(FundType.SOFFunds));//for sales rep
                            if (tempfund != null)
                            {
                                hdnProductFundAmount.Text = tempfund.AmountAvailable.ToString();
                                hdnFundName.Text          = tempfund.FundName;
                                productcategoryfund       = Convert.ToDecimal(hdnProductFundAmount.Text);
                                hdnProductFundID.Text     = "2";
                            }
                            else
                            {
                                hdnProductFundAmount.Text = "0";
                                productcategoryfund       = Convert.ToDecimal("0.00");
                            }
                        }

                        hdnproductprice.Text = productprice.ToString().Replace("$", "").Replace(",", "").Replace(" ", "");
                        if (this.IsPostBack)
                        {
                            hdnquantity.Text = Request.Form["Quantity_1_1"];
                        }
                        else
                        {
                            hdnquantity.Text = "1";
                        }

                        if (String.IsNullOrEmpty(hdnquantity.Text) || String.IsNullOrWhiteSpace(hdnquantity.Text))
                        {
                            hdnquantity.Text = "0";
                        }
                        productprice = productprice * Convert.ToInt32(hdnquantity.Text);
                        if (productcategoryfund < productprice)
                        {
                            productprice = productprice - productcategoryfund;
                            hdnProductFundAmountUsed.Text = (Convert.ToDecimal(productcategoryfund)).ToString();
                        }
                        else
                        {
                            productcategoryfund           = productcategoryfund - productprice;
                            hdnProductFundAmountUsed.Text = (Convert.ToDecimal(productprice)).ToString();
                            productprice        = 0;
                            txtBluBuksUsed.Text = productprice.ToString();
                        }
                        hdnpricewithfund.Text = productprice.ToString();
                        //End apply fund
                        //End
                    }
                    else
                    {
                        hdnpricewithfund.Text   = productprice.ToString();
                        hdnBluBucktsPoints.Text = "0";
                        ppointscount.InnerText  = "You have " + Math.Round(Convert.ToDecimal(0.00), 2) + " BLU™ Bucks you can use to purchase your items.";
                    }

                    CategoryHelper     = AppLogic.LookupHelper("Category", 0);
                    SectionHelper      = AppLogic.LookupHelper("Section", 0);
                    ManufacturerHelper = AppLogic.LookupHelper("Manufacturer", 0);
                    DistributorHelper  = AppLogic.LookupHelper("Distributor", 0);
                    GenreHelper        = AppLogic.LookupHelper("Genre", 0);
                    VectorHelper       = AppLogic.LookupHelper("Vector", 0);

                    String SEName = String.Empty;
                    if (DB.RSFieldByLocale(rs, "SETitle", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SETitle = Security.HtmlEncode(AppLogic.AppConfig("StoreName") + " - " + ProductName);
                    }
                    else
                    {
                        SETitle = DB.RSFieldByLocale(rs, "SETitle", ThisCustomer.LocaleSetting);
                    }
                    if (DB.RSFieldByLocale(rs, "SEDescription", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SEDescription = Security.HtmlEncode(ProductName);
                    }
                    else
                    {
                        SEDescription = DB.RSFieldByLocale(rs, "SEDescription", ThisCustomer.LocaleSetting);
                    }
                    if (DB.RSFieldByLocale(rs, "SEKeywords", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SEKeywords = Security.HtmlEncode(ProductName);
                    }
                    else
                    {
                        SEKeywords = DB.RSFieldByLocale(rs, "SEKeywords", ThisCustomer.LocaleSetting);
                    }
                    SENoScript = DB.RSFieldByLocale(rs, "SENoScript", ThisCustomer.LocaleSetting);
                }
            }

            //Log all views of unknown and registered customer
            if (AppLogic.AppConfigBool("DynamicRelatedProducts.Enabled") || AppLogic.AppConfigBool("RecentlyViewedProducts.Enabled"))
            {
                ThisCustomer.LogProductView(ProductID);
            }

            if (IsAKit && !Vortx.MobileFramework.MobileHelper.isMobile())
            {
                Server.Transfer(ResolveClientUrl("~/kitproduct.aspx"), true);
                return;
            }
            else if (IsAKit && Vortx.MobileFramework.MobileHelper.isMobile())
            {
                Server.Transfer(ResolveClientUrl("~/mobilekitproduct.aspx"), true);
                return;
            }

            CategoryName     = CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting);
            SectionName      = SectionHelper.GetEntityName(SectionID, ThisCustomer.LocaleSetting);
            ManufacturerName = ManufacturerHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting);
            DistributorName  = DistributorHelper.GetEntityName(DistributorID, ThisCustomer.LocaleSetting);
            GenreName        = GenreHelper.GetEntityName(GenreID, ThisCustomer.LocaleSetting);
            VectorName       = VectorHelper.GetEntityName(VectorID, ThisCustomer.LocaleSetting);

            if (ManufacturerID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = ManufacturerID.ToString();
                Profile.LastViewedEntityInstanceName = ManufacturerName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (DistributorID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_DistributorEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = DistributorID.ToString();
                Profile.LastViewedEntityInstanceName = DistributorName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (GenreID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_GenreEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = GenreID.ToString();
                Profile.LastViewedEntityInstanceName = GenreName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (VectorID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_VectorEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = VectorID.ToString();
                Profile.LastViewedEntityInstanceName = VectorName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (CategoryID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = CategoryID.ToString();
                Profile.LastViewedEntityInstanceName = CategoryName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (SectionID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = SectionID.ToString();
                Profile.LastViewedEntityInstanceName = SectionName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }



            SourceEntity             = Profile.LastViewedEntityName;
            SourceEntityInstanceName = Profile.LastViewedEntityInstanceName;
            SourceEntityID           = int.Parse(CommonLogic.IIF(CommonLogic.IsInteger(Profile.LastViewedEntityInstanceID), Profile.LastViewedEntityInstanceID, "0"));

            // validate that source entity id is actually valid for this product:
            if (SourceEntityID != 0)
            {
                String sqlx = string.Format("select count(*) as N from productentity a with (nolock) inner join (select distinct a.entityid, a.EntityType from productentity a with (nolock) left join EntityStore b with (nolock) " +
                                            "on a.EntityID = b.EntityID where ({0} = 0 or StoreID = {1})) b on a.EntityID = b.EntityID and a.EntityType=b.EntityType where ProductID = {2} and a.EntityID = {3} and a.EntityType = {4}"
                                            , CommonLogic.IIF(AppLogic.GlobalConfigBool("AllowEntityFiltering") == true, 1, 0), AppLogic.StoreID(), ProductID, SourceEntityID, DB.SQuote(SourceEntity));
                if (DB.GetSqlN(sqlx) == 0)
                {
                    SourceEntityID = 0;
                }
            }

            // we had no entity context coming in, try to find a category context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    CategoryID   = SourceEntityID;
                    CategoryName = CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = CategoryID.ToString();
                    Profile.LastViewedEntityInstanceName = CategoryName;

                    SourceEntity             = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = CategoryName;
                }
            }

            // we had no entity context coming in, try to find a section context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    SectionID   = SourceEntityID;
                    SectionName = CategoryHelper.GetEntityName(SectionID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = SectionID.ToString();
                    Profile.LastViewedEntityInstanceName = SectionName;

                    SourceEntity             = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = SectionName;
                }
            }

            // we had no entity context coming in, try to find a Manufacturer context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    ManufacturerID   = SourceEntityID;
                    ManufacturerName = CategoryHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = ManufacturerID.ToString();
                    Profile.LastViewedEntityInstanceName = ManufacturerName;

                    SourceEntity             = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = ManufacturerName;
                }
            }

            // build up breadcrumb if we need:
            SectionTitle = Breadcrumb.GetProductBreadcrumb(ProductID, ProductName, SourceEntity, SourceEntityID, ThisCustomer);
            //Reset LastViewedEntityInstanceID to zero if no entities are mapped to the product so the left nav will render properly.
            if (SourceEntityID <= 0)
            {
                HttpContext.Current.Profile.SetPropertyValue("LastViewedEntityInstanceID", "0");
            }

            if (RequiresReg && !ThisCustomer.IsRegistered)
            {
                m_PageOutput       += "<b>" + AppLogic.GetString("showproduct.aspx.1", SkinID, ThisCustomer.LocaleSetting) + "</b><a href=\"signin.aspx?returnurl=" + CommonLogic.GetThisPageName(false) + "?ProductID=" + ProductID.ToString() + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING").Trim().Length > 0, "&" + Security.HtmlEncode(Security.UrlEncode(CommonLogic.ServerVariables("QUERY_STRING"))), String.Empty) + "\">" + AppLogic.GetString("showproduct.aspx.2", SkinID, ThisCustomer.LocaleSetting) + "</a> " + AppLogic.GetString("showproduct.aspx.3", SkinID, ThisCustomer.LocaleSetting);
                m_PageOutputCustom += "<b>" + AppLogic.GetString("showproduct.aspx.1", SkinID, ThisCustomer.LocaleSetting) + "</b><a href=\"signin.aspx?returnurl=" + CommonLogic.GetThisPageName(false) + "?ProductID=" + ProductID.ToString() + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING").Trim().Length > 0, "&" + Security.HtmlEncode(Security.UrlEncode(CommonLogic.ServerVariables("QUERY_STRING"))), String.Empty) + "\">" + AppLogic.GetString("showproduct.aspx.2", SkinID, ThisCustomer.LocaleSetting) + "</a> " + AppLogic.GetString("showproduct.aspx.3", SkinID, ThisCustomer.LocaleSetting);
            }
            else
            {
                AppLogic.eventHandler("ViewProductPage").CallEvent("&ViewProductPage=true");

                // check if the postback was caused by an addtocart button
                if (this.IsPostBack && this.IsAddToCartPostBack)
                {
                    HandleAddToCart();
                    return;
                }

                DB.ExecuteSQL("update product set Looks=Looks+1 where ProductID=" + ProductID.ToString());

                m_PageOutput       = "<!-- XmlPackage: " + m_XmlPackage + " -->\n";
                m_PageOutputCustom = "<!-- XmlPackage: " + m_XmlPackage + " -->\n";
                if (m_XmlPackage.Length == 0)
                {
                    m_PageOutput       += "<p><b><font color=red>XmlPackage format was chosen, but no XmlPackage was specified!</font></b></p>";
                    m_PageOutputCustom += "<p><b><font color=red>XmlPackage format was chosen, but no XmlPackage was specified!</font></b></p>";
                }
                else
                {
                    using (XmlPackage2 p = new XmlPackage2(m_XmlPackage, ThisCustomer, SkinID, "", "EntityName=" + SourceEntity + "&EntityID=" + SourceEntityID.ToString() + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING").IndexOf("cartrecid") != -1, "&cartrecid=" + CommonLogic.QueryStringUSInt("cartrecid").ToString(), "&showproduct=1"), String.Empty, true))
                    {
                        m_PageOutput += AppLogic.RunXmlPackage(p, base.GetParser, ThisCustomer, SkinID, true, true);

                        if (p.SectionTitle != "")
                        {
                            SectionTitle = p.SectionTitle;
                        }
                        if (p.SETitle != "")
                        {
                            SETitle = p.SETitle;
                        }
                        if (p.SEDescription != "")
                        {
                            SEDescription = p.SEDescription;
                        }
                        if (p.SEKeywords != "")
                        {
                            SEKeywords = p.SEKeywords;
                        }
                        if (p.SENoScript != "")
                        {
                            SENoScript = p.SENoScript;
                        }
                    }
                    //Get add to cart button for popup
                    using (XmlPackage2 p = new XmlPackage2("product.SimpleProductCustom.xml.config", ThisCustomer, SkinID, "", "EntityName=" + SourceEntity + "&EntityID=" + SourceEntityID.ToString() + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING").IndexOf("cartrecid") != -1, "&cartrecid=" + CommonLogic.QueryStringUSInt("cartrecid").ToString(), "&showproduct=1"), String.Empty, true))
                    {
                        m_PageOutputCustom = AppLogic.RunXmlPackage(p, base.GetParser, ThisCustomer, SkinID, true, true);
                        LiteralCustom.Text = m_PageOutputCustom;
                    }
                }
            }
            if (!this.IsPostBack)
            {
                litOutput.Text = m_PageOutput;
            }

            GetParentCategory();
            if (!string.IsNullOrEmpty(SourceEntityInstanceName) && !string.IsNullOrEmpty(parentCategoryID))
            {
                parentCategoryName = CategoryHelper.GetEntityName(Convert.ToInt32(parentCategoryID), ThisCustomer.LocaleSetting);

                ((System.Web.UI.WebControls.HyperLink)Master.FindControl("lnkCategory")).Text        = parentCategoryName;
                ((System.Web.UI.WebControls.HyperLink)Master.FindControl("lnkCategory")).NavigateUrl = "~/c-" + parentCategoryID + "-" + parentCategoryName.Replace(" ", "-") + ".aspx";

                ((System.Web.UI.WebControls.Label)Master.FindControl("lblSperator")).Text = ">>";

                ((System.Web.UI.WebControls.HyperLink)Master.FindControl("lnkSubCategory")).Text        = SourceEntityInstanceName;
                ((System.Web.UI.WebControls.HyperLink)Master.FindControl("lnkSubCategory")).NavigateUrl = "~/c-" + SourceEntityID + "-" + SourceEntityInstanceName.Replace(" ", "-") + ".aspx";
            }

            //get fund BluBucks Percentage
            BudgetPercentageRatio FundPercentage = AuthenticationSSO.GetBudgetPercentageRatio(ThisCustomer.CustomerLevelID, Convert.ToInt32(parentCategoryID));
            hdnBudgetPercentValue.Text = FundPercentage.BudgetPercentageValue.ToString();
            ppercentage.InnerText      = "You can pay for up to " + hdnBudgetPercentValue.Text + "% of this item's cost with BLU™ Bucks.";
            hdnProductCategoryID.Text  = parentCategoryID.ToString();
            LstInventories             = JsonConvert.SerializeObject(AppLogic.LstInventory);
            hdnInventory.Text          = JsonConvert.SerializeObject(AppLogic.LstInventory);
        }
コード例 #2
0
        private void SetupProductDefaults()
        {
            String ActualSEName = string.Empty;

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS("select * from Product  with (NOLOCK)  where Deleted=0 and ProductID=" + ProductID.ToString(), dbconn))
                {
                    if (!rs.Read())
                    {
                        HttpContext.Current.Server.Transfer("pagenotfound.aspx");
                    }
                    else
                    {
                        bool a = DB.RSFieldBool(rs, "Published");
                        if (!a)
                        {
                            HttpContext.Current.Server.Transfer("pagenotfound.aspx");
                        }
                    }

                    String SENameINURL = CommonLogic.QueryStringCanBeDangerousContent("SEName");
                    ActualSEName = SE.MungeName(DB.RSField(rs, "SEName"));
                    if (ActualSEName != SENameINURL)
                    {
                        String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(ProductID, ActualSEName);

                        string QStr  = "?";
                        bool   first = true;
                        for (int i = 0; i < Request.QueryString.Count; i++)
                        {
                            string key = Request.QueryString.GetKey(i);
                            if ((key.Equals("productid", StringComparison.InvariantCultureIgnoreCase)) == false && (key.Equals("sename", StringComparison.InvariantCultureIgnoreCase)) == false)
                            {
                                if (!first)
                                {
                                    QStr += "&";
                                }
                                QStr += key + "=" + Request.QueryString[i].ToString();
                                first = false;
                            }
                        }
                        if (QStr.Length > 1)
                        {
                            NewURL += QStr;
                        }

                        HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                        Response.Status = "301 Moved Permanently";
                        Response.AddHeader("Location", NewURL);
                        HttpContext.Current.Response.End();
                    }

                    m_XmlPackage = DB.RSField(rs, "XmlPackage").ToLowerInvariant();
                    IsAKit       = DB.RSFieldBool(rs, "IsAKit");
                    if (m_XmlPackage.Length == 0)
                    {
                        if (IsAKit)
                        {
                            m_XmlPackage = AppLogic.ro_DefaultProductKitXmlPackage; // provide a default
                        }
                        else
                        {
                            m_XmlPackage = AppLogic.ro_DefaultProductXmlPackage; // provide a default
                        }
                    }
                    RequiresReg = DB.RSFieldBool(rs, "RequiresRegistration");
                    ProductName = DB.RSFieldByLocale(rs, "Name", ThisCustomer.LocaleSetting);

                    CategoryHelper     = AppLogic.LookupHelper("Category", 0);
                    SectionHelper      = AppLogic.LookupHelper("Section", 0);
                    ManufacturerHelper = AppLogic.LookupHelper("Manufacturer", 0);
                    DistributorHelper  = AppLogic.LookupHelper("Distributor", 0);
                    GenreHelper        = AppLogic.LookupHelper("Genre", 0);
                    VectorHelper       = AppLogic.LookupHelper("Vector", 0);

                    String SEName = String.Empty;
                    if (DB.RSFieldByLocale(rs, "SETitle", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SETitle = Security.HtmlEncode(AppLogic.AppConfig("StoreName") + " - " + ProductName);
                    }
                    else
                    {
                        SETitle = DB.RSFieldByLocale(rs, "SETitle", ThisCustomer.LocaleSetting);
                    }
                    if (DB.RSFieldByLocale(rs, "SEDescription", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SEDescription = Security.HtmlEncode(ProductName);
                    }
                    else
                    {
                        SEDescription = DB.RSFieldByLocale(rs, "SEDescription", ThisCustomer.LocaleSetting);
                    }
                    if (DB.RSFieldByLocale(rs, "SEKeywords", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SEKeywords = Security.HtmlEncode(ProductName);
                    }
                    else
                    {
                        SEKeywords = DB.RSFieldByLocale(rs, "SEKeywords", ThisCustomer.LocaleSetting);
                    }
                    SENoScript = DB.RSFieldByLocale(rs, "SENoScript", ThisCustomer.LocaleSetting);
                }
            }

            //Log all views of unknown and registered customer
            if (AppLogic.AppConfigBool("DynamicRelatedProducts.Enabled") || AppLogic.AppConfigBool("RecentlyViewedProducts.Enabled"))
            {
                ThisCustomer.LogProductView(ProductID);
            }

            CategoryName     = CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting);
            SectionName      = SectionHelper.GetEntityName(SectionID, ThisCustomer.LocaleSetting);
            ManufacturerName = ManufacturerHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting);
            DistributorName  = DistributorHelper.GetEntityName(DistributorID, ThisCustomer.LocaleSetting);
            GenreName        = GenreHelper.GetEntityName(GenreID, ThisCustomer.LocaleSetting);
            VectorName       = VectorHelper.GetEntityName(VectorID, ThisCustomer.LocaleSetting);

            String SourceEntityInstanceName = String.Empty;

            if (ManufacturerID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = ManufacturerID.ToString();
                Profile.LastViewedEntityInstanceName = ManufacturerName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (DistributorID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_DistributorEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = DistributorID.ToString();
                Profile.LastViewedEntityInstanceName = DistributorName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (GenreID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_GenreEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = GenreID.ToString();
                Profile.LastViewedEntityInstanceName = GenreName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (VectorID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_VectorEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = VectorID.ToString();
                Profile.LastViewedEntityInstanceName = VectorName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (CategoryID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = CategoryID.ToString();
                Profile.LastViewedEntityInstanceName = CategoryName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (SectionID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = SectionID.ToString();
                Profile.LastViewedEntityInstanceName = SectionName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }

            SourceEntity             = Profile.LastViewedEntityName;
            SourceEntityInstanceName = Profile.LastViewedEntityInstanceName;
            SourceEntityID           = int.Parse(CommonLogic.IIF(CommonLogic.IsInteger(Profile.LastViewedEntityInstanceID), Profile.LastViewedEntityInstanceID, "0"));

            // validate that source entity id is actually valid for this product:
            if (SourceEntityID != 0)
            {
                String sqlx = "select count(*) as N from dbo.productentity with (NOLOCK) where ProductID=" + ProductID.ToString() + " and EntityID=" + SourceEntityID.ToString() + " and EntityType = " + DB.SQuote(SourceEntity);
                if (DB.GetSqlN(sqlx) == 0)
                {
                    SourceEntityID = 0;
                }
            }

            // we had no entity context coming in, try to find a category context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    CategoryID   = SourceEntityID;
                    CategoryName = CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = CategoryID.ToString();
                    Profile.LastViewedEntityInstanceName = CategoryName;

                    SourceEntity             = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = CategoryName;
                }
            }

            // we had no entity context coming in, try to find a section context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    SectionID   = SourceEntityID;
                    SectionName = CategoryHelper.GetEntityName(SectionID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = SectionID.ToString();
                    Profile.LastViewedEntityInstanceName = SectionName;

                    SourceEntity             = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = SectionName;
                }
            }

            // we had no entity context coming in, try to find a Manufacturer context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    ManufacturerID   = SourceEntityID;
                    ManufacturerName = CategoryHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = ManufacturerID.ToString();
                    Profile.LastViewedEntityInstanceName = ManufacturerName;

                    SourceEntity             = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = ManufacturerName;
                }
            }

            // build up breadcrumb if we need:
            SectionTitle = Breadcrumb.GetProductBreadcrumb(ProductID, ProductName, SourceEntity, SourceEntityID, ThisCustomer);
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            EntityHelper CategoryHelper = AppLogic.LookupHelper("Category", 0);

            ThisCustomer = (Page as SkinBase).ThisCustomer;
            baseSkinID   = (Page as SkinBase).SkinID;

            using (SqlConnection conn = DB.dbConn())
            {
                conn.Open();
                using (IDataReader rs = DB.GetRS("select p.*, pv.name variantname from product p  with (NOLOCK)  join productvariant pv  with (NOLOCK)  on p.ProductID = pv.ProductID and pv.isdefault = 1 where p.ProductID=" + ProductID.ToString(), conn))
                {
                    if (!rs.Read())
                    {
                        Response.Redirect("default.aspx");
                    }
                    SEName      = DB.RSField(rs, "SEName");
                    ProductName = DB.RSFieldByLocale(rs, "Name", ThisCustomer.LocaleSetting);
                    VariantName = DB.RSFieldByLocale(rs, "VariantName", ThisCustomer.LocaleSetting);

                    RequiresReg        = DB.RSFieldBool(rs, "RequiresRegistration");
                    ProductDescription = DB.RSFieldByLocale(rs, "Description", ThisCustomer.LocaleSetting);
                    if (AppLogic.ReplaceImageURLFromAssetMgr)
                    {
                        ProductDescription = ProductDescription.Replace("../images", "images");
                    }
                    String FileDescription = new ProductDescriptionFile(ProductID, ThisCustomer.LocaleSetting, baseSkinID).Contents;
                    if (FileDescription.Length != 0)
                    {
                        ProductDescription += "<div align=\"left\">" + FileDescription + "</div>";
                    }
                }
            }

            String SourceEntityInstanceName = String.Empty;

            SourceEntity             = Profile.LastViewedEntityName;
            SourceEntityInstanceName = Profile.LastViewedEntityInstanceName;
            SourceEntityID           = int.Parse(CommonLogic.IIF(CommonLogic.IsInteger(Profile.LastViewedEntityInstanceID), Profile.LastViewedEntityInstanceID, "0"));;

            // validate that source entity id is actually valid for this product:
            if (SourceEntityID != 0)
            {
                String sqlx = "select count(*) as N from dbo.productentity  with (NOLOCK)  where ProductID=" + ProductID.ToString() + " and EntityID=" + SourceEntityID.ToString() + " and EntityType = " + DB.SQuote(SourceEntity);
                if (DB.GetSqlN(sqlx) == 0)
                {
                    SourceEntityID = 0;
                }
            }

            // we had no entity context coming in, try to find a category context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    CategoryID   = SourceEntityID;
                    CategoryName = CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting);
                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = CategoryID.ToString();
                    Profile.LastViewedEntityInstanceName = CategoryName;
                    SourceEntity             = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = CategoryName;
                }
            }

            // we had no entity context coming in, try to find a section context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    SectionID   = SourceEntityID;
                    SectionName = CategoryHelper.GetEntityName(SectionID, ThisCustomer.LocaleSetting);
                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = SectionID.ToString();
                    Profile.LastViewedEntityInstanceName = SectionName;
                    SourceEntity             = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = SectionName;
                }
            }

            // we had no entity context coming in, try to find a Manufacturer context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    ManufacturerID                       = SourceEntityID;
                    ManufacturerName                     = CategoryHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting);
                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = ManufacturerID.ToString();
                    Profile.LastViewedEntityInstanceName = ManufacturerName;
                    SourceEntity             = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = ManufacturerName;
                }
            }

            // build up breadcrumb if we need:
            (Page as SkinBase).SectionTitle = Breadcrumb.GetProductBreadcrumb(ProductID, ProductName, SourceEntity, SourceEntityID, ThisCustomer);

            reqToAddress.ErrorMessage     = AppLogic.GetString("emailproduct.aspx.13", baseSkinID, ThisCustomer.LocaleSetting);
            regexToAddress.ErrorMessage   = AppLogic.GetString("emailproduct.aspx.14", baseSkinID, ThisCustomer.LocaleSetting);
            reqFromAddress.ErrorMessage   = AppLogic.GetString("emailproduct.aspx.16", baseSkinID, ThisCustomer.LocaleSetting);
            regexFromAddress.ErrorMessage = AppLogic.GetString("emailproduct.aspx.17", baseSkinID, ThisCustomer.LocaleSetting);

            if (!this.IsPostBack)
            {
                InitializePageContent();
            }
        }
コード例 #4
0
        public ActionResult Detail(int id, string searchEngineName, int?cartRecordId = null)
        {
            var product = new Product(id);


            // Make sure we should show the product
            if (product.ProductID == 0 ||
                !product.Published ||
                !product.IsMappedToStore())
            {
                throw new HttpException(404, null);
            }

            var outOfStockLevel = AppLogic.AppConfigNativeInt("HideProductsWithLessThanThisInventoryLevel");

            if (AppLogic.AppConfigBool("ProductPageOutOfStockRedirect") &&
                outOfStockLevel != -1)
            {
                if (AppLogic.DeterminePurchasableQuantity(product.ProductID,
                                                          AppLogic.GetProductsDefaultVariantID(product.ProductID),
                                                          AppLogic.ProductTracksInventoryBySizeAndColor(product.ProductID),
                                                          "Product") < outOfStockLevel)
                {
                    throw new HttpException(404, null);
                }
            }

            // 301 Redirect to the correct search engine name in the url if it is wrong
            if (!string.IsNullOrEmpty(product.SEName) &&
                !StringComparer.OrdinalIgnoreCase.Equals(searchEngineName, product.SEName))
            {
                return(RedirectPermanent(Url.BuildProductLink(id, product.SEName)));
            }
            else
            {
                SysLog.LogMessage(
                    message: "Invalid product se name.",
                    details: string.Format("Product {0} does not have an SE Name set.", product.ProductID),
                    messageType: MessageTypeEnum.Informational,
                    messageSeverity: MessageSeverityEnum.Alert);
            }

            // Set the xmlpackage
            var xmlpackageName = !string.IsNullOrEmpty(product.XmlPackage)
                                ? product.XmlPackage
                                : AppLogic.ro_DefaultProductXmlPackage;

            // Kits always get the default kit xmlpackage
            if (product.IsAKit)
            {
                xmlpackageName = "page.kitheader.xml.config";
            }

            var customer = HttpContext.GetCustomer();

            // Get the context of where we've come from
            var sourceEntityInfo = GetSourceEntityInfo(product.ProductID, customer.LocaleSetting);

            // Save source entity info to the profile
            Profile["LastViewedEntityName"]         = sourceEntityInfo.Type;
            Profile["LastViewedEntityInstanceID"]   = sourceEntityInfo.Id.ToString();
            Profile["LastViewedEntityInstanceName"] = sourceEntityInfo.Name;

            if (!product.RequiresRegistration || customer.IsRegistered)
            {
                //Log views to generate dynamic related product results
                if (AppLogic.AppConfigBool("DynamicRelatedProducts.Enabled") && !AppLogic.UserAgentIsKnownBot())
                {
                    customer.LogProductView(product.ProductID);
                }

                //Fire an event
                AppLogic.eventHandler("ViewProductPage").CallEvent("&ViewProductPage=true");

                //Update Product looks(views count)
                DB.ExecuteSQL("update product set Looks=Looks+1 where ProductID = @ProductId", new SqlParameter[] { new SqlParameter("ProductId", product.ProductID) });
            }

            // Additional runtime parameters
            var runtimeParameters = string.Format("EntityName={0}&EntityID={1}", sourceEntityInfo.Type, sourceEntityInfo.Id);

            if (Request.Url.Query.Contains("cartrecid"))
            {
                runtimeParameters += string.Format("&cartrecid={0}", CommonLogic.QueryStringUSInt("cartrecid"));
            }

            // Add a showproduct runtime node
            runtimeParameters += "&showproduct=1";

            // Breadcrumb and meta tags
            var pageTitle   = Breadcrumb.GetProductBreadcrumb(product.ProductID, product.LocaleName, sourceEntityInfo.Type, sourceEntityInfo.Id, customer);
            var pageContent = string.Empty;

            var metaTitle = XmlCommon.GetLocaleEntry(product.SETitle, customer.LocaleSetting, true);

            if (string.IsNullOrEmpty(metaTitle))
            {
                metaTitle = Server.HtmlEncode(string.Format("{0} - {1}", AppLogic.AppConfig("StoreName"), product.LocaleName));
            }

            var metaDescription = XmlCommon.GetLocaleEntry(product.SEDescription, customer.LocaleSetting, true);

            if (string.IsNullOrEmpty(metaDescription))
            {
                metaDescription = Server.HtmlEncode(product.LocaleName);
            }

            var metaKeywords = XmlCommon.GetLocaleEntry(product.SEKeywords, customer.LocaleSetting, true);

            if (string.IsNullOrEmpty(metaKeywords))
            {
                metaKeywords = Server.HtmlEncode(product.LocaleName);
            }

            var parser = new Parser();

            var xmlpackage = new XmlPackage(
                packageName: xmlpackageName,
                customer: customer,
                additionalRuntimeParms: runtimeParameters,
                htmlHelper: ControllerContext.GetHtmlHelper());

            pageContent = AppLogic.RunXmlPackage(xmlpackage, parser, customer, customer.SkinID, true, true);
            if (!string.IsNullOrEmpty(xmlpackage.SectionTitle))
            {
                pageTitle = xmlpackage.SectionTitle;
            }

            if (!string.IsNullOrEmpty(xmlpackage.SETitle))
            {
                metaTitle = xmlpackage.SETitle;
            }

            if (!string.IsNullOrEmpty(xmlpackage.SEDescription))
            {
                metaDescription = xmlpackage.SEDescription;
            }

            if (xmlpackage.SEKeywords != string.Empty)
            {
                metaKeywords = xmlpackage.SEKeywords;
            }

            // Build the view model
            var productViewModel = new ProductViewModel
            {
                Id               = product.ProductID,
                Name             = XmlCommon.GetLocaleEntry(product.LocaleName, customer.LocaleSetting, true),
                MetaTitle        = metaTitle,
                MetaDescription  = metaDescription,
                MetaKeywords     = metaKeywords,
                PageTitle        = pageTitle,
                PageContent      = pageContent,
                LoginRequired    = product.RequiresRegistration && !customer.IsRegistered,
                IsAKit           = product.IsAKit,
                XmlPackageName   = xmlpackageName,
                CartRecordId     = cartRecordId,
                SchemaProductUrl = string.Format("{0}://schema.org/Product", Request.Url.Scheme)
            };

            // Override the layout
            var layoutName = string.Empty;

            if (AppLogic.AppConfigBool("TemplateSwitching.Enabled"))
            {
                layoutName = AppLogic.GetCurrentEntityTemplateName(sourceEntityInfo.Type, sourceEntityInfo.Id);
            }

            // Kits use a separate view
            var viewName = product.IsAKit
                                ? ViewNames.KitDetail
                                : ViewNames.Detail;

            return(!string.IsNullOrEmpty(layoutName)
                                ? View(viewName, layoutName, productViewModel)
                                : View(viewName, productViewModel));
        }
コード例 #5
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (AppLogic.AppConfigBool("GoNonSecureAgain"))
            {
                SkinBase.GoNonSecureAgain();
            }

            ProductID      = CommonLogic.QueryStringUSInt("ProductID");
            CategoryID     = CommonLogic.QueryStringUSInt("CategoryID");
            SectionID      = CommonLogic.QueryStringUSInt("SectionID");
            ManufacturerID = CommonLogic.QueryStringUSInt("ManufacturerID");
            DistributorID  = CommonLogic.QueryStringUSInt("DistributorID");
            GenreID        = CommonLogic.QueryStringUSInt("GenreID");
            VectorID       = CommonLogic.QueryStringUSInt("VectorID");

            if (ProductID == 0)
            {
                if (IsAddToCartPostBack)
                {
                    int    PackID                 = 0;
                    int    packProductID          = 0;
                    int    packVariantID          = 0;
                    int    packQuantity           = 0;
                    int    packProductTypeID      = 0;
                    bool   FromCart               = false;
                    int    packCartRecID          = 0;
                    String ChosenColor            = String.Empty;
                    String ChosenColorSKUModifier = String.Empty;
                    String ChosenSize             = String.Empty;
                    String ChosenSizeSKUModifier  = String.Empty;
                    String color      = string.Empty;
                    String size       = string.Empty;
                    String TextOption = CommonLogic.FormCanBeDangerousContent("TextOption");


                    for (int i = 0; i <= HttpContext.Current.Request.Form.Count - 1; i++)
                    {
                        if (HttpContext.Current.Request.Form.Keys[i].StartsWith("ProductID", StringComparison.InvariantCultureIgnoreCase))
                        {
                            packProductID = Localization.ParseUSInt(CommonLogic.FormCanBeDangerousContent("__EVENTARGUMENT").Split('_')[1]);
                        }
                        if (HttpContext.Current.Request.Form.Keys[i].StartsWith("VariantID", StringComparison.InvariantCultureIgnoreCase))
                        {
                            packVariantID = Localization.ParseUSInt(CommonLogic.FormCanBeDangerousContent("__EVENTARGUMENT").Split('_')[2]);
                        }

                        if (HttpContext.Current.Request.Form.Keys[i].StartsWith("PackID", StringComparison.InvariantCultureIgnoreCase))
                        {
                            PackID = Localization.ParseUSInt(CommonLogic.FormCanBeDangerousContent(HttpContext.Current.Request.Form.Keys[i]));
                            if (CommonLogic.FormCanBeDangerousContent(HttpContext.Current.Request.Form.Keys[i]).Contains(",") && PackID == 0)
                            {
                                PackID = Localization.ParseUSInt(CommonLogic.FormCanBeDangerousContent(HttpContext.Current.Request.Form.Keys[i]).Split(',')[0]);
                            }
                        }

                        if (HttpContext.Current.Request.Form.Keys[i].StartsWith("Quantity", StringComparison.InvariantCultureIgnoreCase) && !HttpContext.Current.Request.Form.Keys[i].StartsWith("Quantity_vldt", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (Localization.ParseUSInt(HttpContext.Current.Request.Form.Keys[i].Split('_')[2]) == packVariantID)
                            {
                                packQuantity = Localization.ParseUSInt(CommonLogic.FormCanBeDangerousContent(HttpContext.Current.Request.Form.Keys[i]));
                            }
                        }
                        if (HttpContext.Current.Request.Form.Keys[i].StartsWith("CartRecID", StringComparison.InvariantCultureIgnoreCase))
                        {
                            packCartRecID = Localization.ParseUSInt(CommonLogic.FormCanBeDangerousContent(HttpContext.Current.Request.Form.Keys[i]));
                        }
                        if (HttpContext.Current.Request.Form.Keys[i].StartsWith("Color", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (Localization.ParseUSInt(HttpContext.Current.Request.Form.Keys[i].Split('_')[2]) == packVariantID)
                            {
                                color = CommonLogic.FormCanBeDangerousContent(HttpContext.Current.Request.Form.Keys[i]).ToString();
                            }
                        }
                        if (HttpContext.Current.Request.Form.Keys[i].StartsWith("Size", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (Localization.ParseUSInt(HttpContext.Current.Request.Form.Keys[i].Split('_')[2]) == packVariantID)
                            {
                                size = CommonLogic.FormCanBeDangerousContent(HttpContext.Current.Request.Form.Keys[i]).ToString();
                            }
                        }
                        if (HttpContext.Current.Request.Form.Keys[i].StartsWith("ProductTypeID", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (Localization.ParseUSInt(HttpContext.Current.Request.Form.Keys[i].Split('_')[2]) == packVariantID)
                            {
                                packProductTypeID = Localization.ParseUSInt(CommonLogic.FormCanBeDangerousContent(HttpContext.Current.Request.Form.Keys[i]));
                            }
                        }
                    }


                    ThisCustomer.RequireCustomerRecord();
                    if (packQuantity == 0)
                    {
                        packQuantity = 1;
                    }
                    FromCart = (packCartRecID > 0);

                    if (color.Length != 0)
                    {
                        String[] ColorSel = color.Split(',');
                        try
                        {
                            ChosenColor = ColorSel[0];
                        }
                        catch { }
                        try
                        {
                            ChosenColorSKUModifier = ColorSel[1];
                        }
                        catch { }
                    }
                    if (ChosenColor.Length != 0)
                    {
                        ThisCustomer.ThisCustomerSession["ChosenColor"] = ChosenColor;
                    }


                    if (size.Length != 0)
                    {
                        String[] SizeSel = size.Split(',');
                        try
                        {
                            ChosenSize = SizeSel[0];
                        }
                        catch { }
                        try
                        {
                            ChosenSizeSKUModifier = SizeSel[1];
                        }
                        catch { }
                    }
                    if (ChosenSize.Length != 0)
                    {
                        ThisCustomer.ThisCustomerSession["ChosenSize"] = ChosenSize;
                    }

                    if (packQuantity > 0)
                    {
                        // add to custom cart:
                        if (FromCart)
                        {
                            CustomCart.AddItem(PackID, packProductID, packVariantID, packQuantity, ChosenColor, ChosenColorSKUModifier, ChosenSize, ChosenSizeSKUModifier, packCartRecID, ThisCustomer, CartTypeEnum.ShoppingCart);
                        }
                        else
                        {
                            CustomCart cart = new CustomCart(ThisCustomer, PackID, 1, CartTypeEnum.ShoppingCart);
                            cart.AddItem(packProductID, packVariantID, packQuantity, ChosenColor, ChosenColorSKUModifier, ChosenSize, ChosenSizeSKUModifier);
                        }
                    }

                    if (CommonLogic.QueryStringCanBeDangerousContent("UpdateCartPack") == "")
                    {
                        String url = "pb.aspx?type=" + packProductTypeID.ToString() + "&PackID=" + PackID.ToString() + "&ProductID=" + packProductID.ToString() + "&cartrecid=" + packCartRecID;

                        Response.Redirect(url + CommonLogic.IIF(FromCart, "?cartrecid=" + packCartRecID.ToString(), ""));
                        Response.Redirect(url);
                    }
                    else
                    {
                        Response.Redirect(ResolveClientUrl("~/shoppingcart.aspx"));
                    }
                }
            }
            String ActualSEName = string.Empty;

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS(string.Format("select * from Product a with (NOLOCK) inner join (select a.ProductID, b.StoreID from Product a with (nolock) left join ProductStore b " +
                                                               "with (NOLOCK) on a.ProductID = b.ProductID) b on a.ProductID = b.ProductID where Deleted=0 and a.ProductID={0} and ({1}=0 or StoreID={2})", +
                                                               ProductID, CommonLogic.IIF(AppLogic.GlobalConfigBool("AllowProductFiltering") == true, 1, 0), AppLogic.StoreID()), dbconn))
                {
                    if (!rs.Read())
                    {
                        Response.Redirect(SE.MakeDriverLink("ProductNotFound"));
                    }
                    else
                    {
                        bool a = DB.RSFieldBool(rs, "Published");
                        if (!a)
                        {
                            Response.Redirect(SE.MakeDriverLink("ProductNotFound"));
                        }
                    }

                    String SENameINURL = CommonLogic.QueryStringCanBeDangerousContent("SEName");
                    ActualSEName = SE.MungeName(DB.RSField(rs, "SEName"));
                    if (ActualSEName != SENameINURL)
                    {
                        String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);

                        string QStr  = "?";
                        bool   first = true;
                        for (int i = 0; i < Request.QueryString.Count; i++)
                        {
                            string key = Request.QueryString.GetKey(i);
                            if ((key.Equals("productid", StringComparison.InvariantCultureIgnoreCase)) == false && (key.Equals("sename", StringComparison.InvariantCultureIgnoreCase)) == false)
                            {
                                if (!first)
                                {
                                    QStr += "&";
                                }
                                QStr += key + "=" + Request.QueryString[i];
                                first = false;
                            }
                        }
                        if (QStr.Length > 1)
                        {
                            NewURL += QStr;
                        }

                        HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                        Response.Status = "301 Moved Permanently";
                        Response.AddHeader("Location", NewURL);
                        HttpContext.Current.Response.End();
                    }


                    #region Vortx Mobile Xml Package Modification
                    m_XmlPackage = Vortx.MobileFramework.MobileXmlPackageController.XmlPackageHook(DB.RSField(rs, "XmlPackage").ToLowerInvariant(), ThisCustomer);
                    #endregion
                    IsAKit  = DB.RSFieldBool(rs, "IsAKit");
                    IsAPack = DB.RSFieldBool(rs, "IsAPack");
                    if (m_XmlPackage.Length == 0)
                    {
                        if (IsAKit)
                        {
                            m_XmlPackage = AppLogic.ro_DefaultProductKitXmlPackage; // provide a default
                        }
                        else if (IsAPack)
                        {
                            m_XmlPackage = AppLogic.ro_DefaultProductPackXmlPackage; // provide a default
                        }
                        else
                        {
                            m_XmlPackage = AppLogic.ro_DefaultProductXmlPackage; // provide a default
                        }
                    }
                    RequiresReg = DB.RSFieldBool(rs, "RequiresRegistration");
                    ProductName = DB.RSFieldByLocale(rs, "Name", ThisCustomer.LocaleSetting);

                    CategoryHelper     = AppLogic.LookupHelper("Category", 0);
                    SectionHelper      = AppLogic.LookupHelper("Section", 0);
                    ManufacturerHelper = AppLogic.LookupHelper("Manufacturer", 0);
                    DistributorHelper  = AppLogic.LookupHelper("Distributor", 0);
                    GenreHelper        = AppLogic.LookupHelper("Genre", 0);
                    VectorHelper       = AppLogic.LookupHelper("Vector", 0);

                    String SEName = String.Empty;
                    if (DB.RSFieldByLocale(rs, "SETitle", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SETitle = Security.HtmlEncode(AppLogic.AppConfig("StoreName") + " - " + ProductName);
                    }
                    else
                    {
                        SETitle = DB.RSFieldByLocale(rs, "SETitle", ThisCustomer.LocaleSetting);
                    }
                    if (DB.RSFieldByLocale(rs, "SEDescription", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SEDescription = Security.HtmlEncode(ProductName);
                    }
                    else
                    {
                        SEDescription = DB.RSFieldByLocale(rs, "SEDescription", ThisCustomer.LocaleSetting);
                    }
                    if (DB.RSFieldByLocale(rs, "SEKeywords", ThisCustomer.LocaleSetting).Length == 0)
                    {
                        SEKeywords = Security.HtmlEncode(ProductName);
                    }
                    else
                    {
                        SEKeywords = DB.RSFieldByLocale(rs, "SEKeywords", ThisCustomer.LocaleSetting);
                    }
                    SENoScript = DB.RSFieldByLocale(rs, "SENoScript", ThisCustomer.LocaleSetting);
                }
            }

            //Log all views of unknown and registered customer
            if (!AppLogic.ProductIsMLExpress() && (AppLogic.AppConfigBool("DynamicRelatedProducts.Enabled") || AppLogic.AppConfigBool("RecentlyViewedProducts.Enabled")))
            {
                ThisCustomer.LogProductView(ProductID);
            }

            if (IsAKit && !Vortx.MobileFramework.MobileHelper.isMobile())
            {
                Server.Transfer(ResolveClientUrl("~/kitproduct.aspx"), true);
                return;
            }
            else if (IsAKit && Vortx.MobileFramework.MobileHelper.isMobile())
            {
                Server.Transfer(ResolveClientUrl("~/mobilekitproduct.aspx"), true);
                return;
            }

            CategoryName     = CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting);
            SectionName      = SectionHelper.GetEntityName(SectionID, ThisCustomer.LocaleSetting);
            ManufacturerName = ManufacturerHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting);
            DistributorName  = DistributorHelper.GetEntityName(DistributorID, ThisCustomer.LocaleSetting);
            GenreName        = GenreHelper.GetEntityName(GenreID, ThisCustomer.LocaleSetting);
            VectorName       = VectorHelper.GetEntityName(VectorID, ThisCustomer.LocaleSetting);

            String SourceEntityInstanceName = String.Empty;

            if (ManufacturerID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = ManufacturerID.ToString();
                Profile.LastViewedEntityInstanceName = ManufacturerName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (DistributorID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_DistributorEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = DistributorID.ToString();
                Profile.LastViewedEntityInstanceName = DistributorName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (GenreID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_GenreEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = GenreID.ToString();
                Profile.LastViewedEntityInstanceName = GenreName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (VectorID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_VectorEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = VectorID.ToString();
                Profile.LastViewedEntityInstanceName = VectorName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (CategoryID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = CategoryID.ToString();
                Profile.LastViewedEntityInstanceName = CategoryName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (SectionID != 0)
            {
                Profile.LastViewedEntityName         = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                Profile.LastViewedEntityInstanceID   = SectionID.ToString();
                Profile.LastViewedEntityInstanceName = SectionName;

                String NewURL = AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeProductLink(ProductID, ActualSEName);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }

            SourceEntity             = Profile.LastViewedEntityName;
            SourceEntityInstanceName = Profile.LastViewedEntityInstanceName;
            SourceEntityID           = int.Parse(CommonLogic.IIF(CommonLogic.IsInteger(Profile.LastViewedEntityInstanceID), Profile.LastViewedEntityInstanceID, "0"));

            // validate that source entity id is actually valid for this product:
            if (SourceEntityID != 0)
            {
                String sqlx = string.Format("select count(*) as N from productentity a with (nolock) inner join (select distinct a.entityid, a.EntityType from productentity a with (nolock) left join EntityStore b with (nolock) " +
                                            "on a.EntityID = b.EntityID where ({0} = 0 or StoreID = {1})) b on a.EntityID = b.EntityID and a.EntityType=b.EntityType where ProductID = {2} and a.EntityID = {3} and a.EntityType = {4}"
                                            , CommonLogic.IIF(AppLogic.GlobalConfigBool("AllowEntityFiltering") == true, 1, 0), AppLogic.StoreID(), ProductID, SourceEntityID, DB.SQuote(SourceEntity));
                if (DB.GetSqlN(sqlx) == 0)
                {
                    SourceEntityID = 0;
                }
            }

            // we had no entity context coming in, try to find a category context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    CategoryID   = SourceEntityID;
                    CategoryName = CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = CategoryID.ToString();
                    Profile.LastViewedEntityInstanceName = CategoryName;

                    SourceEntity             = EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = CategoryName;
                }
            }

            // we had no entity context coming in, try to find a section context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    SectionID   = SourceEntityID;
                    SectionName = CategoryHelper.GetEntityName(SectionID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = SectionID.ToString();
                    Profile.LastViewedEntityInstanceName = SectionName;

                    SourceEntity             = EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = SectionName;
                }
            }

            // we had no entity context coming in, try to find a Manufacturer context for this product, so they have some context if possible:
            if (SourceEntityID == 0)
            {
                SourceEntityID = EntityHelper.GetProductsFirstEntity(ProductID, EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName);
                if (SourceEntityID > 0)
                {
                    ManufacturerID   = SourceEntityID;
                    ManufacturerName = CategoryHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting);

                    Profile.LastViewedEntityName         = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                    Profile.LastViewedEntityInstanceID   = ManufacturerID.ToString();
                    Profile.LastViewedEntityInstanceName = ManufacturerName;

                    SourceEntity             = EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName;
                    SourceEntityInstanceName = ManufacturerName;
                }
            }

            // build up breadcrumb if we need:
            SectionTitle = Breadcrumb.GetProductBreadcrumb(ProductID, ProductName, SourceEntity, SourceEntityID, ThisCustomer);
            //Reset LastViewedEntityInstanceID to zero if no entities are mapped to the product so the left nav will render properly.
            if (SourceEntityID <= 0)
            {
                HttpContext.Current.Profile.SetPropertyValue("LastViewedEntityInstanceID", "0");
            }

            if (RequiresReg && !ThisCustomer.IsRegistered)
            {
                m_PageOutput += "<br/><br/><br/><br/><b>" + AppLogic.GetString("showproduct.aspx.1", SkinID, ThisCustomer.LocaleSetting) + "</b><br/><br/><br/><a href=\"signin.aspx?returnurl=" + CommonLogic.GetThisPageName(false) + "?ProductID=" + ProductID.ToString() + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING").Trim().Length > 0, "&" + Security.HtmlEncode(Security.UrlEncode(CommonLogic.ServerVariables("QUERY_STRING"))), String.Empty) + "\">" + AppLogic.GetString("showproduct.aspx.2", SkinID, ThisCustomer.LocaleSetting) + "</a> " + AppLogic.GetString("showproduct.aspx.3", SkinID, ThisCustomer.LocaleSetting);
            }
            else
            {
                AppLogic.eventHandler("ViewProductPage").CallEvent("&ViewProductPage=true");

                // check if the postback was caused by an addtocart button
                if (this.IsPostBack && this.IsAddToCartPostBack)
                {
                    HandleAddToCart();
                    return;
                }

                DB.ExecuteSQL("update product set Looks=Looks+1 where ProductID=" + ProductID.ToString());

                m_PageOutput = "<!-- XmlPackage: " + m_XmlPackage + " -->\n";
                if (m_XmlPackage.Length == 0)
                {
                    m_PageOutput += "<p><b><font color=red>XmlPackage format was chosen, but no XmlPackage was specified!</font></b></p>";
                }
                else
                {
                    using (XmlPackage2 p = new XmlPackage2(m_XmlPackage, ThisCustomer, SkinID, "", "EntityName=" + SourceEntity + "&EntityID=" + SourceEntityID.ToString() + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING").IndexOf("cartrecid") != -1, "&cartrecid=" + CommonLogic.QueryStringUSInt("cartrecid").ToString(), "&showproduct=1"), String.Empty, true))
                    {
                        m_PageOutput += AppLogic.RunXmlPackage(p, base.GetParser, ThisCustomer, SkinID, true, true);
                        if (p.SectionTitle != "")
                        {
                            SectionTitle = p.SectionTitle;
                        }
                        if (p.SETitle != "")
                        {
                            SETitle = p.SETitle;
                        }
                        if (p.SEDescription != "")
                        {
                            SEDescription = p.SEDescription;
                        }
                        if (p.SEKeywords != "")
                        {
                            SEKeywords = p.SEKeywords;
                        }
                        if (p.SENoScript != "")
                        {
                            SENoScript = p.SENoScript;
                        }
                    }
                }
            }
            litOutput.Text = m_PageOutput;
        }
コード例 #6
0
        public ActionResult Detail(int id, string searchEngineName, int?cartRecordId = null)
        {
            var product = new Product(id);

            // Make sure we should show the product
            if (product.ProductID == 0 ||
                !product.Published ||
                !product.IsMappedToStore())
            {
                throw new HttpException(404, null);
            }

            var outOfStockLevel = AppLogic.AppConfigNativeInt("HideProductsWithLessThanThisInventoryLevel");

            if (AppLogic.AppConfigBool("ProductPageOutOfStockRedirect") &&
                outOfStockLevel != -1)
            {
                if (AppLogic.DeterminePurchasableQuantity(product.ProductID,
                                                          AppLogic.GetProductsDefaultVariantID(product.ProductID),
                                                          AppLogic.ProductTracksInventoryBySizeAndColor(product.ProductID),
                                                          "Product") < outOfStockLevel)
                {
                    throw new HttpException(404, null);
                }
            }

            // If the search engine name in the URL is incorrect, 301 Redirect to the correct search engine name URL
            if (!string.IsNullOrEmpty(product.SEName) &&
                !StringComparer.OrdinalIgnoreCase.Equals(searchEngineName, product.SEName))
            {
                // The search engine name in the URL is incorrect
                // We should redirect to the correct search engine name, which should be stored in the database 'SEName' field

                // First, let's make sure the SEName field in the database has not been tampered with
                // If the Product.SEName field has been manually modified, we can't redirect properly
                var expectedSENameForURL = SearchEngineNameProvider.GenerateSeName(product.SEName);

                if (expectedSENameForURL == product.SEName)
                {
                    // SEName in the database is in the expected format - let's redirect to the expected SEName URL
                    return(RedirectPermanent(Url.BuildProductLink(id, product.SEName)));
                }
                else
                {
                    // SEName contains invalid characters, or otherwise is not in the correct format in the database
                    // This should only happen if the user is manually modifying their database, or modifying products improperly using Wsi
                    // Let's blow up to prevent infinite redirect.  An Admin will need to fix their manually modified SEName field(s)
                    throw new HttpException(500, $"Invalid SEName in the database for ProductID {product.ProductID}");
                }
            }

            // Set the xmlpackage
            var xmlpackageName = !string.IsNullOrEmpty(product.XmlPackage)
                                ? product.XmlPackage
                                : AppLogic.ro_DefaultProductXmlPackage;

            // Kits always get the default kit xmlpackage
            if (product.IsAKit)
            {
                xmlpackageName = "page.kitheader.xml.config";
            }

            var customer = HttpContext.GetCustomer();

            // Get the context of where we've come from
            var sourceEntityInfo = GetSourceEntityInfo(product.ProductID, customer.LocaleSetting);

            // Save source entity info to the profile
            Profile["LastViewedEntityName"]         = sourceEntityInfo.Type;
            Profile["LastViewedEntityInstanceID"]   = sourceEntityInfo.Id.ToString();
            Profile["LastViewedEntityInstanceName"] = sourceEntityInfo.Name;

            if (!product.RequiresRegistration || customer.IsRegistered)
            {
                //Log views to generate dynamic related product results
                if (AppLogic.AppConfigBool("DynamicRelatedProducts.Enabled") && !AppLogic.UserAgentIsKnownBot())
                {
                    customer.LogProductView(product.ProductID);
                }

                //Fire an event
                AppLogic.eventHandler("ViewProductPage").CallEvent("&ViewProductPage=true");

                //Update Product looks(views count)
                DB.ExecuteSQL("update product set Looks=Looks+1 where ProductID = @ProductId", new SqlParameter[] { new SqlParameter("ProductId", product.ProductID) });
            }

            // Additional runtime parameters
            var runtimeParameters = string.Format("EntityName={0}&EntityID={1}", sourceEntityInfo.Type, sourceEntityInfo.Id);

            if (Request.Url.Query.Contains("cartrecid"))
            {
                runtimeParameters += string.Format("&cartrecid={0}", CommonLogic.QueryStringUSInt("cartrecid"));
            }

            // Add a showproduct runtime node
            runtimeParameters += "&showproduct=1";

            // Breadcrumb and meta tags
            var pageTitle   = Breadcrumb.GetProductBreadcrumb(product.ProductID, product.LocaleName, sourceEntityInfo.Type, sourceEntityInfo.Id, customer);
            var pageContent = string.Empty;

            var metaTitle = XmlCommon.GetLocaleEntry(product.SETitle, customer.LocaleSetting, true);

            if (string.IsNullOrEmpty(metaTitle))
            {
                metaTitle = string.Format("{0} - {1}", AppLogic.AppConfig("StoreName"), product.LocaleName);
            }

            var metaDescription = XmlCommon.GetLocaleEntry(product.SEDescription, customer.LocaleSetting, true);

            if (string.IsNullOrEmpty(metaDescription))
            {
                metaDescription = product.LocaleName;
            }

            var metaKeywords = XmlCommon.GetLocaleEntry(product.SEKeywords, customer.LocaleSetting, true);

            if (string.IsNullOrEmpty(metaKeywords))
            {
                metaKeywords = product.LocaleName;
            }

            var parser = new Parser();

            var xmlpackage = new XmlPackage(
                packageName: xmlpackageName,
                customer: customer,
                additionalRuntimeParms: runtimeParameters,
                htmlHelper: ControllerContext.GetHtmlHelper());

            pageContent = AppLogic.RunXmlPackage(xmlpackage, parser, customer, customer.SkinID, true, true);
            if (!string.IsNullOrEmpty(xmlpackage.SectionTitle))
            {
                pageTitle = xmlpackage.SectionTitle;
            }

            if (!string.IsNullOrEmpty(xmlpackage.SETitle))
            {
                metaTitle = xmlpackage.SETitle;
            }

            if (!string.IsNullOrEmpty(xmlpackage.SEDescription))
            {
                metaDescription = xmlpackage.SEDescription;
            }

            if (xmlpackage.SEKeywords != string.Empty)
            {
                metaKeywords = xmlpackage.SEKeywords;
            }

            // Build the view model
            var productViewModel = new ProductViewModel
            {
                Id              = product.ProductID,
                Name            = XmlCommon.GetLocaleEntry(product.LocaleName, customer.LocaleSetting, true),
                MetaTitle       = metaTitle,
                MetaDescription = metaDescription,
                MetaKeywords    = metaKeywords,
                PageTitle       = pageTitle,
                PageContent     = pageContent,
                LoginRequired   = product.RequiresRegistration && !customer.IsRegistered,
                IsAKit          = product.IsAKit,
                XmlPackageName  = xmlpackageName,
                CartRecordId    = cartRecordId
            };

            // Override the layout
            var layoutName = string.Empty;

            if (AppLogic.AppConfigBool("TemplateSwitching.Enabled"))
            {
                layoutName = AppLogic.GetCurrentEntityTemplateName(sourceEntityInfo.Type, sourceEntityInfo.Id);
            }

            // Kits use a separate view
            var viewName = product.IsAKit
                                ? ViewNames.KitDetail
                                : ViewNames.Detail;

            return(!string.IsNullOrEmpty(layoutName)
                                ? View(viewName, layoutName, productViewModel)
                                : View(viewName, productViewModel));
        }