示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _paging = new SqlPaging();
            _paging.From("[Catalog].[Product]");
            _paging.Inner_Join("[Catalog].[ProductExt]  ON [Product].[ProductID] = [ProductExt].[ProductID]");
            _paging.Left_Join("[Catalog].[Photo]  ON [Photo].[PhotoId] = [ProductExt].[PhotoId]");
            _paging.Left_Join("[Catalog].[Offer] ON [ProductExt].[OfferID] = [Offer].[OfferID]");

            _paging.Left_Join("[Catalog].[ShoppingCart] ON [ShoppingCart].[OfferID] = [Offer].[OfferID] AND [ShoppingCart].[ShoppingCartType] = 3 AND [ShoppingCart].[CustomerID] = {0}", CustomerContext.CustomerId);
            _paging.Left_Join("[Catalog].[Ratio] on Product.ProductId= Ratio.ProductID and Ratio.CustomerId=[ShoppingCart].[CustomerID]");


            _paging.Select(
                "[Product].[ProductID]",
                "CountPhoto",
                "Photo.PhotoId",
                "PhotoName AS Photo",
                "Photo.Description as PhotoDesc",
                "BriefDescription",
                "Product.ArtNo",
                "Name",
                "Recomended",
                "Bestseller",
                "New",
                "OnSale",
                "[Product].Discount",
                "Offer.OfferID",
                "MaxAvailable AS Amount",
                "MinAmount",
                "MaxAmount",
                "Enabled",
                "AllowPreOrder",
                "Ratio",
                "RatioID",
                "ShoppingCartItemId",
                "UrlPath",
                "Offer.ColorID",
                "null as AdditionalPhoto"
                );

            if (SettingsCatalog.ComplexFilter)
            {
                _paging.Select(
                    "Colors",
                    "NotSamePrices as MultiPrices",
                    "MinPrice as Price"
                    );
            }
            else
            {
                _paging.Select(
                    "null as Colors",
                    "0 as MultiPrices",
                    "Price"
                    );
            }

            if (string.IsNullOrEmpty(Request["type"]) || !Enum.TryParse(Request["type"], true, out _typeFlag) ||
                _typeFlag == ProductOnMain.TypeFlag.None)
            {
                Error404();
            }

            switch (_typeFlag)
            {
            case ProductOnMain.TypeFlag.Bestseller:
                PageName = Resource.Client_ProductList_AllBestSellers;
                SetMeta(new MetaInfo(SettingsMain.ShopName + " - " + Resource.Client_Bestsellers_Header), string.Empty);
                break;

            case ProductOnMain.TypeFlag.New:
                PageName = Resource.Client_ProductList_AllNew;
                SetMeta(new MetaInfo(SettingsMain.ShopName + " - " + Resource.Client_New_Header), string.Empty);
                break;

            case ProductOnMain.TypeFlag.Discount:
                PageName = Resource.Client_ProductList_AllDiscount;
                SetMeta(new MetaInfo(SettingsMain.ShopName + " - " + Resource.Client_Discount_Header), string.Empty);
                break;

            case ProductOnMain.TypeFlag.OnSale:
                PageName = Resource.Client_ProductList_OnSale;
                SetMeta(new MetaInfo(SettingsMain.ShopName + " - " + Resource.Client_OnSale_Header), string.Empty);
                break;

            case ProductOnMain.TypeFlag.Recomended:
                PageName = Resource.Client_ProductList_Recomended;
                SetMeta(new MetaInfo(SettingsMain.ShopName + " - " + Resource.Client_Recomended_Header), string.Empty);
                break;
            }

            ProductsCount       = ProductOnMain.GetProductCountByType(_typeFlag);
            pnlSort.Visible     = ProductsCount > 0;
            productView.Visible = ProductsCount > 0;

            breadCrumbs.Items.AddRange(new BreadCrumbs[]
            {
                new BreadCrumbs()
                {
                    Name = Resource.Client_MasterPage_MainPage,
                    Url  = UrlService.GetAbsoluteLink("/")
                },
                new BreadCrumbs()
                {
                    Name = PageName, Url = null
                }
            });

            BuildSorting();
            BuildFilter();
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request["categoryid"]) || !Int32.TryParse(Request["categoryid"], out _categoryId))
            {
                Error404();
            }

            Category = CategoryService.GetCategory(_categoryId);
            if (Category == null || Category.Enabled == false || Category.ParentsEnabled == false)
            {
                Error404();
                return;
            }

            //Indepth = Request["indepth"] == "1" || Category.DisplayChildProducts;
            Indepth = true;

            _paging = new SqlPaging();
            _paging.From("[Catalog].[Product]");
            _paging.Left_Join("[Catalog].[ProductExt]  ON [Product].[ProductID] = [ProductExt].[ProductID]");
            _paging.Left_Join("[Catalog].[Photo]  ON [Photo].[PhotoId] = [ProductExt].[PhotoId]");
            _paging.Left_Join("[Catalog].[Offer] ON [ProductExt].[OfferID] = [Offer].[OfferID]");

            _paging.Left_Join("[Catalog].[ShoppingCart] ON [ShoppingCart].[OfferID] = [Offer].[OfferID] AND [ShoppingCart].[ShoppingCartType] = 3 AND [ShoppingCart].[CustomerID] = {0}", CustomerContext.CustomerId);
            _paging.Left_Join("[Catalog].[Ratio] on Product.ProductId= Ratio.ProductID and Ratio.CustomerId=[ShoppingCart].[CustomerID]");
            // Для сотрировки по популярности
            _paging.Left_Join(@"(Select [Order].[OrderItems].[ProductId], COUNT([Order].[OrderItems].[ProductId])as Popularity  From [Order].[OrderItems],[Catalog].[Product]
where [Order].[OrderItems].[ProductId]=[Catalog].[Product].[ProductId]
Group by  [Order].[OrderItems].[ProductId])as PopTable
ON PopTable.ProductId=[Catalog].[Product].[ProductId]");


            if (!Indepth)
            {
                _paging.Inner_Join("[Catalog].[ProductCategories] on [ProductCategories].[CategoryID] = {0} and  ProductCategories.ProductId = [Product].[ProductID]", _categoryId);
            }

            _paging.Select(
                "[Product].[ProductID]",
                "CountPhoto",
                "Photo.PhotoId",
                "PhotoName AS Photo",
                "Photo.Description as PhotoDesc",
                "BriefDescription",
                "Product.ArtNo",
                "Name",
                "Recomended",
                "Bestseller",
                "New",
                "OnSale",
                "[Product].Discount",
                "Offer.OfferID",
                "MaxAvailable AS Amount",
                "MinAmount",
                "MaxAmount",
                "Enabled",
                "AllowPreOrder",
                "Ratio",
                "RatioID",
                "ShoppingCartItemId",
                "UrlPath",
                "Offer.ColorID",
                "PopularityManually",
                "DateAdded",
                "ISNULL (Popularity , 0)as Popularity"
                );

            if (SettingsCatalog.ComplexFilter)
            {
                _paging.Select(
                    "Colors",
                    "NotSamePrices as MultiPrices",
                    "MinPrice as Price"
                    );
            }
            else
            {
                _paging.Select(
                    "null as Colors",
                    "0 as MultiPrices",
                    "Price"
                    );
            }

            ProductsCount = Indepth ? Category.ProductsCount : CategoryService.GetEnabledProductsCountInCategory(Category.ID, Indepth);

            categoryView.CategoryID = _categoryId;
            //categoryView.Visible = Category.DisplayStyle == "True" || ProductsCount == 0;
            categoryView.Visible = false;

            pnlSort.Visible        = ProductsCount > 0;
            productView.Visible    = ProductsCount > 0;
            catalogView.CategoryID = _categoryId;

            filterProperty.CategoryId = _categoryId;

            filterBrand.CategoryId = _categoryId;
            filterBrand.InDepth    = Indepth;
            filterBrand.Visible    = SettingsCatalog.ShowProducerFilter;

            filterSize.CategoryId = _categoryId;
            filterSize.InDepth    = Indepth;
            filterSize.Visible    = SettingsCatalog.ShowSizeFilter;

            filterColor.CategoryId = _categoryId;
            filterColor.InDepth    = Indepth;
            filterColor.Visible    = SettingsCatalog.ShowColorFilter;

            filterPrice.CategoryId = _categoryId;
            filterPrice.InDepth    = Indepth;
            filterPrice.Visible    = SettingsCatalog.ShowPriceFilter;


            lblCategoryName.Text = _categoryId != 0 ? Category.Meta.H1 : Resource.Client_MasterPage_Catalog;

            breadCrumbs.Items =
                CategoryService.GetParentCategories(_categoryId).Select(parent => new BreadCrumbs
            {
                Name = parent.Name,
                Url  = UrlService.GetLink(ParamType.Category, parent.UrlPath, parent.CategoryId)
            }).Reverse().ToList();

            if (_categoryId == 0)
            {
                breadCrumbs.Items.Add(new BreadCrumbs
                {
                    Name = Resource.Client_MasterPage_Catalog,
                    Url  = UrlService.GetAbsoluteLink("catalog")
                });
            }

            breadCrumbs.Items.Insert(0, new BreadCrumbs
            {
                Name = Resource.Client_MasterPage_MainPage,
                Url  = UrlService.GetAbsoluteLink("/")
            });

            //Добавим новые meta
            MetaInfo newMetaInfo = new MetaInfo();

            newMetaInfo = Category.Meta;

            StringBuilder newTitle     = new StringBuilder("", 200);
            string        polTitle     = "";
            string        vozrastTitle = "";
            string        brandTitle   = "";

            //если в фильтре указан бренд
            if (!string.IsNullOrEmpty(Request["brand"]))
            {
                brandTitle = BrandService.GetBrandById(int.Parse(Request["brand"])).Name;
            }

            // если в фильтре выбраны пол (prop = 5083 для девочек, prop = 5084 для мальчиков) или
            //возраст( prop = 5087   0 - 12 мес, prop = 5086   1 - 3 года, prop = 5075   4 - 5 лет, prop = 5081  6 - 8 лет, prop = 5082  9 - 11 лет, prop = 5085  более 12 лет
            if (!string.IsNullOrEmpty(Request["prop"]))
            {
                var filterCol = Request["prop"].Split('-');
                foreach (var val in filterCol)
                {
                    switch (val)
                    {
                    case "5083":
                        polTitle = PropertyService.GetPropertyValueById(int.Parse(val)).Value;
                        break;

                    case "5084":
                        polTitle = PropertyService.GetPropertyValueById(int.Parse(val)).Value;
                        break;

                    case "5087":
                        vozrastTitle = PropertyService.GetPropertyValueById(int.Parse(val)).Value;
                        break;

                    case "5086":
                        vozrastTitle = PropertyService.GetPropertyValueById(int.Parse(val)).Value;
                        break;

                    case "5075":
                        vozrastTitle = PropertyService.GetPropertyValueById(int.Parse(val)).Value;
                        break;

                    case "5081":
                        vozrastTitle = PropertyService.GetPropertyValueById(int.Parse(val)).Value;
                        break;

                    case "5082":
                        vozrastTitle = PropertyService.GetPropertyValueById(int.Parse(val)).Value;
                        break;

                    case "5085":
                        vozrastTitle = PropertyService.GetPropertyValueById(int.Parse(val)).Value;
                        break;
                    }
                }
            }

            //если  пол или возраст указаны в фильтре
            if (polTitle != "" || vozrastTitle != "")
            {
                newTitle.Append("Игрушки ");
                if (polTitle != "")
                {
                    newTitle.Append(polTitle);
                }
                if (vozrastTitle != "")
                {
                    newTitle.Append((newTitle.ToString() == "") ? vozrastTitle : ", " + vozrastTitle);
                }
                if (brandTitle != "")
                {
                    newTitle.Append(" от " + brandTitle);
                }
            }
            //если пол и возраст не указаны в фильтре
            else
            {
                newTitle.Append(Category.Name);
                if (brandTitle != "")
                {
                    newTitle.Append(" " + brandTitle);
                }
            }
            newMetaInfo.Title           = newTitle + " купить в интернет-магазине Корпорация Игрушек";
            newMetaInfo.MetaDescription = "Интернет-магазин Корпорация Игрушек представляет: " + newTitle.ToString() + " и еще более 5,5 тысяч видов товаров по оптовым ценам. Порадуйте своего ребенка!";
            newMetaInfo.MetaKeywords    = (polTitle != "" || vozrastTitle != "") ? "Игрушки " + newTitle.ToString() : newTitle.ToString();

            var metaInfo = SetMeta(newMetaInfo, Category.Name, page: paging.CurrentPage);

            //var metaInfo = SetMeta(Category.Meta, Category.Name, page: paging.CurrentPage);
            lblCategoryName.Text = metaInfo.H1;

            BuildSorting();
            BuildFilter();
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _paging = new SqlPaging();
            _paging.From("[Catalog].[Product]");
            _paging.Inner_Join("[Catalog].[ProductExt]  ON [Product].[ProductID] = [ProductExt].[ProductID]");
            _paging.Left_Join("[Catalog].[Photo]  ON [Photo].[PhotoId] = [ProductExt].[PhotoId]");
            _paging.Left_Join("[Catalog].[Offer] ON [ProductExt].[OfferID] = [Offer].[OfferID]");

            _paging.Left_Join("[Catalog].[ShoppingCart] ON [ShoppingCart].[OfferID] = [Offer].[OfferID] AND [ShoppingCart].[ShoppingCartType] = 3 AND [ShoppingCart].[CustomerID] = {0}", CustomerContext.CustomerId);
            _paging.Left_Join("[Catalog].[Ratio] on Product.ProductId= Ratio.ProductID and Ratio.CustomerId=[ShoppingCart].[CustomerID]");

            // Для сотрировки по популярности
            _paging.Left_Join(@"(Select [Order].[OrderItems].[ProductId], COUNT([Order].[OrderItems].[ProductId])as Popularity  From [Order].[OrderItems],[Catalog].[Product]
            where [Order].[OrderItems].[ProductId]=[Catalog].[Product].[ProductId]
            Group by  [Order].[OrderItems].[ProductId])as PopTable
            ON PopTable.ProductId=[Catalog].[Product].[ProductId]");

            _paging.Select(
                "[Product].[ProductID]",
                "CountPhoto",
                "Photo.PhotoId",
                "PhotoName AS Photo",
                "Photo.Description as PhotoDesc",
                "BriefDescription",
                "Product.ArtNo",
                "Name",
                "Recomended",
                "Bestseller",
                "New",
                "OnSale",
                "[Product].Discount",
                "Offer.OfferID",
                "MaxAvailable AS Amount",
                "MinAmount",
                "MaxAmount",
                "Enabled",
                "AllowPreOrder",
                "Ratio",
                "RatioID",
                "ShoppingCartItemId",
                "UrlPath",
                "Offer.ColorID",
                "null as AdditionalPhoto"
                );

            if (SettingsCatalog.ComplexFilter)
            {
                _paging.Select(
                    "Colors",
                    "NotSamePrices as MultiPrices",
                    "MinPrice as Price"
                    );
            }
            else
            {
                _paging.Select(
                    "null as Colors",
                    "0 as MultiPrices",
                    "Price"
                    );
            }

            BuildSorting();
            BuildFilter();

            var nmeta = new MetaInfo(string.Format("{0} - {1}", SettingsMain.ShopName, Resource.Client_Search_AdvancedSearch));

            SetMeta(nmeta, string.Empty, page: paging.CurrentPage);
            txtName.Focus();
        }
示例#4
0
        private void BuildFilter()
        {
            _paging.Where("Enabled={0}", true);
            _paging.Where("AND CategoryEnabled={0}", true);

            if (Indepth)
            {
                _paging.Where("AND Exists( select 1 from [Catalog].[ProductCategories] INNER JOIN [Settings].[GetChildCategoryByParent]({0}) AS hCat ON hCat.id = [ProductCategories].[CategoryID] and  ProductCategories.ProductId = [Product].[ProductID])", _categoryId);
            }

            if (!string.IsNullOrEmpty(Request["brand"]))
            {
                var brandIds = Request["brand"].Split(',').Select(item => item.TryParseInt()).Where(id => id != 0).ToList();
                filterBrand.SelectedBrandIDs = brandIds;
                _paging.Where("AND BrandID IN ({0})", brandIds.ToArray());
            }
            else
            {
                filterBrand.SelectedBrandIDs = new List <int>();
            }

            _paging.Where("AND Offer.Main={0} AND Offer.Main IS NOT NULL", true);


            if (!string.IsNullOrEmpty(Request["size"]))
            {
                var sizeIds = Request["size"].Split(',').Select(item => item.TryParseInt()).Where(id => id != 0).ToList();
                filterSize.SelectedSizesIDs = sizeIds;
                _paging.Where("and Exists( select 1 from [Catalog].[Offer] where Offer.[SizeID] IN ({0}) and Offer.ProductId = [Product].[ProductID])", sizeIds.ToArray());
            }
            else
            {
                filterSize.SelectedSizesIDs = new List <int>();
            }

            if (!string.IsNullOrEmpty(Request["color"]))
            {
                var colorIds = Request["color"].Split(',').Select(item => item.TryParseInt()).Where(id => id != 0).ToList();
                filterColor.SelectedColorsIDs = colorIds;
                _paging.Where("and Exists( select 1 from [Catalog].[Offer] where Offer.[ColorID] IN ({0}) and Offer.ProductId = [Product].[ProductID]  and Offer.[Amount] > 0)", colorIds.ToArray());

                if (SettingsCatalog.ComplexFilter)
                {
                    _paging.Select(
                        string.Format(
                            "(select Top 1 PhotoName from catalog.Photo inner join catalog.offer on Photo.objid=offer.productid and Type='product'" +
                            " where offer.productid=product.productid and Photo.ColorID in({0}) order by Photo.PhotoSortOrder, Photo.Main)" +
                            " as AdditionalPhoto",
                            colorIds.AggregateString(',')));
                }
                else
                {
                    _paging.Select("null as AdditionalPhoto");
                }
            }
            else
            {
                filterColor.SelectedColorsIDs = new List <int>();
                _paging.Select("null as AdditionalPhoto");
            }

            if (!string.IsNullOrEmpty(Request["pricefrom"]) || !string.IsNullOrEmpty(Request["priceto"]))
            {
                var pricefrom = Request["pricefrom"].TryParseInt(0);
                var priceto   = Request["priceto"].TryParseInt(int.MaxValue);

                filterPrice.CurValMin = pricefrom;
                filterPrice.CurValMax = priceto;
                _paging.Where("and Exists( select 1 from [Catalog].[Offer] where Offer.Price - Offer.Price * Discount / 100 >= {0} ", pricefrom * CurrencyService.CurrentCurrency.Value);
                _paging.Where("AND Offer.Price - Offer.Price * Discount / 100 <={0} and Offer.ProductId = [Product].[ProductID])", priceto * CurrencyService.CurrentCurrency.Value);
            }
            else
            {
                filterPrice.CurValMin = 0;
                filterPrice.CurValMax = int.MaxValue;
            }

            if (!string.IsNullOrEmpty(Request["prop"]))
            {
                var selectedPropertyIDs = new List <int>();
                var filterCollection    = Request["prop"].Split('-');

                CheckSelectCategory();

                foreach (var val in filterCollection)
                {
                    var tempListIds = new List <int>();
                    foreach (int id in val.Split(',').Select(item => item.TryParseInt()).Where(id => id != 0))
                    {
                        tempListIds.Add(id);
                        selectedPropertyIDs.Add(id);
                    }
                    if (tempListIds.Count > 0)
                    {
                        _paging.Where("AND Exists( select 1 from [Catalog].[ProductPropertyValue] where [Product].[ProductID] = [ProductID] and PropertyValueID IN ({0}))", tempListIds.ToArray());
                    }
                }
                filterProperty.SelectedPropertyIDs = selectedPropertyIDs;
            }
            else
            {
                filterProperty.SelectedPropertyIDs = new List <int>();
            }


            var rangeIds     = new Dictionary <int, KeyValuePair <float, float> >();
            var rangeQueries =
                Request.QueryString.AllKeys.Where(
                    p => p != null && p.StartsWith("prop_") && (p.EndsWith("_min") || p.EndsWith("_max"))).ToList();

            foreach (var rangeQuery in rangeQueries)
            {
                if (rangeQuery.EndsWith("_max"))
                {
                    continue;
                }

                var propertyId = rangeQuery.Split('_')[1].TryParseInt();
                if (propertyId == 0)
                {
                    continue;
                }

                var min = Request.QueryString[rangeQuery].TryParseFloat();
                var max = Request.QueryString[rangeQuery.Replace("min", "max")].TryParseFloat();

                rangeIds.Add(propertyId, new KeyValuePair <float, float>(min, max));
            }

            if (rangeIds.Count > 0)
            {
                foreach (var i in rangeIds.Keys)
                {
                    _paging.Where("AND Exists( select 1 from [Catalog].[ProductPropertyValue] ");
                    _paging.Where("inner Join [Catalog].[PropertyValue] on [PropertyValue].[PropertyValueID] = [ProductPropertyValue].[PropertyValueID]");
                    _paging.Where("where [Product].[ProductID] = [ProductID] and PropertyId = {0}", i);
                    _paging.Where("And RangeValue >= {0}", rangeIds[i].Key);
                    _paging.Where("And RangeValue <= {0})", rangeIds[i].Value);
                }
            }
            filterProperty.SelectedRangePropertyIDs = rangeIds;

            switch (Request["available"])
            {
            case "1":
                filterExtra.AvailableSelected = true;
                break;

            case "0":
                filterExtra.AvailableSelected = false;
                break;

            default:
                filterExtra.AvailableSelected = SettingsCatalog.AvaliableFilterSelected;
                break;
            }

            if (filterExtra.AvailableSelected)
            {
                _paging.Where("AND MaxAvailable>{0}", 0);
            }


            switch (Request["preorder"])
            {
            case "1":
                filterExtra.PreOrderSelected = true;
                break;

            case "0":
                filterExtra.PreOrderSelected = false;
                break;

            default:
                filterExtra.PreOrderSelected = SettingsCatalog.PreorderFilterSelected;
                break;
            }

            if (filterExtra.PreOrderSelected)
            {
                _paging.Where("AND AllowPreOrder={0}", true);
                _paging.Where("AND MaxAvailable={0}", false);
            }
        }