Skip to content

Commit

Permalink
Fixes #434 Shipping.ByTotal: Make grid pageable
Browse files Browse the repository at this point in the history
  • Loading branch information
mgesing committed Aug 22, 2014
1 parent c4e8f97 commit 107928b
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 147 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
* PayPal Standard: Costs for checkout attributes were double charged
* Paging of return request grid did not work
* #428 Multiline checkout attributes aren't rendered correctly
* #434 Shipping.ByTotal: Make grid pageable


##SmartStore.NET 2.0.2#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web.Mvc;
using System.Web.Mvc;
using SmartStore.Core.Domain.Common;
using SmartStore.Core.Domain.Directory;
using SmartStore.Plugin.Shipping.ByTotal.Domain;
using SmartStore.Plugin.Shipping.ByTotal.Models;
Expand All @@ -25,29 +22,29 @@ public class ShippingByTotalController : PluginControllerBase
private readonly IShippingByTotalService _shippingByTotalService;
private readonly ShippingByTotalSettings _shippingByTotalSettings;
private readonly ICountryService _countryService;
private readonly IStateProvinceService _stateProvinceService;
private readonly ICurrencyService _currencyService;
private readonly CurrencySettings _currencySettings;
private readonly AdminAreaSettings _adminAreaSettings;

public ShippingByTotalController(IShippingService shippingService,
IStoreService storeService,
ISettingService settingService,
IShippingByTotalService shippingByTotalService,
ShippingByTotalSettings shippingByTotalSettings,
ICountryService countryService,
IStateProvinceService stateProvinceService,
ICurrencyService currencyService,
CurrencySettings currencySettings)
CurrencySettings currencySettings,
AdminAreaSettings adminAreaSettings)
{
this._shippingService = shippingService;
this._storeService = storeService;
this._settingService = settingService;
this._shippingByTotalService = shippingByTotalService;
this._shippingByTotalSettings = shippingByTotalSettings;
this._countryService = countryService;
this._stateProvinceService = stateProvinceService;
this._currencyService = currencyService;
this._currencySettings = currencySettings;
this._adminAreaSettings = adminAreaSettings;
}

public ActionResult Configure()
Expand Down Expand Up @@ -78,91 +75,25 @@ public ActionResult Configure()
model.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() });
}

//model.AvailableStates.Add(new SelectListItem() { Text = "*", Value = "0" });
model.LimitMethodsToCreated = _shippingByTotalSettings.LimitMethodsToCreated;
model.SmallQuantityThreshold = _shippingByTotalSettings.SmallQuantityThreshold;
model.SmallQuantitySurcharge = _shippingByTotalSettings.SmallQuantitySurcharge;
model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;

model.Records = _shippingByTotalService.GetAllShippingByTotalRecords()
.Select(x =>
{
var m = new ShippingByTotalModel
{
Id = x.Id,
StoreId = x.StoreId,
ShippingMethodId = x.ShippingMethodId,
CountryId = x.CountryId,
StateProvinceId = x.StateProvinceId,
Zip = x.Zip,
From = x.From,
To = x.To,
UsePercentage = x.UsePercentage,
ShippingChargePercentage = x.ShippingChargePercentage,
ShippingChargeAmount = x.ShippingChargeAmount,
BaseCharge = x.BaseCharge,
MaxCharge = x.MaxCharge
};
var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId);
m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable";
//store
var store = _storeService.GetStoreById(x.StoreId);
m.StoreName = (store != null) ? store.Name : "*";
var c = _countryService.GetCountryById(x.CountryId ?? 0);
m.CountryName = (c != null) ? c.Name : "*";
var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId ?? 0);
m.StateProvinceName = (s != null) ? s.Name : "*";
m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*";
return m;
})
.ToList();
model.GridPageSize = _adminAreaSettings.GridPageSize;

return View(model);
}

[HttpPost, GridAction(EnableCustomBinding = true)]
public ActionResult RatesList(GridCommand command)
{
var sbwModel = _shippingByTotalService.GetAllShippingByTotalRecords()
.Select(x =>
{
var m = new ShippingByTotalModel
{
Id = x.Id,
StoreId = x.StoreId,
ShippingMethodId = x.ShippingMethodId,
CountryId = x.CountryId,
From = x.From,
To = x.To,
UsePercentage = x.UsePercentage,
ShippingChargePercentage = x.ShippingChargePercentage,
ShippingChargeAmount = x.ShippingChargeAmount,
BaseCharge = x.BaseCharge,
MaxCharge = x.MaxCharge
};
var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId);
m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable";
//store
var store = _storeService.GetStoreById(x.StoreId);
m.StoreName = (store != null) ? store.Name : "*";
var c = _countryService.GetCountryById(x.CountryId ?? 0);
m.CountryName = (c != null) ? c.Name : "*";
var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId ?? 0);
m.StateProvinceName = (s != null) ? s.Name : "*";
m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*";
return m;
})
.ToList();
int totalCount;
var data = _shippingByTotalService.GetShippingByTotalModels(command.Page - 1, command.PageSize, out totalCount);

var model = new GridModel<ShippingByTotalModel>
{
Data = sbwModel,
Total = sbwModel.Count
Data = data,
Total = totalCount
};

return new JsonResult
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/Shipping.ByTotal/Description.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FriendlyName: Shipping by total
SystemName: Shipping.ByTotal
Version: 1.5
Version: 1.51
MinAppVersion: 2.0.0
DisplayOrder: 1
FileName: SmartStore.Plugin.Shipping.ByTotal.dll
Expand Down
3 changes: 3 additions & 0 deletions src/Plugins/Shipping.ByTotal/Localization/resources.de-de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
</LocaleResource>
<LocaleResource Name="Fields.SmallQuantitySurcharge">
<Value>Mindermengenzuschlag</Value>
</LocaleResource>
<LocaleResource Name="Fields.SmallQuantitySurcharge.Hint">
<Value>Mindermengenzuschlag</Value>
</LocaleResource>
<LocaleResource Name="Fields.Store">
<Value>Shop</Value>
Expand Down
3 changes: 3 additions & 0 deletions src/Plugins/Shipping.ByTotal/Localization/resources.en-us.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
</LocaleResource>
<LocaleResource Name="Fields.SmallQuantitySurcharge">
<Value>Surcharge for small quantities</Value>
</LocaleResource>
<LocaleResource Name="Fields.SmallQuantitySurcharge.Hint">
<Value>Surcharge for small quantities</Value>
</LocaleResource>
<LocaleResource Name="Fields.Store">
<Value>Store</Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public ShippingByTotalListModel()
AvailableCountries = new List<SelectListItem>();
AvailableStates = new List<SelectListItem>();
AvailableShippingMethods = new List<SelectListItem>();
Records = new List<ShippingByTotalModel>();
AvailableStores = new List<SelectListItem>();
AvailableStores = new List<SelectListItem>();
}

[SmartResourceDisplayName("Plugins.Shipping.ByTotal.Fields.Store")]
Expand Down Expand Up @@ -66,10 +65,11 @@ public ShippingByTotalListModel()

public string PrimaryStoreCurrencyCode { get; set; }

public int GridPageSize { get; set; }

public IList<SelectListItem> AvailableCountries { get; set; }
public IList<SelectListItem> AvailableStates { get; set; }
public IList<SelectListItem> AvailableShippingMethods { get; set; }
public IList<ShippingByTotalModel> Records { get; set; }
public IList<SelectListItem> AvailableStores { get; set; }
}
}
22 changes: 17 additions & 5 deletions src/Plugins/Shipping.ByTotal/Services/IShippingByTotalService.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
using System.Collections.Generic;
using System.Linq;
using SmartStore.Core;
using SmartStore.Plugin.Shipping.ByTotal.Domain;
using SmartStore.Plugin.Shipping.ByTotal.Models;

namespace SmartStore.Plugin.Shipping.ByTotal.Services
{
public partial interface IShippingByTotalService
{
/// <summary>
/// Gets all the ShippingByTotalRecords
/// </summary>
/// <returns>ShippingByTotalRecord collection</returns>
IList<ShippingByTotalRecord> GetAllShippingByTotalRecords();
/// <summary>
/// Get queryable shipping by total records
/// </summary>
IQueryable<ShippingByTotalRecord> GetShippingByTotalRecords();

/// <summary>
/// Get paged shipping by total records
/// </summary>
IPagedList<ShippingByTotalRecord> GetShippingByTotalRecords(int pageIndex, int pageSize);

/// <summary>
/// Get models for shipping by total records
/// </summary>
IList<ShippingByTotalModel> GetShippingByTotalModels(int pageIndex, int pageSize, out int totalCount);

/// <summary>
/// Finds the ShippingByTotalRecord by its identifier
Expand Down
Loading

0 comments on commit 107928b

Please sign in to comment.