Skip to content

Commit f25dcd7

Browse files
committed
Selecting an attribute of type date caused an error on the product detail page
1 parent 388308f commit f25dcd7

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/Libraries/SmartStore.Services/Catalog/Modelling/ProductVariantQueryFactory.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ protected Multimap<string, string> QueryItems
4141
if (_httpContext.Request?.Unvalidated != null)
4242
{
4343
var form = _httpContext.Request.Unvalidated.Form;
44-
4544
if (form != null)
4645
{
4746
foreach (var key in form.AllKeys)
@@ -54,7 +53,6 @@ protected Multimap<string, string> QueryItems
5453
}
5554

5655
var query = _httpContext.Request.Unvalidated.QueryString;
57-
5856
if (query != null)
5957
{
6058
foreach (var key in query.AllKeys)
@@ -141,8 +139,18 @@ public ProductVariantQuery CreateFromQuery()
141139
// Convert from three form controls.
142140
var dateKey = key.Replace("-year", "");
143141
year = value.ToInt();
144-
month = QueryItems[dateKey + "-month"].FirstOrDefault()?.ToInt() ?? 0;
145-
day = QueryItems[dateKey + "-day"].FirstOrDefault()?.ToInt() ?? 0;
142+
143+
if (QueryItems.ContainsKey(dateKey + "-month"))
144+
{
145+
var str = QueryItems[dateKey + "-month"].FirstOrDefault();
146+
month = str?.ToInt() ?? 0;
147+
}
148+
149+
if (QueryItems.ContainsKey(dateKey + "-day"))
150+
{
151+
var str = QueryItems[dateKey + "-day"].FirstOrDefault();
152+
day = str?.ToInt() ?? 0;
153+
}
146154
}
147155

148156
if (year > 0 && month > 0 && day > 0)

src/Presentation/SmartStore.Web/Scripts/public.product.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
var ctx = inputCtrl.closest('.update-container');
2525
var isTouchSpin = inputCtrl.parent(".bootstrap-touchspin").length > 0;
2626
var isFileUpload = inputCtrl.data("fileupload");
27+
var isDateTime = inputCtrl.hasClass("date-part");
2728

2829
if (ctx.length === 0) {
2930
// It's an associated or bundled item.
@@ -33,14 +34,14 @@
3334
ctx.doAjax({
3435
data: ctx.find(':input').serialize(),
3536
callbackSuccess: function (response) {
36-
self.updateDetailData(response, ctx, isTouchSpin, isFileUpload);
37+
self.updateDetailData(response, ctx, isTouchSpin, isFileUpload, isDateTime);
3738

3839
if (ctx.hasClass('pd-bundle-item')) {
3940
// Update bundle price too.
4041
$('#main-update-container').doAjax({
4142
data: $('.pd-bundle-items').find(':input').serialize(),
4243
callbackSuccess: function (response2) {
43-
self.updateDetailData(response2, $('#main-update-container'), isTouchSpin, isFileUpload);
44+
self.updateDetailData(response2, $('#main-update-container'), isTouchSpin, isFileUpload, isDateTime);
4445
}
4546
});
4647
}
@@ -51,7 +52,7 @@
5152
return this;
5253
};
5354

54-
this.updateDetailData = function (data, ctx, isTouchSpin, isFileUpload) {
55+
this.updateDetailData = function (data, ctx, isTouchSpin, isFileUpload, isDateTime) {
5556
var gallery = $('#pd-gallery').data(galPluginName);
5657

5758
// Image gallery needs special treatment
@@ -73,7 +74,8 @@
7374
// Iterate all elems with [data-partial] attribute...
7475
var $el = $(el);
7576
var partial = $el.data('partial');
76-
if (partial && !(isTouchSpin && partial === 'OfferActions')) {
77+
78+
if (partial && !(isTouchSpin && partial === 'OfferActions') && !(isDateTime && partial === 'Variants')) {
7779
// ...fetch the updated html from the corresponding AJAX result object's properties
7880
if (data.Partials && data.Partials.hasOwnProperty(partial)) {
7981
if (partial === 'Variants') {

0 commit comments

Comments
 (0)