Skip to content

Commit a80ca88

Browse files
committed
Added paging to backend checkout attribute list
1 parent 6acca50 commit a80ca88

5 files changed

Lines changed: 57 additions & 30 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Export email attachments needs to be stored in database because the temp file may not exist anymore when sending the email
2626
* #913 Use HTML5 Input types (tel, email)
2727
* Added paging to frontend order list
28+
* Added paging to backend checkout attribute list
2829

2930
### Bugfixes
3031
* Fixed ajax cache issue when saving payment or shipping restrictions. Internet Explorer showed the old data state (before storage).

src/Libraries/SmartStore.Services/Orders/CheckoutAttributeService.cs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,40 @@ public virtual void DeleteCheckoutAttribute(CheckoutAttribute checkoutAttribute)
8585
_eventPublisher.EntityDeleted(checkoutAttribute);
8686
}
8787

88+
/// <summary>
89+
/// Gets checkout attributes
90+
/// </summary>
91+
/// <param name="storeId">Whether to filter result by store identifier</param>
92+
/// <param name="showHidden">A value indicating whether to show hidden records</param>
93+
/// <returns>Checkout attributes query</returns>
94+
public virtual IQueryable<CheckoutAttribute> GetCheckoutAttributes(int storeId = 0, bool showHidden = false)
95+
{
96+
var query = _checkoutAttributeRepository.Table;
97+
98+
if (!showHidden)
99+
query = query.Where(x => x.IsActive);
100+
101+
if (storeId > 0 && !QuerySettings.IgnoreMultiStore)
102+
{
103+
query =
104+
from x in query
105+
join sm in _storeMappingRepository.Table on new { c1 = x.Id, c2 = "CheckoutAttribute" } equals new { c1 = sm.EntityId, c2 = sm.EntityName } into x_sm
106+
from sm in x_sm.DefaultIfEmpty()
107+
where !x.LimitedToStores || storeId == sm.StoreId
108+
select x;
109+
110+
query =
111+
from x in query
112+
group x by x.Id into grp
113+
orderby grp.Key
114+
select grp.FirstOrDefault();
115+
}
116+
117+
query = query.OrderBy(x => x.DisplayOrder);
118+
119+
return query;
120+
}
121+
88122
/// <summary>
89123
/// Gets all checkout attributes
90124
/// </summary>
@@ -97,32 +131,10 @@ public virtual IList<CheckoutAttribute> GetAllCheckoutAttributes(int storeId = 0
97131

98132
return _cacheManager.Get(key, () =>
99133
{
100-
var query = _checkoutAttributeRepository.Table;
101-
102-
if (!showHidden)
103-
query = query.Where(x => x.IsActive);
104-
105-
if (storeId > 0 && !QuerySettings.IgnoreMultiStore)
106-
{
107-
query =
108-
from x in query
109-
join sm in _storeMappingRepository.Table on new { c1 = x.Id, c2 = "CheckoutAttribute" } equals new { c1 = sm.EntityId, c2 = sm.EntityName } into x_sm
110-
from sm in x_sm.DefaultIfEmpty()
111-
where !x.LimitedToStores || storeId == sm.StoreId
112-
select x;
113-
114-
query =
115-
from x in query
116-
group x by x.Id into grp
117-
orderby grp.Key
118-
select grp.FirstOrDefault();
119-
}
120-
121-
query = query.OrderBy(x => x.DisplayOrder);
122-
123-
var checkoutAttributes = query.ToList();
124-
return checkoutAttributes;
125-
});
134+
var query = GetCheckoutAttributes(storeId, showHidden);
135+
136+
return query.ToList();
137+
});
126138
}
127139

128140
/// <summary>

src/Libraries/SmartStore.Services/Orders/ICheckoutAttributeService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using SmartStore.Core.Domain.Orders;
34

45
namespace SmartStore.Services.Orders
@@ -16,6 +17,14 @@ public partial interface ICheckoutAttributeService
1617
/// <param name="checkoutAttribute">Checkout attribute</param>
1718
void DeleteCheckoutAttribute(CheckoutAttribute checkoutAttribute);
1819

20+
/// <summary>
21+
/// Gets checkout attributes
22+
/// </summary>
23+
/// <param name="storeId">Whether to filter result by store identifier</param>
24+
/// <param name="showHidden">A value indicating whether to show hidden records</param>
25+
/// <returns>Checkout attributes query</returns>
26+
IQueryable<CheckoutAttribute> GetCheckoutAttributes(int storeId = 0, bool showHidden = false);
27+
1928
/// <summary>
2029
/// Gets all checkout attributes
2130
/// </summary>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Web.Mvc;
44
using SmartStore.Admin.Models.Orders;
5+
using SmartStore.Core;
56
using SmartStore.Core.Domain.Common;
67
using SmartStore.Core.Domain.Directory;
78
using SmartStore.Core.Domain.Orders;
@@ -158,16 +159,17 @@ public ActionResult List(GridCommand command)
158159

159160
if (_services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog))
160161
{
161-
var checkoutAttributes = _checkoutAttributeService.GetAllCheckoutAttributes(0, true);
162+
var query = _checkoutAttributeService.GetCheckoutAttributes(0, true);
163+
var pagedList = new PagedList<CheckoutAttribute>(query, command.Page - 1, command.PageSize);
162164

163-
model.Data = checkoutAttributes.Select(x =>
165+
model.Data = pagedList.Select(x =>
164166
{
165167
var caModel = x.ToModel();
166168
caModel.AttributeControlTypeName = x.AttributeControlType.GetLocalizedEnum(_services.Localization, _services.WorkContext);
167169
return caModel;
168170
});
169171

170-
model.Total = checkoutAttributes.Count();
172+
model.Total = pagedList.TotalCount;
171173
}
172174
else
173175
{

src/Presentation/SmartStore.Web/Administration/Views/CheckoutAttribute/List.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
@T("Admin.Catalog.Attributes.CheckoutAttributes")
99
</div>
1010
<div class="options">
11-
<a href="@Url.Action("Create")" class="btn btn-primary"><i class="fa fa-plus"></i>&nbsp;@T("Admin.Common.AddNew")</a>
11+
<a href="@Url.Action("Create")" class="btn btn-primary">
12+
<i class="fa fa-plus"></i>&nbsp;@T("Admin.Common.AddNew")
13+
</a>
1214
</div>
1315
</div>
1416
<script>
@@ -43,6 +45,7 @@
4345
.Hidden(Model.AvailableStores.Count <= 1)
4446
.Centered();
4547
})
48+
.Pageable(settings => settings.PageSize(Model.GridPageSize).Position(GridPagerPosition.Both))
4649
.DataBinding(dataBinding => dataBinding.Ajax().Select("List", "CheckoutAttribute"))
4750
.ClientEvents(events => events.OnRowDataBound("checkoutAttributesGrid_onRowDataBound"))
4851
.EnableCustomBinding(true))

0 commit comments

Comments
 (0)