Skip to content

Commit 4824f2d

Browse files
committed
Further changes on "SearchProducts" method of "IProductService"
1 parent b067f52 commit 4824f2d

9 files changed

Lines changed: 47 additions & 29 deletions

File tree

migrations/1.0.1-next/migrate-multistore.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ CREATE PROCEDURE [dbo].[ProductLoadAllPaged]
416416
(
417417
@CategoryIds nvarchar(MAX) = null, --a list of category IDs (comma-separated list). e.g. 1,2,3
418418
@ManufacturerId int = 0,
419+
@StoreId int = 0,
419420
@ProductTagId int = 0,
420421
@FeaturedProducts bit = null, --0 featured only , 1 not featured only, null - load all products
421422
@PriceMin decimal(18, 4) = null,
@@ -429,7 +430,6 @@ CREATE PROCEDURE [dbo].[ProductLoadAllPaged]
429430
@LanguageId int = 0,
430431
@OrderBy int = 0, --0 position, 5 - Name: A to Z, 6 - Name: Z to A, 10 - Price: Low to High, 11 - Price: High to Low, 15 - creation date
431432
@AllowedCustomerRoleIds nvarchar(MAX) = null, --a list of customer role IDs (comma-separated list) for which a product should be shown (if a subjet to ACL)
432-
@StoreId int = 0,
433433
@PageIndex int = 0,
434434
@PageSize int = 2147483644,
435435
@ShowHidden bit = 0,
@@ -887,8 +887,8 @@ BEGIN
887887
))'
888888
END
889889

890-
--show hidden and filter by store
891-
IF @ShowHidden = 0
890+
--filter by store
891+
IF @StoreId > 0
892892
BEGIN
893893
SET @sql = @sql + '
894894
AND (p.LimitedToStores = 0 OR EXISTS (

src/Libraries/SmartStore.Services/Catalog/ProductSearchContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public ProductSearchContext()
100100
public bool ShowHidden { get; set; }
101101

102102
/// <summary>
103-
/// Current store id
103+
/// Store identifier; 0 to load all records
104104
/// </summary>
105-
public int CurrentStoreId { get; set; }
105+
public int StoreId { get; set; }
106106
}
107107
}

src/Libraries/SmartStore.Services/Catalog/ProductService.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,7 @@ public virtual IPagedList<Product> SearchProducts(ProductSearchContext ctx)
315315

316316
ctx.FilterableSpecificationAttributeOptionIds = new List<int>();
317317

318-
//Current store
319-
ctx.CurrentStoreId = _workContext.CurrentStore.Id;
320-
318+
//search by keyword
321319
bool searchLocalizedValue = false;
322320
if (ctx.LanguageId > 0)
323321
{
@@ -328,11 +326,15 @@ public virtual IPagedList<Product> SearchProducts(ProductSearchContext ctx)
328326
else
329327
{
330328
//ensure that we have at least two published languages
331-
var totalPublishedLanguages = _languageService.GetAllLanguages(storeId: ctx.CurrentStoreId).Count;
329+
var totalPublishedLanguages = _languageService.GetAllLanguages(storeId: ctx.StoreId).Count;
332330
searchLocalizedValue = totalPublishedLanguages >= 2;
333331
}
334332
}
335333

334+
//validate "categoryIds" parameter
335+
if (ctx.CategoryIds != null && ctx.CategoryIds.Contains(0))
336+
ctx.CategoryIds.Remove(0);
337+
336338
//Access control list. Allowed customer roles
337339
var allowedCustomerRolesIds = _workContext.CurrentCustomer.CustomerRoles
338340
.Where(cr => cr.Active).Select(cr => cr.Id).ToList();
@@ -399,6 +401,11 @@ public virtual IPagedList<Product> SearchProducts(ProductSearchContext ctx)
399401
pManufacturerId.Value = ctx.ManufacturerId;
400402
pManufacturerId.DbType = DbType.Int32;
401403

404+
var pStoreId = _dataProvider.GetParameter();
405+
pStoreId.ParameterName = "StoreId";
406+
pStoreId.Value = ctx.StoreId;
407+
pStoreId.DbType = DbType.Int32;
408+
402409
var pProductTagId = _dataProvider.GetParameter();
403410
pProductTagId.ParameterName = "ProductTagId";
404411
pProductTagId.Value = ctx.ProductTagId;
@@ -464,11 +471,6 @@ public virtual IPagedList<Product> SearchProducts(ProductSearchContext ctx)
464471
pAllowedCustomerRoleIds.Value = commaSeparatedAllowedCustomerRoleIds;
465472
pAllowedCustomerRoleIds.DbType = DbType.String;
466473

467-
var pStoreId = _dataProvider.GetParameter();
468-
pStoreId.ParameterName = "StoreId";
469-
pStoreId.Value = ctx.CurrentStoreId;
470-
pStoreId.DbType = DbType.Int32;
471-
472474
var pPageIndex = _dataProvider.GetParameter();
473475
pPageIndex.ParameterName = "PageIndex";
474476
pPageIndex.Value = ctx.PageIndex;
@@ -505,6 +507,7 @@ public virtual IPagedList<Product> SearchProducts(ProductSearchContext ctx)
505507
"ProductLoadAllPaged",
506508
pCategoryIds,
507509
pManufacturerId,
510+
pStoreId,
508511
pProductTagId,
509512
pFeaturedProducts,
510513
pPriceMin,
@@ -518,7 +521,6 @@ public virtual IPagedList<Product> SearchProducts(ProductSearchContext ctx)
518521
pLanguageId,
519522
pOrderBy,
520523
pAllowedCustomerRoleIds,
521-
pStoreId,
522524
pPageIndex,
523525
pPageSize,
524526
pShowHidden,
@@ -553,10 +555,9 @@ public virtual IPagedList<Product> SearchProducts(ProductSearchContext ctx)
553555
// if we use standard Distinct() method, then all fields will be compared (low performance)
554556
// it'll not work in SQL Server Compact when searching products by a keyword)
555557
query = from p in query
556-
group p by p.Id
557-
into pGroup
558-
orderby pGroup.Key
559-
select pGroup.FirstOrDefault();
558+
group p by p.Id into pGroup
559+
orderby pGroup.Key
560+
select pGroup.FirstOrDefault();
560561

561562
//sort products
562563
if (ctx.OrderBy == ProductSortingEnum.Position && ctx.CategoryIds != null && ctx.CategoryIds.Count > 0)
@@ -689,14 +690,17 @@ join acl in _aclRepository.Table on p.Id equals acl.EntityId into p_acl
689690
from acl in p_acl.DefaultIfEmpty()
690691
where !p.SubjectToAcl || (acl.EntityName == "Product" && allowedCustomerRolesIds.Contains(acl.CustomerRoleId))
691692
select p;
693+
}
692694

695+
if (ctx.StoreId > 0)
696+
{
693697
//Store mapping
694698
query = from p in query
695699
join sm in _storeMappingRepository.Table on p.Id equals sm.EntityId into p_sm
696700
from sm in p_sm.DefaultIfEmpty()
697-
where !p.LimitedToStores || (sm.EntityName == "Product" && ctx.CurrentStoreId == sm.StoreId)
701+
where !p.LimitedToStores || (sm.EntityName == "Product" && ctx.StoreId == sm.StoreId)
698702
select p;
699-
}
703+
}
700704

701705
// product variants
702706
// The function 'CurrentUtcDateTime' is not supported by SQL Server Compact.

src/Libraries/SmartStore.Services/Seo/SitemapGenerator.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ namespace SmartStore.Services.Seo
1313
/// </summary>
1414
public partial class SitemapGenerator : BaseSitemapGenerator, ISitemapGenerator
1515
{
16+
private readonly IWorkContext _workContext;
1617
private readonly ICategoryService _categoryService;
1718
private readonly IProductService _productService;
1819
private readonly IManufacturerService _manufacturerService;
1920
private readonly ITopicService _topicService;
2021
private readonly CommonSettings _commonSettings;
2122
private readonly IWebHelper _webHelper;
2223

23-
public SitemapGenerator(ICategoryService categoryService,
24+
public SitemapGenerator(IWorkContext workContext, ICategoryService categoryService,
2425
IProductService productService, IManufacturerService manufacturerService,
2526
ITopicService topicService, CommonSettings commonSettings, IWebHelper webHelper)
2627
{
28+
this._workContext = workContext;
2729
this._categoryService = categoryService;
2830
this._productService = productService;
2931
this._manufacturerService = manufacturerService;
@@ -92,7 +94,8 @@ private void WriteProducts()
9294
var ctx = new ProductSearchContext()
9395
{
9496
OrderBy = ProductSortingEnum.CreatedOn,
95-
PageSize = int.MaxValue
97+
PageSize = int.MaxValue,
98+
StoreId = _workContext.CurrentStore.Id
9699
};
97100

98101
var products = _productService.SearchProducts(ctx);

src/Presentation/SmartStore.Web/Administration/Controllers/ActivityLogController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public JsonResult ListLogs(GridCommand command, ActivityLogSearchModel model)
142142
}),
143143
Total = activityLog.TotalCount
144144
};
145-
return new JsonResult { Data = gridModel};;
145+
return new JsonResult { Data = gridModel};
146146
}
147147

148148
[GridAction(EnableCustomBinding = true)]

src/Presentation/SmartStore.Web/App_Data/SqlServer.StoredProcedures.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ CREATE PROCEDURE [ProductLoadAllPaged]
6767
(
6868
@CategoryIds nvarchar(MAX) = null, --a list of category IDs (comma-separated list). e.g. 1,2,3
6969
@ManufacturerId int = 0,
70+
@StoreId int = 0,
7071
@ProductTagId int = 0,
7172
@FeaturedProducts bit = null, --0 featured only , 1 not featured only, null - load all products
7273
@PriceMin decimal(18, 4) = null,
@@ -80,7 +81,6 @@ CREATE PROCEDURE [ProductLoadAllPaged]
8081
@LanguageId int = 0,
8182
@OrderBy int = 0, --0 position, 5 - Name: A to Z, 6 - Name: Z to A, 10 - Price: Low to High, 11 - Price: High to Low, 15 - creation date
8283
@AllowedCustomerRoleIds nvarchar(MAX) = null, --a list of customer role IDs (comma-separated list) for which a product should be shown (if a subjet to ACL)
83-
@StoreId int = 0,
8484
@PageIndex int = 0,
8585
@PageSize int = 2147483644,
8686
@ShowHidden bit = 0,
@@ -538,8 +538,8 @@ BEGIN
538538
))'
539539
END
540540

541-
--show hidden and filter by store
542-
IF @ShowHidden = 0
541+
--filter by store
542+
IF @StoreId > 0
543543
BEGIN
544544
SET @sql = @sql + '
545545
AND (p.LimitedToStores = 0 OR EXISTS (

src/Presentation/SmartStore.Web/Controllers/CatalogController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ protected void ResolveCategoryProductsCount(TreeNode<CategoryNavigationModel.Cat
624624

625625
var ctx = new ProductSearchContext();
626626
ctx.CategoryIds = categoryIds;
627-
ctx.CurrentStoreId = _workContext.CurrentStore.Id;
627+
ctx.StoreId = _workContext.CurrentStore.Id;
628628
node.Value.NumberOfProducts = _productService.CountProducts(ctx);
629629
}
630630
}
@@ -677,6 +677,7 @@ protected void ResolveCategoryProductsCount(TreeNode<CategoryNavigationModel.Cat
677677
// ctx.CategoryIds = categoryIds;
678678
// //ctx.OrderBy = ProductSortingEnum.Position;
679679
// //ctx.PageSize = 1;
680+
// ctx.StoreId = _workContext.CurrentStore.Id;
680681

681682
// //model.NumberOfProducts = _productService.SearchProducts(ctx).TotalCount;
682683
// model.NumberOfProducts = _productService.CountProducts(ctx);
@@ -1564,6 +1565,7 @@ public ActionResult Category(int categoryId, CatalogPagingFilteringModel command
15641565
ctx.LanguageId = _workContext.WorkingLanguage.Id;
15651566
ctx.OrderBy = ProductSortingEnum.Position;
15661567
ctx.PageSize = int.MaxValue;
1568+
ctx.StoreId = _workContext.CurrentStore.Id;
15671569

15681570
var featuredProducts = _productService.SearchProducts(ctx);
15691571

@@ -1608,6 +1610,7 @@ public ActionResult Category(int categoryId, CatalogPagingFilteringModel command
16081610
ctx2.PageIndex = command.PageNumber - 1;
16091611
ctx2.PageSize = command.PageSize;
16101612
ctx2.LoadFilterableSpecificationAttributeOptionIds = true;
1613+
ctx2.StoreId = _workContext.CurrentStore.Id;
16111614

16121615
var products = _productService.SearchProducts(ctx2);
16131616

@@ -1749,6 +1752,7 @@ public ActionResult Manufacturer(int manufacturerId, CatalogPagingFilteringModel
17491752
ctx.LanguageId = _workContext.WorkingLanguage.Id;
17501753
ctx.OrderBy = ProductSortingEnum.Position;
17511754
ctx.PageSize = int.MaxValue;
1755+
ctx.StoreId = _workContext.CurrentStore.Id;
17521756

17531757
var featuredProducts = _productService.SearchProducts(ctx);
17541758

@@ -1768,6 +1772,7 @@ public ActionResult Manufacturer(int manufacturerId, CatalogPagingFilteringModel
17681772
ctx2.OrderBy = (ProductSortingEnum)command.OrderBy;
17691773
ctx2.PageIndex = command.PageNumber - 1;
17701774
ctx2.PageSize = command.PageSize;
1775+
ctx2.StoreId = _workContext.CurrentStore.Id;
17711776

17721777
var products = _productService.SearchProducts(ctx2);
17731778

@@ -2633,6 +2638,7 @@ public ActionResult RecentlyAddedProducts(CatalogPagingFilteringModel command)
26332638
//ctx.PageIndex = command.PageNumber - 1;
26342639
//codehint: sm-edit end
26352640
ctx.FilterableSpecificationAttributeOptionIds = filterableSpecificationAttributeOptionIds;
2641+
ctx.StoreId = _workContext.CurrentStore.Id;
26362642

26372643
var products = _productService.SearchProducts(ctx);
26382644

@@ -2664,6 +2670,7 @@ public ActionResult RecentlyAddedProductsRss()
26642670
ctx.LanguageId = _workContext.WorkingLanguage.Id;
26652671
ctx.OrderBy = ProductSortingEnum.CreatedOn;
26662672
ctx.PageSize = _catalogSettings.RecentlyAddedProductsNumber;
2673+
ctx.StoreId = _workContext.CurrentStore.Id;
26672674

26682675
var products = _productService.SearchProducts(ctx);
26692676

@@ -2999,6 +3006,7 @@ public ActionResult ProductsByTag(int productTagId, CatalogPagingFilteringModel
29993006
ctx.OrderBy = (ProductSortingEnum)command.OrderBy;
30003007
ctx.PageIndex = command.PageNumber - 1;
30013008
ctx.PageSize = command.PageSize;
3009+
ctx.StoreId = _workContext.CurrentStore.Id;
30023010

30033011
var products = _productService.SearchProducts(ctx);
30043012

@@ -3668,6 +3676,7 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
36683676
ctx.OrderBy = (ProductSortingEnum)command.OrderBy; // ProductSortingEnum.Position; // codehint: sm-edit
36693677
ctx.PageIndex = command.PageNumber - 1;
36703678
ctx.PageSize = command.PageSize;
3679+
ctx.StoreId = _workContext.CurrentStore.Id;
36713680

36723681
products = _productService.SearchProducts(ctx);
36733682

@@ -3707,6 +3716,7 @@ public ActionResult SearchTermAutoComplete(string term)
37073716
ctx.Keywords = term;
37083717
ctx.OrderBy = ProductSortingEnum.Position;
37093718
ctx.PageSize = productNumber;
3719+
ctx.StoreId = _workContext.CurrentStore.Id;
37103720

37113721
var products = _productService.SearchProducts(ctx);
37123722

src/Presentation/SmartStore.Web/Controllers/CommonController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ public ActionResult Sitemap()
779779
productSearchContext.OrderBy = ProductSortingEnum.Position;
780780
productSearchContext.PageSize = 200;
781781
productSearchContext.FilterableSpecificationAttributeOptionIds = filterableSpecificationAttributeOptionIds;
782+
productSearchContext.StoreId = _workContext.CurrentStore.Id;
782783

783784
var products = _productService.SearchProducts(productSearchContext);
784785

src/Presentation/SmartStore.Web/Themes/Mobile/Content/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
.order-summary-content .cart,.wishlist-content .cart{}
8888
.wishlist-content .cart{margin-bottom:10px;}
8989
.order-summary-content .cart .cart-item-row,.wishlist-content .cart .cart-item-row{font-weight:normal;}
90-
.order-summary-content .cart .cart-item-row .product,.wishlist-content .cart .cart-item-row .product{text-align:left;;}
90+
.order-summary-content .cart .cart-item-row .product,.wishlist-content .cart .cart-item-row .product{text-align:left;}
9191
.order-summary-content .cart .cart-item-row .product a,.wishlist-content .cart .cart-item-row .product a{}
9292
.order-summary-content .cart .cart-item-row .sku,.wishlist-content .cart .cart-item-row .sku{}
9393
.order-summary-content .cart .cart-item-row .quantity,.wishlist-content .cart .cart-item-row .quantity{}

0 commit comments

Comments
 (0)