protected void btnSave_Click(object sender, EventArgs e)
        {
            var item = HccApp.CatalogServices.ProductVariants.Find(EditedVariantId);

            if (item != null)
            {
                cvVariantSku.IsValid = true;
                var prodGuid = DataTypeHelper.BvinToNullableGuid(ProductId);
                if (HccApp.CatalogServices.Products.IsSkuExist(txtVariantSku.Text.Trim(), prodGuid))
                {
                    cvVariantSku.IsValid = false;
                    ShowDialog();
                    return;
                }

                item.Sku = txtVariantSku.Text.Trim();
                var p = item.Price;
                if (decimal.TryParse(txtVariantPrice.Text.Trim(), NumberStyles.Currency, CultureInfo.CurrentCulture,
                                     out p))
                {
                    item.Price = Money.RoundCurrency(p);
                }

                if (ucVariantImage.HasFile)
                {
                    DiskStorage.CopyProductVariantImage(HccApp.CurrentStore.Id, ProductId, item.Bvin,
                                                        ucVariantImage.TempImagePath, ucVariantImage.FileName);
                }

                HccApp.CatalogServices.ProductVariants.Update(item);
            }

            CloseDialog();
            LoadVariants();
        }
        protected IQueryable <JoinedItem <hcc_Category, hcc_CategoryTranslation> > GetSecureQueryForCurrentStore(
            IRepoStrategy <hcc_Category> strategy, string parentId)
        {
            var parentGuid = DataTypeHelper.BvinToNullableGuid(parentId);

            return
                (GetSecureQueryForCurrentStore(strategy)
                 .Where(i => i.Item.ParentID == parentGuid || (!i.Item.ParentID.HasValue && !parentGuid.HasValue)));
        }
        /// <summary>
        ///     Get list of children category for given parent category.
        /// </summary>
        /// <param name="parentId">Categoy unique identifier</param>
        /// <param name="pageNumber">Page number</param>
        /// <param name="pageSize">Page Size</param>
        /// <param name="totalRowCount">Total records reference parameter</param>
        /// <returns>Returns list of <see cref="CategorySnapshot" /> instances</returns>
        public List <CategorySnapshot> FindChildren(string parentId, int pageNumber, int pageSize, ref int totalRowCount)
        {
            var parentGuid = DataTypeHelper.BvinToNullableGuid(parentId);

            using (var s = CreateStrategy())
            {
                var query = GetSecureQueryForCurrentStore(s, parentId).OrderBy(y => y.Item.SortOrder);
                var items = GetPagedItems(query, pageNumber, pageSize);
                return(ListPocoSnapshot(items));
            }
        }
Пример #4
0
        public int FindCountByProductType(string productTypeId)
        {
            var productTypeGuid = DataTypeHelper.BvinToNullableGuid(productTypeId);

            using (var s = CreateStrategy())
            {
                var result = GetSecureQueryForCurrentStore(s)
                             .Where(y => y.Item.ProductTypeId == productTypeGuid)
                             .Count();
                return(result);
            }
        }
        public List <ProductTypePropertyAssociation> FindByProductType(string productTypeBvin)
        {
            var storeId         = Context.CurrentStore.Id;
            var productTypeGuid = DataTypeHelper.BvinToNullableGuid(productTypeBvin);

            return(FindListPoco(q =>
            {
                return q.Where(y => y.StoreId == storeId)
                .Where(y => y.ProductTypeBvin == productTypeGuid)
                .OrderBy(y => y.SortOrder);
            }));
        }
        public List <ProductReview> FindByProductIdPaged(string productId, int pageNumber, int pageSize)
        {
            var guid    = DataTypeHelper.BvinToNullableGuid(productId);
            var storeId = Context.CurrentStore.Id;

            return(FindListPoco(q =>
            {
                return q.Where(y => y.ProductId == guid)
                .Where(y => y.StoreId == storeId)
                .OrderByDescending(y => y.Karma)
                .ThenByDescending(y => y.ReviewDate);
            }, pageNumber, pageSize));
        }
Пример #7
0
        public void RegisterEvent(string userId, ActionTypes actionType, string objectId)
        {
            var analyticsEvent = new AnalyticsEvent();

            analyticsEvent.UserId              = userId;
            analyticsEvent.SessionGuid         = SessionManager.GetCurrentSessionGuid();
            analyticsEvent.ShoppingSessionGuid = SessionManager.GetCurrentShoppingSessionGuid();
            analyticsEvent.StoreId             = Context.CurrentStore.Id;
            analyticsEvent.Action              = actionType;
            analyticsEvent.ObjectId            = DataTypeHelper.BvinToNullableGuid(objectId);
            analyticsEvent.DateTime            = DateTime.UtcNow;

            AnalyticsEvents.Create(analyticsEvent);
        }
        public int FindMaxSort(string parentId)
        {
            var storeId    = Context.CurrentStore.Id;
            var parentGuid = DataTypeHelper.BvinToNullableGuid(parentId);

            using (var s = CreateStrategy())
            {
                var maxSortOrder = GetJoinedQuery(s)
                                   .Where(y => y.Item.ParentID == parentGuid || !(parentGuid.HasValue || y.Item.ParentID.HasValue))
                                   .Where(y => y.Item.StoreId == storeId)
                                   .Max(y => (int?)y.Item.SortOrder);

                return(maxSortOrder ?? 0);
            }
        }
        private void RegisterAnalyticsEvent(HotcakesApplication app, DateTime dateTime, ActionTypes actionType,
                                            string objectId, Guid shoppingSessionGuid)
        {
            var analyticsEvent = new AnalyticsEvent();

            analyticsEvent.UserId              = null;
            analyticsEvent.SessionGuid         = null;
            analyticsEvent.ShoppingSessionGuid = shoppingSessionGuid;
            analyticsEvent.StoreId             = app.CurrentStore.Id;
            analyticsEvent.Action              = actionType;
            analyticsEvent.ObjectId            = DataTypeHelper.BvinToNullableGuid(objectId);
            analyticsEvent.DateTime            = dateTime;

            app.AnalyticsService.AnalyticsEvents.Create(analyticsEvent);
        }
Пример #10
0
 protected override void CopyModelToItem(JoinedItem <hcc_Product, hcc_ProductTranslation> data, Product model)
 {
     data.Item.AllowReviews        = model.AllowReviews;
     data.Item.bvin                = DataTypeHelper.BvinToGuid(model.Bvin);
     data.Item.CreationDate        = model.CreationDateUtc;
     data.Item.CustomProperties    = model.CustomPropertiesToXml();
     data.Item.Featured            = model.Featured;
     data.Item.IsSearchable        = model.IsSearchable;
     data.Item.GiftWrapAllowed     = model.GiftWrapAllowed ? 1 : 0;
     data.Item.GiftWrapPrice       = model.GiftWrapPrice;
     data.Item.ImageFileMedium     = model.ImageFileMedium;
     data.Item.ImageFileSmall      = model.ImageFileSmall;
     data.Item.OutOfStockMode      = (int)model.InventoryMode;
     data.Item.IsAvailableForSale  = model.IsAvailableForSale;
     data.Item.IsUserPrice         = model.IsUserSuppliedPrice;
     data.Item.HideQty             = model.HideQty;
     data.Item.LastUpdated         = model.LastUpdated;
     data.Item.ListPrice           = model.ListPrice;
     data.Item.ManufacturerID      = DataTypeHelper.BvinToNullableGuid(model.ManufacturerId);
     data.Item.MinimumQty          = model.MinimumQty;
     data.Item.PostContentColumnId = model.PostContentColumnId;
     data.Item.PreContentColumnId  = model.PreContentColumnId;
     data.Item.ProductTypeId       = DataTypeHelper.BvinToNullableGuid(model.ProductTypeId);
     data.Item.ExtraShipFee        = model.ShippingDetails.ExtraShipFee;
     data.Item.ShippingHeight      = model.ShippingDetails.Height;
     data.Item.NonShipping         = model.ShippingDetails.IsNonShipping ? 1 : 0;
     data.Item.ShippingLength      = model.ShippingDetails.Length;
     data.Item.ShippingWeight      = model.ShippingDetails.Weight;
     data.Item.ShippingWidth       = model.ShippingDetails.Width;
     data.Item.ShipSeparately      = model.ShippingDetails.ShipSeparately ? 1 : 0;
     data.Item.ShippingMode        = (int)model.ShippingMode;
     data.Item.SiteCost            = model.SiteCost;
     data.Item.SitePrice           = model.SitePrice;
     data.Item.SKU                   = model.Sku;
     data.Item.Status                = (int)model.Status;
     data.Item.StoreId               = model.StoreId;
     data.Item.TaxExempt             = model.TaxExempt ? 1 : 0;
     data.Item.TaxClass              = model.TaxSchedule.ToString();
     data.Item.TemplateName          = model.TemplateName;
     data.Item.RewriteUrl            = model.UrlSlug;
     data.Item.VendorID              = DataTypeHelper.BvinToNullableGuid(model.VendorId);
     data.Item.IsBundle              = model.IsBundle;
     data.Item.IsGiftCard            = model.IsGiftCard;
     data.Item.IsRecurring           = model.IsRecurring;
     data.Item.RecurringInterval     = model.RecurringInterval;
     data.Item.RecurringIntervalType = (int)model.RecurringIntervalType;
     data.Item.ShippingCharge        = (int)model.ShippingCharge;
 }
        public int CountByProductType(string productTypeBvin)
        {
            var result          = 0;
            var storeId         = Context.CurrentStore.Id;
            var productTypeGuid = DataTypeHelper.BvinToNullableGuid(productTypeBvin);

            using (var s = CreateStrategy())
            {
                var temp = s.GetQuery().Where(y => y.StoreId == storeId)
                           .Where(y => y.ProductTypeBvin == productTypeGuid).Count();

                if (temp >= 0)
                {
                    result = temp;
                }
                return(result);
            }
        }
        /// <summary>
        ///     Copies the model to item.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="model">The model.</param>
        protected override void CopyModelToItem(JoinedItem <hcc_Category, hcc_CategoryTranslation> data, Category model)
        {
            data.Item.BannerImageURL      = model.BannerImageUrl;
            data.Item.bvin                = DataTypeHelper.BvinToGuid(model.Bvin);
            data.Item.CustomPageNewWindow = model.CustomPageOpenInNewWindow ? 1 : 0;
            data.Item.CustomPageURL       = model.CustomPageUrl;

            data.Item.DisplaySortOrder    = (int)model.DisplaySortOrder;
            data.Item.Hidden              = model.Hidden ? 1 : 0;
            data.Item.ImageURL            = model.ImageUrl;
            data.Item.CreationDate        = model.CreationDateUtc;
            data.Item.LastUpdated         = model.LastUpdatedUtc;
            data.Item.ParentID            = DataTypeHelper.BvinToNullableGuid(model.ParentId);
            data.Item.PostContentColumnId = model.PostContentColumnId;
            data.Item.PreContentColumnId  = model.PreContentColumnId;
            data.Item.RewriteUrl          = model.RewriteUrl;
            data.Item.ShowInTopMenu       = model.ShowInTopMenu ? 1 : 0;
            data.Item.ShowTitle           = model.ShowTitle ? 1 : 0;
            data.Item.SortOrder           = model.SortOrder;
            data.Item.SourceType          = (int)model.SourceType;
            data.Item.StoreId             = model.StoreId;
            data.Item.TemplateName        = model.TemplateName;
        }
        public ProductSearchResultAdv DoSearch(ProductSearchQueryAdv query, int pageNumber, int pageSize)
        {
            _query = query;
            var result = new ProductSearchResultAdv();

            IQueryable <ProductQuery> dbQuery    = null;
            IQueryable <ProductQuery> dbQueryAll = null;

            _queryCategories    = query.Categories.Select(bvin => DataTypeHelper.BvinToGuid(bvin)).ToList();
            _queryTypes         = query.Types.Select(bvin => DataTypeHelper.BvinToNullableGuid(bvin)).ToList();
            _queryManufacturers = query.Manufacturers.Select(bvin => DataTypeHelper.BvinToNullableGuid(bvin)).ToList();
            _queryVendors       = query.Vendors.Select(bvin => DataTypeHelper.BvinToNullableGuid(bvin)).ToList();
            var selPropIds = query.Properties.Keys.ToList();

            _querySelectedProperties = _context.hcc_ProductProperty.Where(pp => selPropIds.Contains(pp.Id)).ToList();

            var productSecurityFilterQuery = _context.hcc_Product.Where(p => p.Status == (int)ProductStatus.Active);

            if (query.IsConsiderSearchable)
            {
                productSecurityFilterQuery = productSecurityFilterQuery.Where(p => p.IsSearchable == query.IsSearchable);
            }
            var prodQuery = SecurityFilter(productSecurityFilterQuery);

            if (query.SortOrder != CategorySortOrder.ProductName &&
                query.SortOrder != CategorySortOrder.ProductNameDescending)
            {
                dbQuery = prodQuery.Where(p => p.IsAvailableForSale)
                          .GroupJoin(_propertiesJoin, p => p.bvin, ppvj => ppvj.ppv.Item.ProductBvin,
                                     (p, ppvj) =>
                                     new ProductQuery
                {
                    p    = p,
                    pt   = null,
                    ppvj = ppvj.Where(pj => pj.ptypes.Any(pt => pt.ProductTypeBvin == p.ProductTypeId))
                });
            }
            else
            {
                var productTranslation = _context.hcc_ProductTranslations
                                         .Where(
                    it =>
                    it.Culture == _reqContext.MainContentCulture ||
                    it.Culture == _reqContext.FallbackContentCulture);
                dbQuery = prodQuery.Where(p => p.IsAvailableForSale)
                          .GroupJoin(productTranslation, p => p.bvin, pt => pt.ProductId, (p, pt)
                                     =>
                                     new
                {
                    p,
                    pt =
                        pt.OrderBy(ptr => ptr.Culture == _reqContext.MainContentCulture ? 1 : 2)
                        .FirstOrDefault()
                })
                          .GroupJoin(_propertiesJoin, p => p.p.bvin, ppvj => ppvj.ppv.Item.ProductBvin,
                                     (p, ppvj) =>
                                     new ProductQuery
                {
                    p    = p.p,
                    pt   = p.pt,
                    ppvj = ppvj.Where(pj => pj.ptypes.Any(pt => pt.ProductTypeBvin == p.p.ProductTypeId))
                });
            }
            // Fill price info before filtering by price is done
            result.MinPrice = dbQuery.Min(q => (decimal?)q.p.SitePrice) ?? 0;
            result.MaxPrice = dbQuery.Max(q => (decimal?)q.p.SitePrice) ?? 0;

            using (MiniProfiler.Current.Step("Filtering"))
            {
                // Filtering results by price
                dbQuery    = FilterByPrice(dbQuery);
                dbQueryAll = FilterByFacets(dbQuery);

                switch (query.SortOrder)
                {
                case CategorySortOrder.ProductName:
                    dbQueryAll = dbQueryAll.OrderBy(q => q.pt.ProductName);
                    break;

                case CategorySortOrder.ProductNameDescending:
                    dbQueryAll = dbQueryAll.OrderByDescending(q => q.pt.ProductName);
                    break;

                case CategorySortOrder.ProductPriceAscending:
                    dbQueryAll = dbQueryAll.OrderBy(q => q.p.SitePrice);
                    break;

                case CategorySortOrder.ProductPriceDescending:
                    dbQueryAll = dbQueryAll.OrderByDescending(q => q.p.SitePrice);
                    break;

                case CategorySortOrder.ProductSKUAscending:
                    dbQueryAll = dbQueryAll.OrderBy(q => q.p.SKU);
                    break;

                case CategorySortOrder.ProductSKUDescending:
                    dbQueryAll = dbQueryAll.OrderByDescending(q => q.p.SKU);
                    break;

                default:
                    dbQueryAll =
                        dbQueryAll.OrderBy(
                            q =>
                            q.p.hcc_ProductXCategory.Where(z => _queryCategories.Contains(z.CategoryId))
                            .Select(z => z.SortOrder)
                            .FirstOrDefault());
                    break;
                }
            }

            // Fill facets info
            using (MiniProfiler.Current.Step("Build Manufactory Facets"))
            {
                result.Manufacturers = BuildManufactoryFacets(FilterByFacets(dbQuery, "M"));
            }
            using (MiniProfiler.Current.Step("Build Vendors Facets"))
            {
                result.Vendors = BuildVendorsFacets(FilterByFacets(dbQuery, "V"));
            }
            using (MiniProfiler.Current.Step("Build Types Factes"))
            {
                result.Types = BuildTypesFactes(FilterByFacets(dbQuery, "T"));
            }
            using (MiniProfiler.Current.Step("Build Property Facets"))
            {
                result.Properties = BuildPropertyFacets(FilterByFacets(dbQuery, "P"));
            }
            using (MiniProfiler.Current.Step("Build Selections"))
            {
                // Fill selected data
                result.SelectedCategories    = BuildSelectedCategories();
                result.SelectedVendors       = BuildSelectedVendors();
                result.SelectedManufacturers = BuildSelectedManufacturers();
                result.SelectedTypes         = BuildSelectedTypes();
                result.SelectedProperties    = BuildSelectedProperties();

                result.SelectedMinPrice = query.MinPrice ?? result.MinPrice;
                result.SelectedMaxPrice = query.MaxPrice ?? result.MaxPrice;
            }

            using (MiniProfiler.Current.Step("Get Products List"))
            {
                var skip = (pageNumber - 1) * pageSize;
                if (skip < 0)
                {
                    skip = 0;
                }

                var productIds = dbQueryAll.Select(q => q.p.bvin);
                result.TotalCount = productIds.Count();
                result.Products   = productIds.
                                    Skip(skip).
                                    Take(pageSize).
                                    ToList().
                                    Select(guid => DataTypeHelper.GuidToBvin(guid)).
                                    ToList();
            }
            return(result);
        }
Пример #14
0
        private IQueryable <JoinedItem <hcc_Product, hcc_ProductTranslation> > BuildCriteriaQuery(
            ProductSearchCriteria criteria, IRepoStrategy <hcc_Product> s)
        {
            var items = GetSecureQueryForCurrentStore(s);

            var categoryGuid     = DataTypeHelper.BvinToNullableGuid(criteria.CategoryId);
            var productTypeGuid  = DataTypeHelper.BvinToNullableGuid(criteria.ProductTypeId);
            var manufacturerGuid = DataTypeHelper.BvinToNullableGuid(criteria.ManufacturerId);
            var vendorGuid       = DataTypeHelper.BvinToNullableGuid(criteria.VendorId);

            if (criteria.NotCategorized)
            {
                items = items.Where(y => !y.Item.hcc_ProductXCategory.Any());
            }
            else if (categoryGuid.HasValue)
            {
                items =
                    items.Where(
                        y =>
                        y.Item.hcc_ProductXCategory.Where(z => z.CategoryId == categoryGuid).FirstOrDefault() !=
                        null);
            }

            // Display Inactive
            if (!criteria.DisplayInactiveProducts)
            {
                items = items.Where(y => y.Item.Status == 1);
            }
            // Display Bundles
            if (!criteria.DisplayBundles)
            {
                items = items.Where(y => !y.Item.IsBundle);
            }
            // Display Recurring
            if (!criteria.DisplayRecurring)
            {
                items = items.Where(y => !y.Item.IsRecurring);
            }
            // Display Gift Cards
            if (!criteria.DisplayGiftCards)
            {
                items = items.Where(y => !y.Item.IsGiftCard);
            }
            // Status
            if (criteria.Status != ProductStatus.NotSet)
            {
                items = items.Where(y => y.Item.Status == (int)criteria.Status);
            }
            // Inventory Status
            if (criteria.InventoryStatus != ProductInventoryStatus.NotSet)
            {
                if (criteria.InventoryStatus == ProductInventoryStatus.Available)
                {
                    // show products, excluding those that are not available due to inventory settings
                    items =
                        items.Where(
                            y =>
                            y.Item.IsAvailableForSale ||
                            y.Item.OutOfStockMode != (int)ProductInventoryMode.WhenOutOfStockHide);
                }
                else if (criteria.InventoryStatus == ProductInventoryStatus.NotAvailable)
                {
                    // show only products that are not currently availabe in the store due to inventory settings
                    items =
                        items.Where(
                            y =>
                            !y.Item.IsAvailableForSale &&
                            y.Item.OutOfStockMode == (int)ProductInventoryMode.WhenOutOfStockHide);
                }
                else
                {
                    // filter by products with inventory levels that are set (ignore zeroes)
                    items =
                        items.Where(
                            y =>
                            y.Item.hcc_ProductInventory.Where(
                                z =>
                                z.QuantityOnHand <= z.LowStockPoint &&
                                z.QuantityOnHand != 0 & z.LowStockPoint != 0).Any());
                }
            }
            // Product Type
            if (productTypeGuid.HasValue)
            {
                items = items.Where(y => y.Item.ProductTypeId == productTypeGuid);
            }
            // Manufacturer
            if (manufacturerGuid.HasValue)
            {
                items = items.Where(y => y.Item.ManufacturerID == manufacturerGuid);
            }
            // Vendor
            if (vendorGuid.HasValue)
            {
                items = items.Where(y => y.Item.VendorID == vendorGuid);
            }
            // Keywords
            if (!string.IsNullOrEmpty(criteria.Keyword))
            {
                items = items.Where(y => y.Item.SKU.Contains(criteria.Keyword) ||
                                    y.ItemTranslation.ProductName.Contains(criteria.Keyword) ||
                                    y.ItemTranslation.MetaDescription.Contains(criteria.Keyword) ||
                                    y.ItemTranslation.MetaKeywords.Contains(criteria.Keyword) ||
                                    y.ItemTranslation.ShortDescription.Contains(criteria.Keyword) ||
                                    y.ItemTranslation.LongDescription.Contains(criteria.Keyword) ||
                                    y.ItemTranslation.Keywords.Contains(criteria.Keyword) ||
                                    y.ItemTranslation.HiddenSearchKeywords.Contains(criteria.Keyword)
                                    );
            }

            if (!criteria.DisplayProductWithChoice)
            {
                var optionQry = s.GetQuery <hcc_ProductXOption>();
                items = items.Where(y => optionQry.Where(x => x.ProductBvin == y.Item.bvin).Count() <= 0)
                        .Where(
                    y =>
                    y.Item.hcc_BundledProducts.Where(
                        x => optionQry.Any(xx => xx.ProductBvin == x.BundledProductId)).Count() <= 0);
            }

            switch (criteria.CategorySort)
            {
            case CategorySortOrder.ProductName:
                items = items.OrderBy(y => y.ItemTranslation.ProductName);
                break;

            case CategorySortOrder.ProductNameDescending:
                items = items.OrderByDescending(y => y.ItemTranslation.ProductName);
                break;

            case CategorySortOrder.ProductPriceAscending:
                items = items.OrderBy(y => y.Item.SitePrice);
                break;

            case CategorySortOrder.ProductPriceDescending:
                items = items.OrderByDescending(y => y.Item.SitePrice);
                break;

            case CategorySortOrder.ProductSKUAscending:
                items = items.OrderBy(y => y.Item.SKU);
                break;

            case CategorySortOrder.ProductSKUDescending:
                items = items.OrderByDescending(y => y.Item.SKU);
                break;

            default:
                if (categoryGuid.HasValue)
                {
                    items =
                        items.OrderBy(
                            y =>
                            y.Item.hcc_ProductXCategory.Where(z => z.CategoryId == categoryGuid)
                            .Select(z => z.SortOrder)
                            .FirstOrDefault());
                }
                else
                {
                    items = items.OrderBy(y => y.ItemTranslation.ProductName);
                }
                break;
            }
            return(items);
        }
Пример #15
0
        protected bool Save()
        {
            var culture = Thread.CurrentThread.CurrentUICulture;
            var result  = false;

            if (Page.IsValid)
            {
                var p = HccApp.CatalogServices.Products.Find(ProductId);
                if (p == null)
                {
                    p = new Product();
                }

                p.Status       = chkActive.Checked ? ProductStatus.Active : ProductStatus.Disabled;
                p.IsSearchable = chkSearchable.Checked;

                var isBundle = rbBehaviour.SelectedValue == "B";
                var isGC     = rbBehaviour.SelectedValue == "GC";
                p.IsBundle = isBundle;

                if (isGC && p.IsGiftCard != isGC && !string.IsNullOrEmpty(p.Bvin))
                {
                    HccApp.CatalogServices.BundledProducts.DeleteByBundleProductId(p.Bvin);
                }
                p.IsGiftCard = isGC;

                p.TemplateName = ddlTemplateList.SelectedValue;
                p.Featured     = chkFeatured.Checked;

                if (string.Compare(p.Sku.Trim(), SkuField.Text.Trim(), true) != 0)
                {
                    //sku changed, so do a sku check
                    var prodGuid = DataTypeHelper.BvinToNullableGuid(p.Bvin);
                    if (HccApp.CatalogServices.Products.IsSkuExist(SkuField.Text.Trim(), prodGuid))
                    {
                        ucMessageBox.ShowError("Sku already exists on another product. Please pick another sku.");
                        return(false);
                    }
                }

                p.Sku = SkuField.Text.Trim();

                p.ProductName   = txtProductName.Text.Trim();
                p.ProductTypeId = lstProductType.SelectedValue ?? string.Empty;

                p.IsUserSuppliedPrice    = chkUserPrice.Checked;
                p.HideQty                = chkHideQty.Checked;
                p.UserSuppliedPriceLabel = txtUserPriceLabel.Text;

                if (p.IsUserSuppliedPrice || isGC)
                {
                    p.ListPrice             = 0;
                    p.SiteCost              = 0;
                    p.SitePrice             = 0;
                    p.SitePriceOverrideText = string.Empty;
                }
                else
                {
                    decimal listPrice;
                    if (decimal.TryParse(ListPriceField.Text, NumberStyles.Currency, culture, out listPrice))
                    {
                        p.ListPrice = Money.RoundCurrency(listPrice);
                    }
                    decimal cost;
                    if (decimal.TryParse(CostField.Text, NumberStyles.Currency, Thread.CurrentThread.CurrentUICulture,
                                         out cost))
                    {
                        p.SiteCost = Money.RoundCurrency(cost);
                    }
                    decimal price;
                    if (decimal.TryParse(SitePriceField.Text, NumberStyles.Currency,
                                         Thread.CurrentThread.CurrentUICulture, out price))
                    {
                        p.SitePrice = Money.RoundCurrency(price);
                    }
                    p.SitePriceOverrideText = PriceOverrideTextBox.Text.Trim();
                }
                p.LongDescription = LongDescriptionField.Text.Trim();
                p.ManufacturerId  = lstManufacturers.SelectedValue ?? string.Empty;
                p.VendorId        = lstVendors.SelectedValue ?? string.Empty;


                if (string.IsNullOrEmpty(SmallImageAlternateTextField.Text))
                {
                    p.ImageFileSmallAlternateText = p.ProductName + " " + p.Sku;
                }
                else
                {
                    p.ImageFileSmallAlternateText = SmallImageAlternateTextField.Text;
                }
                if (string.IsNullOrEmpty(MediumImageAlternateTextField.Text))
                {
                    p.ImageFileMediumAlternateText = p.ProductName + " " + p.Sku;
                }
                else
                {
                    p.ImageFileMediumAlternateText = MediumImageAlternateTextField.Text;
                }

                p.PreContentColumnId  = ddlPreContentColumn.SelectedValue;
                p.PostContentColumnId = ddlPostContentColumn.SelectedValue;

                var oldUrl = p.UrlSlug;

                // no entry, generate one
                if (p.UrlSlug.Trim().Length < 1)
                {
                    p.UrlSlug = Text.Slugify(p.ProductName, false);
                }
                else
                {
                    p.UrlSlug = Text.Slugify(txtRewriteUrl.Text, false);
                }

                if (UrlRewriter.IsProductSlugInUse(p.UrlSlug, p.Bvin, HccApp))
                {
                    ucMessageBox.ShowWarning("The requested URL is already in use by another item.");
                    return(false);
                }

                p.Keywords      = txtKeywords.Text.Trim();
                p.ProductTypeId = lstProductType.SelectedValue;
                if (!string.IsNullOrEmpty(lstTaxClasses.SelectedValue))
                {
                    p.TaxSchedule = long.Parse(lstTaxClasses.SelectedValue);
                }
                else
                {
                    p.TaxSchedule = -1;
                }

                p.MetaTitle       = txtMetaTitle.Text.Trim();
                p.MetaDescription = txtMetaDescription.Text.Trim();
                p.MetaKeywords    = txtMetaKeywords.Text.Trim();

                decimal weight = 0;
                decimal.TryParse(txtWeight.Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out weight);
                p.ShippingDetails.Weight = weight;

                decimal length = 0;
                decimal.TryParse(txtLength.Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out length);
                p.ShippingDetails.Length = length;

                decimal width = 0;
                decimal.TryParse(txtWidth.Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out width);
                p.ShippingDetails.Width = width;

                decimal height = 0;
                decimal.TryParse(txtHeight.Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out height);
                p.ShippingDetails.Height = height;

                p.ShippingDetails.ExtraShipFee =
                    Money.RoundCurrency(decimal.Parse(ExtraShipFeeField.Text, NumberStyles.Currency, culture));
                p.ShippingMode = (ShippingMode)int.Parse(ddlShipType.SelectedValue);
                p.ShippingDetails.IsNonShipping  = chkNonShipping.Checked;
                p.ShippingDetails.ShipSeparately = chkShipSeparately.Checked;

                p.ShippingCharge = (ShippingChargeType)int.Parse(lstShippingCharge.SelectedValue);

                p.MinimumQty = int.Parse(txtMinimumQty.Text, NumberStyles.Integer, Thread.CurrentThread.CurrentUICulture);

                p.TaxExempt = TaxExemptField.Checked;

                p.GiftWrapAllowed = false;

                if (!string.IsNullOrWhiteSpace(rblAllowReviews.SelectedValue))
                {
                    p.AllowReviews = bool.Parse(rblAllowReviews.SelectedValue);
                }
                else
                {
                    p.AllowReviews = null;
                }
                p.SwatchPath = swatchpathfield.Text;

                if (ucImageUploadLarge.HasFile)
                {
                    var fileName = Text.CleanFileName(Path.GetFileName(ucImageUploadLarge.FileName));
                    p.ImageFileMedium = fileName;
                    p.ImageFileSmall  = fileName;
                }

                if (string.IsNullOrEmpty(p.Bvin))
                {
                    result = HccApp.CatalogServices.ProductsCreateWithInventory(p, true);
                }
                else
                {
                    result = HccApp.CatalogServices.ProductsUpdateWithSearchRebuild(p);
                }

                if (result)
                {
                    // Create taxonomy tags
                    var taxonomyTags = txtTaxonomyTags.Text.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    HccApp.SocialService.UpdateProductTaxonomy(p, taxonomyTags);

                    // Save images
                    UploadImage(p);

                    // Store propety values
                    var props = HccApp.CatalogServices.ProductPropertiesFindForType(lstProductType.SelectedValue);
                    foreach (var prop in props)
                    {
                        if (_productTypeProperties.ContainsKey(prop.Id))
                        {
                            HccApp.CatalogServices.ProductPropertyValues.SetPropertyValue(p.Bvin, prop,
                                                                                          _productTypeProperties[prop.Id]);
                        }
                    }

                    // Update bvin field so that next save will call updated instead of create
                    ProductId = p.Bvin;

                    if (!string.IsNullOrEmpty(oldUrl) && oldUrl != p.UrlSlug)
                    {
                        HccApp.ContentServices.CustomUrls.Register301(oldUrl,
                                                                      p.UrlSlug,
                                                                      p.Bvin, CustomUrlType.Product, HccApp.CurrentRequestContext, HccApp);
                        UrlsAssociated1.LoadUrls();
                    }
                }
                else
                {
                    ucMessageBox.ShowError("Unable to save product. Unknown error. Please check event log.");
                }
            }
            return(result);
        }
Пример #16
0
        public ProductSearchResultAdv DoSearchBySite(long siteId, List <long> wordIds, ProductSearchQueryAdv query,
                                                     int pageNumber, int pageSize)
        {
            using (var context = Factory.CreateHccDbContext())
            {
                var result = new ProductSearchResultAdv();

                var skip = (pageNumber - 1) * pageSize;
                if (skip < 0)
                {
                    skip = 0;
                }

                var dbQuery = context.hcc_SearchObjectWords.
                              Where(w => wordIds.Contains(w.WordId));
                if (siteId > 0)
                {
                    dbQuery = dbQuery.Where(w => w.SiteId == siteId);
                }

                var productPropertyTranslations = context.hcc_ProductPropertyTranslations.
                                                  Where(
                    it =>
                    it.Culture == _hccRequestContext.MainContentCulture ||
                    it.Culture == _hccRequestContext.FallbackContentCulture);
                var productProperties = context.hcc_ProductProperty.Where(pp => pp.DisplayOnSearch).
                                        GroupJoin(productPropertyTranslations, i => i.Id, it => it.ProductPropertyId, (i, it) => new
                {
                    Item            = i,
                    ItemTranslation =
                        it.OrderBy(iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                        .FirstOrDefault()
                });

                var productPropertyValueTranslations = context.hcc_ProductPropertyValueTranslations.
                                                       Where(
                    it =>
                    it.Culture == _hccRequestContext.MainContentCulture ||
                    it.Culture == _hccRequestContext.FallbackContentCulture);
                var productPropertyValues = context.hcc_ProductPropertyValue.
                                            GroupJoin(productPropertyValueTranslations, i => i.Id, it => it.ProductPropertyValueId,
                                                      (i, it) => new
                {
                    Item            = i,
                    ItemTranslation =
                        it.OrderBy(iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                        .FirstOrDefault()
                });

                var propertiesJoin = productProperties.
                                     Join(productPropertyValues, pp => pp.Item.Id, ppv => ppv.Item.PropertyId, (pp, ppv) => new { pp, ppv })
                                     .
                                     GroupJoin(context.hcc_ProductTypeXProductProperty, pv => pv.pp.Item.Id, ptp => ptp.PropertyId,
                                               (pv, ptp) => new { pv.pp, pv.ppv, ptypes = ptp });


                var productSecurityFilterQuery = context.hcc_Product.Where(p => p.Status == (int)ProductStatus.Active);
                if (query.IsConsiderSearchable)
                {
                    productSecurityFilterQuery =
                        productSecurityFilterQuery.Where(p => p.IsSearchable == query.IsSearchable);
                }
                var products = SecurityFilter(productSecurityFilterQuery);

                var dbQueryJ = dbQuery.
                               Join(context.hcc_SearchObjects, sow => sow.SearchObjectId, so => so.Id, (sow, so) => new { sow, so }).
                               Where(s => s.so.ObjectType == (int)SearchManagerObjectType.Product).
                               GroupBy(s => s.so.ObjectId).
                               Select(g => new
                {
                    ObjectId = g.Key,
                    Score    = g.Sum(y => y.sow.Score),
                    Count    = g.Sum(y => 1)
                }).
                               Join(products, s => s.ObjectId, p => p.bvin, (s, p) => new { so = s, p }).
                               GroupJoin(propertiesJoin, s => s.p.bvin, ppvj => ppvj.ppv.Item.ProductBvin,
                                         (s, ppvj) =>
                                         new
                {
                    s.so,
                    s.p,
                    ppvj = ppvj.Where(pj => pj.ptypes.Any(pt => pt.ProductTypeBvin == s.p.ProductTypeId))
                });

                var queryCategories = query.Categories.
                                      Select(bvin => DataTypeHelper.BvinToGuid(bvin)).
                                      ToList();
                var queryTypes = query.Types.
                                 Select(bvin => DataTypeHelper.BvinToNullableGuid(bvin)).
                                 ToList();
                var queryManufactures = query.Manufactures.
                                        Select(bvin => DataTypeHelper.BvinToNullableGuid(bvin)).
                                        ToList();
                var queryVendors = query.Vendors.
                                   Select(bvin => DataTypeHelper.BvinToNullableGuid(bvin)).
                                   ToList();

                if (queryCategories.Count > 0)
                {
                    foreach (var category in queryCategories)
                    {
                        dbQueryJ =
                            dbQueryJ.Where(s => s.p.hcc_ProductXCategory.Select(c => c.CategoryId).Contains(category));
                    }
                }
                if (queryTypes.Count > 0)
                {
                    dbQueryJ = dbQueryJ.Where(s => queryTypes.Contains(s.p.ProductTypeId));
                }
                if (queryManufactures.Count > 0)
                {
                    dbQueryJ = dbQueryJ.Where(s => queryManufactures.Contains(s.p.ManufacturerID));
                }
                if (queryVendors.Count > 0)
                {
                    dbQueryJ = dbQueryJ.Where(s => queryVendors.Contains(s.p.VendorID));
                }
                if (query.Properties.Count > 0)
                {
                    foreach (var pair in query.Properties)
                    {
                        var propertyId    = pair.Key;
                        var propertyValue = pair.Value[0];
                        var property      = context.hcc_ProductProperty.FirstOrDefault(p => p.Id == propertyId);

                        if (property.IsLocalizable)
                        {
                            dbQueryJ =
                                dbQueryJ.Where(
                                    s =>
                                    s.ppvj.Where(
                                        pj =>
                                        pj.ppv.Item.PropertyId == propertyId &&
                                        pj.ppv.ItemTranslation.PropertyLocalizableValue == propertyValue)
                                    .Count() > 0);
                        }
                        else
                        {
                            dbQueryJ =
                                dbQueryJ.Where(
                                    s =>
                                    s.ppvj.Where(
                                        pj =>
                                        pj.ppv.Item.PropertyId == propertyId &&
                                        pj.ppv.Item.PropertyValue == propertyValue).Count() > 0);
                        }
                    }
                }

                // Fill price info before filtering by price is done
                var minPrice = dbQueryJ.Min(s => (decimal?)s.p.SitePrice);
                var maxPrice = dbQueryJ.Max(s => (decimal?)s.p.SitePrice);

                result.MinPrice = minPrice ?? 0;
                result.MaxPrice = maxPrice ?? 0;

                // Filtering results by price
                if (query.MinPrice.HasValue)
                {
                    dbQueryJ = dbQueryJ.Where(s => s.p.SitePrice >= query.MinPrice.Value);
                }
                if (query.MaxPrice.HasValue)
                {
                    dbQueryJ = dbQueryJ.Where(s => s.p.SitePrice <= query.MaxPrice.Value);
                }

                // Fill facets info
                var categoryTranslations = context.hcc_CategoryTranslations.
                                           Where(
                    it =>
                    it.Culture == _hccRequestContext.MainContentCulture ||
                    it.Culture == _hccRequestContext.FallbackContentCulture);
                result.Categories = dbQueryJ.
                                    Join(context.hcc_ProductXCategory, s => s.p.bvin, pc => pc.ProductId, (s, pc) => pc.hcc_Category).
                                    GroupJoin(context.hcc_Category, c => c.ParentID, parent => parent.bvin, (c, parentColl) => new
                {
                    Category = c,
                    Parent   = parentColl.FirstOrDefault()
                }).
                                    GroupBy(c => new { CategoryId = c.Category.bvin, ParentId = c.Category.ParentID }).
                                    Select(g => new
                {
                    g.Key.CategoryId,
                    g.Key.ParentId,
                    Count = g.Sum(t => 1)
                }).
                                    GroupJoin(categoryTranslations, i => i.CategoryId, it => it.CategoryId, (i, it) => new
                {
                    i.CategoryId,
                    i.ParentId,
                    i.Count,
                    ItemTranslation =
                        it.OrderBy(iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                        .FirstOrDefault()
                }).
                                    GroupJoin(categoryTranslations, i => i.ParentId, it => it.CategoryId, (i, it) => new
                {
                    i.CategoryId,
                    i.ParentId,
                    i.Count,
                    i.ItemTranslation,
                    ParentTranslation =
                        it.OrderBy(iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                        .FirstOrDefault()
                }).
                                    Select(c => new InternalFacetItem
                {
                    Id         = c.CategoryId,
                    Name       = c.ItemTranslation.Name,
                    Count      = c.Count,
                    ParentId   = c.ParentId,
                    ParentName = c.ParentId != null ? c.ParentTranslation.Name : null
                }).
                                    OrderByDescending(f => f.Count).
                                    ToList().
                                    Select(f => f.Convert()).
                                    ToList();

                result.Categories = ProductSearchHelper.GroupCategories(result.Categories);

                result.Manufacturers = dbQueryJ.
                                       Join(context.hcc_Manufacturer, s => s.p.ManufacturerID, m => m.bvin, (s, m) => m).
                                       GroupBy(m => new { ManufacturerId = m.bvin, ManufacturerName = m.DisplayName }).
                                       Select(m => new InternalFacetItem
                {
                    Id    = m.Key.ManufacturerId,
                    Name  = m.Key.ManufacturerName,
                    Count = m.Sum(t => 1)
                }).ToList().
                                       Select(f => f.Convert()).
                                       ToList();

                result.Vendors = dbQueryJ.
                                 Join(context.hcc_Vendor, s => s.p.VendorID, v => v.bvin, (s, v) => v).
                                 GroupBy(v => new { VendorId = v.bvin, VendorName = v.DisplayName }).
                                 Select(v => new InternalFacetItem
                {
                    Id    = v.Key.VendorId,
                    Name  = v.Key.VendorName,
                    Count = v.Sum(t => 1)
                }).ToList().
                                 Select(f => f.Convert()).
                                 ToList();

                var productTypeTranslations = context.hcc_ProductTypeTranslations.
                                              Where(
                    it =>
                    it.Culture == _hccRequestContext.MainContentCulture ||
                    it.Culture == _hccRequestContext.FallbackContentCulture);
                result.Types = dbQueryJ.
                               Join(context.hcc_ProductType, s => s.p.ProductTypeId, pt => pt.bvin, (s, pt) => pt).
                               GroupBy(pt => pt.bvin).
                               Select(g => new
                {
                    ProductTypeId = g.Key,
                    Count         = g.Sum(t => 1)
                }).
                               GroupJoin(productTypeTranslations, pt => pt.ProductTypeId, ptt => ptt.ProductTypeId, (i, it) => new
                {
                    ItemTranslation =
                        it.OrderBy(iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                        .FirstOrDefault(),
                    i.Count
                }).
                               Select(pt => new InternalFacetItem
                {
                    Id    = pt.ItemTranslation.ProductTypeId,
                    Name  = pt.ItemTranslation.ProductTypeName,
                    Count = pt.Count
                }).
                               OrderBy(f => f.Name).
                               ToList().
                               Select(f => f.Convert()).
                               ToList();

                // Build product type properties facets

                var customPropertiesInfo = dbQueryJ.
                                           SelectMany(q => q.ppvj).
                                           GroupBy(q => q.pp.Item.Id).
                                           ToList();

                var propertyChoiceTranslations = context.hcc_ProductPropertyChoiceTranslations.
                                                 Where(
                    it =>
                    it.Culture == _hccRequestContext.MainContentCulture ||
                    it.Culture == _hccRequestContext.FallbackContentCulture);
                foreach (var customPropertyInfo in customPropertiesInfo)
                {
                    var propertyFacet = new PropertyFacetItem();

                    var           property       = customPropertyInfo.FirstOrDefault().pp;
                    List <string> propertyValues = null;
                    if (property.Item.IsLocalizable)
                    {
                        propertyValues = customPropertyInfo.
                                         Where(r => r.ppv.ItemTranslation != null).
                                         Select(r => r.ppv.ItemTranslation.PropertyLocalizableValue).
                                         Distinct().ToList();
                    }
                    else
                    {
                        propertyValues = customPropertyInfo.
                                         Where(r => r.ppv.Item != null).
                                         Select(r => r.ppv.Item.PropertyValue).
                                         Distinct().ToList();
                    }

                    propertyFacet.Id           = property.Item.Id;
                    propertyFacet.PropertyName = property.Item.PropertyName;
                    if (property.ItemTranslation != null)
                    {
                        propertyFacet.DisplayName = property.ItemTranslation.DisplayName;
                    }
                    else
                    {
                        propertyFacet.DisplayName = property.Item.PropertyName;
                    }

                    foreach (var propertyValue in propertyValues)
                    {
                        if (!string.IsNullOrEmpty(propertyValue))
                        {
                            var facetItem = new FacetItem();

                            facetItem.Id = propertyValue;
                            if (property.Item.TypeCode == (int)ProductPropertyType.MultipleChoiceField)
                            {
                                var choiceId   = int.Parse(propertyValue);
                                var propChoice = context.hcc_ProductPropertyChoice.
                                                 GroupJoin(propertyChoiceTranslations, i => i.Id, it => it.ProductPropertyChoiceId,
                                                           (i, it) => new
                                {
                                    Item            = i,
                                    ItemTranslation =
                                        it.OrderBy(
                                            iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                                        .FirstOrDefault()
                                }).
                                                 FirstOrDefault(ppc => ppc.Item.Id == choiceId);

                                if (propChoice.ItemTranslation != null)
                                {
                                    facetItem.Name = propChoice.ItemTranslation.DisplayName;
                                }
                            }
                            else
                            {
                                facetItem.Name = propertyValue;
                            }
                            if (property.Item.IsLocalizable)
                            {
                                facetItem.Count = customPropertyInfo.
                                                  Where(r => r.ppv.ItemTranslation != null).
                                                  Count(r => r.ppv.ItemTranslation.PropertyLocalizableValue == propertyValue);
                            }
                            else
                            {
                                facetItem.Count = customPropertyInfo.
                                                  Where(r => r.ppv.Item != null).
                                                  Count(r => r.ppv.Item.PropertyValue == propertyValue);
                            }

                            propertyFacet.FacetItems.Add(facetItem);
                        }
                    }
                    result.Properties.Add(propertyFacet);
                }
                // End - Build product type properties facets

                // Fill selected data
                result.SelectedCategories = context.hcc_Category.
                                            Where(c => queryCategories.Contains(c.bvin)).
                                            GroupJoin(categoryTranslations, i => i.bvin, it => it.CategoryId, (i, it) => new
                {
                    Item            = i,
                    ItemTranslation =
                        it.OrderBy(iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                        .FirstOrDefault()
                }).
                                            Select(c => new InternalSelectedFacetItem
                {
                    Id   = c.Item.bvin,
                    Name = c.ItemTranslation.Name
                }).
                                            ToList().
                                            Select(f => f.Convert()).
                                            ToList();

                result.SelectedVendors = context.hcc_Vendor.
                                         Where(v => queryVendors.Contains(v.bvin)).
                                         Select(v => new InternalSelectedFacetItem
                {
                    Id   = v.bvin,
                    Name = v.DisplayName
                }).
                                         ToList().
                                         Select(f => f.Convert()).
                                         ToList();

                result.SelectedManufacturers = context.hcc_Manufacturer.
                                               Where(m => queryManufactures.Contains(m.bvin)).
                                               Select(m => new InternalSelectedFacetItem
                {
                    Id   = m.bvin,
                    Name = m.DisplayName
                }).
                                               ToList().
                                               Select(f => f.Convert()).
                                               ToList();

                result.SelectedTypes = context.hcc_ProductType.
                                       Where(pt => queryTypes.Contains(pt.bvin)).
                                       GroupJoin(productTypeTranslations, pt => pt.bvin, ptt => ptt.ProductTypeId, (i, it) => new
                {
                    Item            = i,
                    ItemTranslation =
                        it.OrderBy(iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                        .FirstOrDefault()
                }).
                                       Select(pt => new InternalSelectedFacetItem
                {
                    Id   = pt.Item.bvin,
                    Name = pt.ItemTranslation.ProductTypeName
                }).
                                       ToList().
                                       Select(f => f.Convert()).
                                       ToList();

                result.SelectedProperties = new List <SelectedPropertyFacetItem>();
                foreach (var property in query.Properties)
                {
                    var propertyId    = property.Key;
                    var propertyValue = property.Value[0];

                    var productProperty = productProperties.
                                          Where(pp => pp.Item.Id == propertyId).
                                          FirstOrDefault();

                    if (productProperty != null)
                    {
                        var propFacet = new SelectedPropertyFacetItem();
                        propFacet.Id             = productProperty.Item.Id;
                        propFacet.PropertyName   = productProperty.Item.PropertyName;
                        propFacet.DisplayName    = productProperty.ItemTranslation.DisplayName;
                        propFacet.PropertyValues = new List <SelectedFacetItem>();

                        if (productProperty.Item.TypeCode == (int)ProductPropertyType.MultipleChoiceField)
                        {
                            var choiceId   = int.Parse(propertyValue);
                            var propChoice = context.hcc_ProductPropertyChoice.
                                             GroupJoin(propertyChoiceTranslations, i => i.Id, it => it.ProductPropertyChoiceId,
                                                       (i, it) => new
                            {
                                Item            = i,
                                ItemTranslation =
                                    it.OrderBy(
                                        iit => iit.Culture == _hccRequestContext.MainContentCulture ? 1 : 2)
                                    .FirstOrDefault()
                            }).
                                             FirstOrDefault(ppc => ppc.Item.Id == choiceId);

                            if (propChoice.ItemTranslation != null)
                            {
                                propFacet.PropertyValues.Add(new SelectedFacetItem
                                {
                                    Id   = propertyValue,
                                    Name = propChoice.ItemTranslation.DisplayName
                                });
                            }
                        }
                        else
                        {
                            propFacet.PropertyValues.Add(new SelectedFacetItem
                            {
                                Id   = propertyValue,
                                Name = propertyValue
                            });
                        }
                        result.SelectedProperties.Add(propFacet);
                    }
                }

                result.SelectedMinPrice = query.MinPrice ?? result.MinPrice;
                result.SelectedMaxPrice = query.MaxPrice ?? result.MaxPrice;

                var step1a = dbQueryJ.
                             OrderByDescending(y => y.so.Count).
                             ThenByDescending(y => y.so.Score).
                             Select(y => y.p.bvin);

                result.TotalCount = step1a.Count();
                result.Products   = step1a.
                                    Skip(skip).
                                    Take(pageSize).
                                    ToList().
                                    Select(guid => DataTypeHelper.GuidToBvin(guid)).
                                    ToList();

                return(result);
            }
        }