Skip to content

Commit 1fc0835

Browse files
committed
Resolves smartstore#553 Option to set a delivery time for products available for order with stock quantity < 1
1 parent e68bafd commit 1fc0835

12 files changed

Lines changed: 94 additions & 22 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* (Developer) Implemented new HtmlHelper extension `AddCustomHeadParts`: registers whatever head (meta) tag you wish
99
* (Developer) Added `SmartUrlRoutingModule`, which can pass static files to `UrlRoutingModule` if desired (e.g. used by MiniProfiler). This way static files can be handled by regular actions or filters, without polluting web.config.
1010
* New payment plugin "Payone"
11+
* Option to set a delivery time for products available for order with stock quantity < 1
1112

1213
### Improvements
1314
* (Perf) Faster application warmup

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public CatalogSettings()
4242
MaximumBackInStockSubscriptions = 200;
4343
FileUploadMaximumSizeBytes = 1024 * 200; //200KB
4444
ManufacturersBlockItemsToDisplay = 5;
45-
DisplayAllImagesNumber = 6; // codehint: sm-add
45+
DisplayAllImagesNumber = 6;
4646
ShowColorSquaresInLists = true;
4747
ShowDiscountSign = true;
4848
ShowVariantCombinationPriceAdjustment = true;
@@ -156,7 +156,6 @@ public CatalogSettings()
156156
/// </summary>
157157
public string PageShareCode { get; set; }
158158

159-
/// codehint: sm-add
160159
/// <summary>
161160
/// Gets or sets a value indicating whether to display reviews in product lists
162161
/// </summary>
@@ -297,7 +296,6 @@ public CatalogSettings()
297296
/// </summary>
298297
public string ProductsByTagPageSizeOptions { get; set; }
299298

300-
//codehint: sm-add begin
301299
public int ProductSearchPageSize { get; set; }
302300

303301
public bool ProductSearchAllowCustomersToSelectPageSize { get; set; }
@@ -322,8 +320,6 @@ public CatalogSettings()
322320

323321
public bool SuppressSkuSearch { get; set; }
324322

325-
//codehint: sm-add end
326-
327323
/// <summary>
328324
/// Gets or sets the available customer selectable default page size options
329325
/// </summary>
@@ -405,5 +401,10 @@ public CatalogSettings()
405401
/// Gets or sets the height of collapsed text
406402
/// </summary>
407403
public int HtmlTextCollapsedHeight { get; set; }
404+
405+
/// <summary>
406+
/// Gets or sets an identifier for a delivery time dislayed when stock is empty
407+
/// </summary>
408+
public int? DeliveryTimeIdForEmptyStock { get; set; }
408409
}
409410
}

src/Libraries/SmartStore.Data/Migrations/201412081934318_V211.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ The details have been sent to our support team and we will investigate the issue
113113
builder.AddOrUpdate("Checkout.ConfirmHint",
114114
"Please verify the order total and the specifics regarding the billing address and, if required, the shipping address. You can make corrections to your entry anytime by clicking on <strong>back</strong>. If everything's as it should be, deliver your order to us by clicking <strong>confirm</strong>.",
115115
"Bitte prüfen Sie die Gesamtsumme und die Rechnungsadresse. Bei abweichender Lieferanschrift prüfen Sie bitte auch diese. Änderungen können Sie jederzeit mit einem Klick auf <strong>zurück</strong> vornehmen. Sind alle Daten richtig, bestätigen Sie bitte mit einem Klick auf <strong>kaufen</strong> Ihre Bestellung.");
116+
117+
// new setting
118+
builder.AddOrUpdate("Admin.Configuration.Settings.Catalog.DeliveryTimeIdForEmptyStock",
119+
"Delivery time dislayed when stock is empty",
120+
"Lieferzeit, die bei einem leerem Lagerbestand angezeigt wird",
121+
"Delivery time to be dislayed when the stock quantity of a product is equal or less 0.",
122+
"Lieferzeit, die angezeigt wird, wenn der Warenbestand des Produktes kleiner gleich 0 ist.");
116123
}
117124
}
118125
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,16 @@ public static string FormatStockMessage(this Product product, ILocalizationServi
215215
/// <param name="product">Product</param>
216216
/// <param name="localizationService">Localization service</param>
217217
/// <returns>The stock message</returns>
218-
public static bool DisplayDeliveryTimeAccordingToStock(this Product product)
218+
public static bool DisplayDeliveryTimeAccordingToStock(this Product product, CatalogSettings catalogSettings)
219219
{
220220
if (product == null)
221221
throw new ArgumentNullException("product");
222222

223223
if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock || product.ManageInventoryMethod == ManageInventoryMethod.ManageStockByAttributes)
224224
{
225+
if (catalogSettings.DeliveryTimeIdForEmptyStock.HasValue && product.StockQuantity <= 0)
226+
return true;
227+
225228
return (product.StockQuantity > 0);
226229
}
227230
return true;

src/Libraries/SmartStore.Services/Directory/DeliveryTimeService.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using SmartStore.Core;
54
using SmartStore.Core.Caching;
65
using SmartStore.Core.Data;
6+
using SmartStore.Core.Domain.Catalog;
77
using SmartStore.Core.Domain.Directory;
88
using SmartStore.Core.Events;
99
using SmartStore.Core.Plugins;
1010
using SmartStore.Services.Customers;
11-
using SmartStore.Core.Domain.Catalog;
1211

1312
namespace SmartStore.Services.Directory
1413
{
@@ -29,9 +28,9 @@ public partial class DeliveryTimeService : IDeliveryTimeService
2928
private readonly IRepository<ProductVariantAttributeCombination> _attributeCombinationRepository;
3029
private readonly ICacheManager _cacheManager;
3130
private readonly ICustomerService _customerService;
32-
//private readonly CurrencySettings _currencySettings;
3331
private readonly IPluginFinder _pluginFinder;
3432
private readonly IEventPublisher _eventPublisher;
33+
private readonly CatalogSettings _catalogSettings;
3534

3635
#endregion
3736

@@ -52,16 +51,17 @@ public DeliveryTimeService(ICacheManager cacheManager,
5251
IRepository<ProductVariantAttributeCombination> attributeCombinationRepository,
5352
ICustomerService customerService,
5453
IPluginFinder pluginFinder,
55-
IEventPublisher eventPublisher)
54+
IEventPublisher eventPublisher,
55+
CatalogSettings catalogSettings)
5656
{
5757
this._cacheManager = cacheManager;
5858
this._deliveryTimeRepository = deliveryTimeRepository;
5959
this._customerService = customerService;
60-
//this._currencySettings = currencySettings;
6160
this._pluginFinder = pluginFinder;
6261
this._eventPublisher = eventPublisher;
6362
this._productRepository = productRepository;
6463
this._attributeCombinationRepository = attributeCombinationRepository;
64+
this._catalogSettings = catalogSettings;
6565
}
6666

6767
#endregion
@@ -114,6 +114,25 @@ public virtual DeliveryTime GetDeliveryTimeById(int deliveryTimeId)
114114
return _deliveryTimeRepository.GetById(deliveryTimeId);
115115
}
116116

117+
/// <summary>
118+
/// Gets the delivery time for a product
119+
/// </summary>
120+
/// <param name="product">The product</param>
121+
/// <returns>Delivery time</returns>
122+
public virtual DeliveryTime GetDeliveryTime(Product product)
123+
{
124+
if (product == null)
125+
return null;
126+
127+
if ((product.ManageInventoryMethod == ManageInventoryMethod.ManageStock || product.ManageInventoryMethod == ManageInventoryMethod.ManageStockByAttributes)
128+
&& _catalogSettings.DeliveryTimeIdForEmptyStock.HasValue && product.StockQuantity <= 0)
129+
{
130+
return GetDeliveryTimeById(_catalogSettings.DeliveryTimeIdForEmptyStock.Value);
131+
}
132+
133+
return GetDeliveryTimeById(product.DeliveryTimeId ?? 0);
134+
}
135+
117136
/// <summary>
118137
/// Gets all delivery times
119138
/// </summary>

src/Libraries/SmartStore.Services/Directory/IDeliveryTimeService.cs

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

45
namespace SmartStore.Services.Directory
@@ -27,6 +28,13 @@ public partial interface IDeliveryTimeService
2728
/// <returns>DeliveryTime</returns>
2829
DeliveryTime GetDeliveryTimeById(int deliveryTimeId);
2930

31+
/// <summary>
32+
/// Gets the delivery time for a product
33+
/// </summary>
34+
/// <param name="product">The product</param>
35+
/// <returns>Delivery time</returns>
36+
DeliveryTime GetDeliveryTime(Product product);
37+
3038
/// <summary>
3139
/// Gets all delivery times
3240
/// </summary>

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public partial class SettingController : AdminControllerBase
7070
private readonly IGenericAttributeService _genericAttributeService;
7171
private readonly ILocalizedEntityService _localizedEntityService;
7272
private readonly ILanguageService _languageService;
73+
private readonly IDeliveryTimeService _deliveryTimesService;
7374

7475
private StoreDependingSettingHelper _storeDependingSettings;
7576

@@ -89,7 +90,8 @@ public SettingController(ISettingService settingService,
8990
IMaintenanceService maintenanceService, IStoreService storeService,
9091
IWorkContext workContext, IGenericAttributeService genericAttributeService,
9192
ILocalizedEntityService localizedEntityService,
92-
ILanguageService languageService)
93+
ILanguageService languageService,
94+
IDeliveryTimeService deliveryTimesService)
9395
{
9496
this._settingService = settingService;
9597
this._countryService = countryService;
@@ -114,6 +116,7 @@ public SettingController(ISettingService settingService,
114116
this._genericAttributeService = genericAttributeService;
115117
this._localizedEntityService = localizedEntityService;
116118
this._languageService = languageService;
119+
this._deliveryTimesService = deliveryTimesService;
117120
}
118121

119122
#endregion 
@@ -570,6 +573,17 @@ public ActionResult Catalog()
570573
new SelectListItem { Value = "list", Text = _localizationService.GetResource("Common.List"), Selected = model.DefaultViewMode.IsCaseInsensitiveEqual("list") }
571574
);
572575

576+
var deliveryTimes = _deliveryTimesService.GetAllDeliveryTimes();
577+
foreach (var dt in deliveryTimes)
578+
{
579+
model.AvailableDeliveryTimes.Add(new SelectListItem()
580+
{
581+
Text = dt.Name,
582+
Value = dt.Id.ToString(),
583+
Selected = dt.Id == catalogSettings.DeliveryTimeIdForEmptyStock
584+
});
585+
}
586+
573587
return View(model);
574588
}
575589
[HttpPost]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ public void Execute()
584584
.ForMember(dest => dest.ActiveShippingRateComputationMethodSystemNames, mo => mo.Ignore())
585585
.ForMember(dest => dest.ReturnValidOptionsIfThereAreAny, mo => mo.Ignore());
586586
Mapper.CreateMap<CatalogSettings, CatalogSettingsModel>()
587-
.ForMember(dest => dest.AvailableDefaultViewModes, mo => mo.Ignore());
587+
.ForMember(dest => dest.AvailableDefaultViewModes, mo => mo.Ignore())
588+
.ForMember(dest => dest.AvailableDeliveryTimes, mo => mo.Ignore());
588589
Mapper.CreateMap<CatalogSettingsModel, CatalogSettings>()
589590
.ForMember(dest => dest.PageShareCode, mo => mo.Ignore())
590591
.ForMember(dest => dest.DefaultProductRatingValue, mo => mo.Ignore())

src/Presentation/SmartStore.Web/Administration/Models/Settings/CatalogSettingsModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class CatalogSettingsModel
99
public CatalogSettingsModel()
1010
{
1111
this.AvailableDefaultViewModes = new List<SelectListItem>();
12+
this.AvailableDeliveryTimes = new List<SelectListItem>();
1213
}
1314

1415
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.ShowProductSku")]
@@ -200,6 +201,10 @@ public CatalogSettingsModel()
200201
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.SuppressSkuSearch")]
201202
public bool SuppressSkuSearch { get; set; }
202203

204+
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.DeliveryTimeIdForEmptyStock")]
205+
public int? DeliveryTimeIdForEmptyStock { get; set; }
206+
203207
public IList<SelectListItem> AvailableDefaultViewModes { get; private set; }
208+
public IList<SelectListItem> AvailableDeliveryTimes { get; private set; }
204209
}
205210
}

src/Presentation/SmartStore.Web/Administration/Views/Setting/Catalog.cshtml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@
613613
@Html.ValidationMessageFor(model => model.ProductsAlsoPurchasedNumber)
614614
</td>
615615
</tr>
616-
@*codehint: sm-add*@
617616
<tr>
618617
<td class="adminTitle">
619618
@Html.SmartLabelFor(model => model.DisplayAllImagesNumber)
@@ -632,6 +631,16 @@
632631
@Html.ValidationMessageFor(model => model.ShowDeliveryTimesInProductDetail)
633632
</td>
634633
</tr>
634+
<tr>
635+
<td class="adminTitle">
636+
@Html.SmartLabelFor(model => model.DeliveryTimeIdForEmptyStock)
637+
</td>
638+
<td class="adminData">
639+
@Html.SettingOverrideCheckbox(model => model.DeliveryTimeIdForEmptyStock)
640+
@Html.DropDownListFor(model => model.DeliveryTimeIdForEmptyStock, Model.AvailableDeliveryTimes, T("Common.Unspecified"))
641+
@Html.ValidationMessageFor(model => model.DeliveryTimeIdForEmptyStock)
642+
</td>
643+
</tr>
635644
<tr>
636645
<td class="adminTitle">
637646
@Html.SmartLabelFor(model => model.EnableDynamicPriceUpdate)

0 commit comments

Comments
 (0)