Skip to content

Commit 5e81e60

Browse files
committed
Resolves smartstore#673 Manufacturer list: Prepend history list of previous selected manufacturers
1 parent 0bde7cd commit 5e81e60

6 files changed

Lines changed: 71 additions & 4 deletions

File tree

src/Libraries/SmartStore.Core/Domain/Catalog/CatalogSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public CatalogSettings()
5353
ShowProductReviewsInProductDetail = true;
5454
HtmlTextCollapsedHeight = 260;
5555
MostRecentlyUsedCategoriesMaxSize = 6;
56+
MostRecentlyUsedManufacturersMaxSize = 4;
5657
}
5758

5859
/// <summary>
@@ -431,5 +432,10 @@ public CatalogSettings()
431432
/// Gets or sets how many items to display maximally in the most recently used category list
432433
/// </summary>
433434
public int MostRecentlyUsedCategoriesMaxSize { get; set; }
435+
436+
/// <summary>
437+
/// Gets or sets how many items to display maximally in the most recently used manufacturer list
438+
/// </summary>
439+
public int MostRecentlyUsedManufacturersMaxSize { get; set; }
434440
}
435441
}

src/Libraries/SmartStore.Core/Domain/Customers/SystemCustomerAttributeNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public static partial class SystemCustomerAttributeNames
3434
public static string ImpersonatedCustomerId { get { return "ImpersonatedCustomerId"; } }
3535
public static string AdminAreaStoreScopeConfiguration { get { return "AdminAreaStoreScopeConfiguration"; } }
3636
public static string MostRecentlyUsedCategories { get { return "MostRecentlyUsedCategories"; } }
37+
public static string MostRecentlyUsedManufacturers { get { return "MostRecentlyUsedManufacturers"; } }
3738

3839
//depends on store
3940
public static string CurrencyId { get { return "CurrencyId"; } }

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
using SmartStore.Core;
66
using SmartStore.Core.Domain.Catalog;
77
using SmartStore.Core.Domain.Common;
8+
using SmartStore.Core.Domain.Customers;
9+
using SmartStore.Core.Infrastructure;
810
using SmartStore.Core.Logging;
911
using SmartStore.Services.Catalog;
12+
using SmartStore.Services.Common;
1013
using SmartStore.Services.ExportImport;
1114
using SmartStore.Services.Helpers;
1215
using SmartStore.Services.Localization;
@@ -182,6 +185,7 @@ private void PrepareManufacturerModel(ManufacturerModel model, Manufacturer manu
182185
public ActionResult AllManufacturers(string label, int selectedId)
183186
{
184187
var manufacturers = _manufacturerService.GetAllManufacturers(true);
188+
185189
if (label.HasValue())
186190
{
187191
manufacturers.Insert(0, new Manufacturer { Name = label, Id = 0 });
@@ -195,7 +199,39 @@ public ActionResult AllManufacturers(string label, int selectedId)
195199
selected = m.Id == selectedId
196200
};
197201

198-
return new JsonResult { Data = list.ToList(), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
202+
var data = list.ToList();
203+
204+
var mru = new MostRecentlyUsedList<string>(_workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.MostRecentlyUsedManufacturers),
205+
_catalogSettings.MostRecentlyUsedManufacturersMaxSize);
206+
207+
// TODO: insert disabled option separator (select2 v.3.4.2 or higher required)
208+
//if (mru.Count > 0)
209+
//{
210+
// data.Insert(0, new
211+
// {
212+
// id = "",
213+
// text = "----------------------",
214+
// selected = false,
215+
// disabled = true
216+
// });
217+
//}
218+
219+
for (int i = mru.Count - 1; i >= 0; --i)
220+
{
221+
string id = mru[i];
222+
var item = manufacturers.FirstOrDefault(x => x.Id.ToString() == id);
223+
if (item != null)
224+
{
225+
data.Insert(0, new
226+
{
227+
id = id,
228+
text = item.Name,
229+
selected = false
230+
});
231+
}
232+
}
233+
234+
return new JsonResult { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
199235
}
200236

201237
public ActionResult Index()

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,11 @@ public ActionResult ProductManufacturerInsert(GridCommand command, ProductModel.
14191419
};
14201420
_manufacturerService.InsertProductManufacturer(productManufacturer);
14211421

1422+
var mru = new MostRecentlyUsedList<string>(_workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.MostRecentlyUsedManufacturers),
1423+
model.Manufacturer, _catalogSettings.MostRecentlyUsedManufacturersMaxSize);
1424+
1425+
_genericAttributeService.SaveAttribute<string>(_workContext.CurrentCustomer, SystemCustomerAttributeNames.MostRecentlyUsedManufacturers, mru.ToString());
1426+
14221427
return ProductManufacturerList(command, model.ProductId);
14231428
}
14241429

@@ -1432,12 +1437,22 @@ public ActionResult ProductManufacturerUpdate(GridCommand command, ProductModel.
14321437
if (productManufacturer == null)
14331438
throw new ArgumentException("No product manufacturer mapping found with the specified id");
14341439

1440+
bool manufacturerChanged = (Int32.Parse(model.Manufacturer) != productManufacturer.ManufacturerId);
1441+
14351442
//use Manufacturer property (not ManufacturerId) because appropriate property is stored in it
14361443
productManufacturer.ManufacturerId = Int32.Parse(model.Manufacturer);
14371444
productManufacturer.IsFeaturedProduct = model.IsFeaturedProduct;
14381445
productManufacturer.DisplayOrder = model.DisplayOrder;
14391446
_manufacturerService.UpdateProductManufacturer(productManufacturer);
14401447

1448+
if (manufacturerChanged)
1449+
{
1450+
var mru = new MostRecentlyUsedList<string>(_workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.MostRecentlyUsedManufacturers),
1451+
model.Manufacturer, _catalogSettings.MostRecentlyUsedManufacturersMaxSize);
1452+
1453+
_genericAttributeService.SaveAttribute<string>(_workContext.CurrentCustomer, SystemCustomerAttributeNames.MostRecentlyUsedManufacturers, mru.ToString());
1454+
}
1455+
14411456
return ProductManufacturerList(command, productManufacturer.ProductId);
14421457
}
14431458

src/Presentation/SmartStore.Web/Administration/Infrastructure/AutoMapperStartupTask.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@ public void Execute()
598598
.ForMember(dest => dest.ShowProductImagesInSearchAutoComplete, mo => mo.Ignore())
599599
.ForMember(dest => dest.ProductSearchPageSize, mo => mo.Ignore())
600600
.ForMember(dest => dest.ManufacturersBlockItemsToDisplay, mo => mo.Ignore())
601-
.ForMember(dest => dest.MostRecentlyUsedCategoriesMaxSize, mo => mo.Ignore());
601+
.ForMember(dest => dest.MostRecentlyUsedCategoriesMaxSize, mo => mo.Ignore())
602+
.ForMember(dest => dest.MostRecentlyUsedManufacturersMaxSize, mo => mo.Ignore());
602603
Mapper.CreateMap<RewardPointsSettings, RewardPointsSettingsModel>()
603604
.ForMember(dest => dest.PrimaryStoreCurrencyCode, mo => mo.Ignore())
604605
.ForMember(dest => dest.PointsForPurchases_OverrideForStore, mo => mo.Ignore());

src/Presentation/SmartStore.Web/Administration/Views/Product/_CreateOrUpdate.Manufacturers.cshtml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
<script>
1010
function onProductManufacturerEdit(e) {
1111
$(e.form).find('#Manufacturer').select2('val', e.dataItem['ManufacturerId']);
12-
}
12+
}
13+
14+
function onProductManufacturerDataBound(e) {
15+
$('#Manufacturer').selectWrapper({ resetDataUrl: '@Url.Action("AllManufacturers", "Manufacturer")' });
16+
}
1317
</script>
1418

1519
@(Html.Telerik().Grid<ProductModel.ProductManufacturerModel>()
@@ -47,7 +51,11 @@
4751
.Width(180);
4852
})
4953
.ToolBar(commands => commands.Insert())
50-
.ClientEvents(events => events.OnEdit("onProductManufacturerEdit"))
54+
.ClientEvents(events =>
55+
{
56+
events.OnEdit("onProductManufacturerEdit");
57+
events.OnDataBound("onProductManufacturerDataBound");
58+
})
5159
.EnableCustomBinding(true))
5260
}
5361
else

0 commit comments

Comments
 (0)