Skip to content

Commit

Permalink
smartstore#1244 Product variant query factory supporting text values
Browse files Browse the repository at this point in the history
  • Loading branch information
mgesing committed Sep 26, 2017
1 parent e3ab08c commit 5cabb04
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 48 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Release Notes
# Release Notes

## SmartStore.NET 3.1.0
### Bugfixes
* #1268 Data importer always inserts new pictures and does not detect equal pictures while importing
* OutputCache computes ambigous cache keys for blog pages
* #1142 Customer import creates role multiple times
* #1244 Variant query model binder cannot handle types text and datepicker

### Improvements
* #1141 Clearer backend order list. Added more infos like payment method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ protected virtual string ToQueryString(ProductVariantQuery query)
{
qs.Add(name + "-date", string.Join("-", item.Date.Value.Year, item.Date.Value.Month, item.Date.Value.Day));
}
else if (item.IsFile)
{
qs.Add(name + "-file", item.Value);
}
else if (item.IsText)
{
qs.Add(name + "-text", item.Value);
}
else
{
if (item.ValueAlias.IsEmpty())
Expand Down Expand Up @@ -145,9 +153,9 @@ public virtual void DeserializeQuery(ProductVariantQuery query, int productId, s

foreach (var value in values)
{
DateTime? date = null;
string newValue = null;
string valueAlias = null;
DateTime? date = null;

switch (attribute.AttributeControlType)
{
Expand All @@ -158,11 +166,9 @@ public virtual void DeserializeQuery(ProductVariantQuery query, int productId, s
newValue = string.Join("-", date.Value.Year, date.Value.Month, date.Value.Day);
}
break;
case AttributeControlType.FileUpload:
case AttributeControlType.TextBox:
case AttributeControlType.MultilineTextbox:
// TODO
break;
case AttributeControlType.FileUpload:
newValue = value;
break;
default:
Expand All @@ -184,7 +190,9 @@ public virtual void DeserializeQuery(ProductVariantQuery query, int productId, s
VariantAttributeId = attribute.Id,
Alias = attribute.ProductAttribute.Alias,
ValueAlias = valueAlias,
Date = date
Date = date,
IsFile = attribute.AttributeControlType == AttributeControlType.FileUpload,
IsText = attribute.AttributeControlType == AttributeControlType.TextBox || attribute.AttributeControlType == AttributeControlType.MultilineTextbox
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,99 +106,128 @@ protected Multimap<string, string> QueryItems
return null;
}

protected virtual void ConvertVariant(ProductVariantQuery query, string key, string value)
protected virtual void ConvertVariant(ProductVariantQuery query, string key, ICollection<string> values)
{
if (key.EndsWith("-day") || key.EndsWith("-month"))
var ids = key.Replace("pvari", "").SplitSafe("-");
if (ids.Length < 4)
return;

var ids = key.Replace("pvari", "").SplitSafe("-");
if (ids.Length > 3)
var isDate = key.EndsWith("-date") || key.EndsWith("-year");
var isFile = key.EndsWith("-file");
var isText = key.EndsWith("-text");

if (isDate || isFile || isText)
{
var value = isText ? string.Join(",", values) : values.First();
var variant = new ProductVariantQueryItem(value);
variant.ProductId = ids[0].ToInt();
variant.BundleItemId = ids[1].ToInt();
variant.AttributeId = ids[2].ToInt();
variant.VariantAttributeId = ids[3].ToInt();
variant.IsFile = isFile;
variant.IsText = isText;

if (key.EndsWith("-date") || key.EndsWith("-year"))
if (isDate)
{
variant.Date = ConvertToDate(key, value);
}

query.AddVariant(variant);
}
else
{
foreach (var value in values)
{
var variant = new ProductVariantQueryItem(value);
variant.ProductId = ids[0].ToInt();
variant.BundleItemId = ids[1].ToInt();
variant.AttributeId = ids[2].ToInt();
variant.VariantAttributeId = ids[3].ToInt();

query.AddVariant(variant);
}
}
}

protected virtual bool ConvertVariantAlias(ProductVariantQuery query, string key, ICollection<string> values, int languageId)
protected virtual void ConvertVariantAlias(ProductVariantQuery query, string key, ICollection<string> values, int languageId)
{
if (values.Count == 0 || key.EndsWith("-day") || key.EndsWith("-month"))
return false;

var isDate = key.EndsWith("-date") || key.EndsWith("-year");
var isFile = key.EndsWith("-file");
var ids = key.SplitSafe("-");
var len = ids.Length;
if (len < 4)
return false;
return;

var isDate = key.EndsWith("-date") || key.EndsWith("-year");
var isFile = key.EndsWith("-file");
var isText = key.EndsWith("-text");

if (isDate || isFile)
if (isDate || isFile || isText)
{
ids = ids.Take(len - 1).ToArray();
len = ids.Length;
}

var alias = string.Join("-", ids.Take(len - 3));

var attributeId = _catalogSearchQueryAliasMapper.GetVariantIdByAlias(alias, languageId);
if (attributeId == 0)
return false;
return;

var productId = ids.SafeGet(len - 3).ToInt();
var bundleItemId = ids.SafeGet(len - 2).ToInt();
var variantAttributeId = ids.SafeGet(len - 1).ToInt();

if (productId == 0 || variantAttributeId == 0)
return false;
return;

foreach (var value in values)
if (isDate || isFile || isText)
{
// We cannot use GetVariantOptionIdByAlias. It doesn't necessarily provide a ProductVariantAttributeValue.Id associated with this product.
//var optionId = _catalogSearchQueryAliasMapper.GetVariantOptionIdByAlias(value, attributeId, languageId);
var optionId = 0;
string valueAlias = null;
DateTime? date = null;
var value = isText ? string.Join(",", values) : values.First();
var variant = new ProductVariantQueryItem(value);
variant.ProductId = productId;
variant.BundleItemId = bundleItemId;
variant.AttributeId = attributeId;
variant.VariantAttributeId = variantAttributeId;
variant.Alias = alias;
variant.IsFile = isFile;
variant.IsText = isText;

if (isDate)
{
date = ConvertToDate(key, value);
variant.Date = ConvertToDate(key, value);
}
else

query.AddVariant(variant);
}
else
{
foreach (var value in values)
{
// We cannot use GetVariantOptionIdByAlias. It doesn't necessarily provide a ProductVariantAttributeValue.Id associated with this product.
//var optionId = _catalogSearchQueryAliasMapper.GetVariantOptionIdByAlias(value, attributeId, languageId);
var optionId = 0;
string valueAlias = null;

var valueIds = value.SplitSafe("-");
if (valueIds.Length >= 2)
{
optionId = valueIds.SafeGet(valueIds.Length - 1).ToInt();
valueAlias = string.Join("-", valueIds.Take(valueIds.Length - 1));
}
}

var variant = new ProductVariantQueryItem(optionId == 0 ? value : optionId.ToString());
variant.ProductId = productId;
variant.BundleItemId = bundleItemId;
variant.AttributeId = attributeId;
variant.VariantAttributeId = variantAttributeId;
variant.Alias = alias;
variant.Date = date;
var variant = new ProductVariantQueryItem(optionId == 0 ? value : optionId.ToString());
variant.ProductId = productId;
variant.BundleItemId = bundleItemId;
variant.AttributeId = attributeId;
variant.VariantAttributeId = variantAttributeId;
variant.Alias = alias;

if (optionId != 0)
{
variant.ValueAlias = valueAlias;
}
if (optionId != 0)
{
variant.ValueAlias = valueAlias;
}

query.AddVariant(variant);
query.AddVariant(variant);
}
}

return true;
}

protected virtual void ConvertGiftCard(ProductVariantQuery query, string key, string value)
Expand Down Expand Up @@ -251,9 +280,14 @@ public ProductVariantQuery CreateFromQuery()

foreach (var item in QueryItems)
{
if (!item.Value.Any() || item.Key.EndsWith("-day") || item.Key.EndsWith("-month"))
{
continue;
}

if (IsVariantKey.IsMatch(item.Key))
{
item.Value.Each(value => ConvertVariant(query, item.Key, value));
ConvertVariant(query, item.Key, item.Value);
}
else if (IsGiftCardKey.IsMatch(item.Key))
{
Expand All @@ -263,8 +297,9 @@ public ProductVariantQuery CreateFromQuery()
{
item.Value.Each(value => ConvertCheckoutAttribute(query, item.Key, value));
}
else if (IsVariantAliasKey.IsMatch(item.Key) && ConvertVariantAlias(query, item.Key, item.Value, languageId))
else if (IsVariantAliasKey.IsMatch(item.Key))
{
ConvertVariantAlias(query, item.Key, item.Value, languageId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static string CreateKey(int productId, int bundleItemId, int attributeId,
public int AttributeId { get; set; }
public int VariantAttributeId { get; set; }
public DateTime? Date { get; set; }
public bool IsFile { get; set; }
public bool IsText { get; set; }

public string Alias { get; set; }
public string ValueAlias { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ private bool IsPropertyModified(HookedEntity entry, string propertyName)
result = prop.OriginalValue != null;
break;
default:
result = prop.CurrentValue != null && !prop.CurrentValue.Equals(prop.OriginalValue);
result =
(prop.CurrentValue != null && !prop.CurrentValue.Equals(prop.OriginalValue)) ||
(prop.OriginalValue != null && !prop.OriginalValue.Equals(prop.CurrentValue));
break;
}
}
Expand Down

0 comments on commit 5cabb04

Please sign in to comment.