Skip to content

Commit

Permalink
Hidden attribute options (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgesing committed Oct 2, 2020
1 parent 427307f commit 5b0329b
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,12 @@ können aber nicht bearbeitet werden. Die Texte dieser Informationen können üb
"Nicht verfügbare Attribut-Kombinationen ausblenden",
"Specifies whether to hide unavailable attribute combinations on product detail pages. By default, they are disabled.",
"Legt fest, ob nicht verfügbare Attribut-Kombinationen auf Produktdetailseiten ausgeblendet werden sollen. Standardmäßig werden sie deaktiviert.");

builder.AddOrUpdate("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Fields.CustomData",
"Custom data",
"Benutzerdefinierte Daten",
"Specifies user-defined data. For free usage, e.g. for individual shop extensions.",
"Legt benutzerdefinierte Daten fest. Zur freien Verwendung, z.B. bei individuellen Shop-Erweiterungen.");

#region Media

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ protected ChoiceModel()

public string TextPrompt { get; set; }

public string CustomData { get; set; }

public bool IsRequired { get; set; }

public bool IsDisabled { get; set; }

public bool IsHidden { get; set; }
//public bool IsHidden { get; set; }

/// <summary>
/// Allowed file extensions for customer uploaded files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2864,6 +2864,7 @@ public ActionResult ProductVariantAttributeList(GridCommand command, int product
ProductAttribute = _productAttributeService.GetProductAttributeById(x.ProductAttributeId).Name,
ProductAttributeId = x.ProductAttributeId,
TextPrompt = x.TextPrompt,
CustomData = x.CustomData,
IsRequired = x.IsRequired,
AttributeControlType = x.AttributeControlType.GetLocalizedEnum(_localizationService, _workContext),
AttributeControlTypeId = x.AttributeControlTypeId,
Expand Down Expand Up @@ -2907,6 +2908,7 @@ public ActionResult ProductVariantAttributeInsert(GridCommand command, ProductMo
// Use ProductAttribute property (not ProductAttributeId) because appropriate property is stored in it.
ProductAttributeId = int.Parse(model.ProductAttribute),
TextPrompt = model.TextPrompt,
CustomData = model.CustomData,
IsRequired = model.IsRequired,
// Use AttributeControlType property (not AttributeControlTypeId) because appropriate property is stored in it.
AttributeControlTypeId = int.Parse(model.AttributeControlType),
Expand Down Expand Up @@ -2934,6 +2936,7 @@ public ActionResult ProductVariantAttributeUpdate(GridCommand command, ProductMo
// Use ProductAttribute property (not ProductAttributeId) because appropriate property is stored in it.
pva.ProductAttributeId = int.Parse(model.ProductAttribute);
pva.TextPrompt = model.TextPrompt;
pva.CustomData = model.CustomData;
pva.IsRequired = model.IsRequired;
// Use AttributeControlType property (not AttributeControlTypeId) because appropriate property is stored in it.
pva.AttributeControlTypeId = int.Parse(model.AttributeControlType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ public class TierPriceModel : EntityModelBase
public class ProductVariantAttributeModel : EntityModelBase
{
public int ProductId { get; set; }

public int ProductAttributeId { get; set; }

[SmartResourceDisplayName("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Fields.Attribute")]
Expand All @@ -645,6 +644,10 @@ public class ProductVariantAttributeModel : EntityModelBase
[AllowHtml]
public string TextPrompt { get; set; }

[SmartResourceDisplayName("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Fields.CustomData")]
[AllowHtml]
public string CustomData { get; set; }

[SmartResourceDisplayName("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Fields.IsRequired")]
public bool IsRequired { get; set; }

Expand All @@ -653,9 +656,9 @@ public class ProductVariantAttributeModel : EntityModelBase
public string AttributeControlType { get; set; }
public int AttributeControlTypeId { get; set; }

//we don't name it DisplayOrder because Telerik has a small bug
//"if we have one more editor with the same name on a page, it doesn't allow editing"
//in our case it's category.DisplayOrder
// We don't name it DisplayOrder because Telerik has a small bug
// "if we have one more editor with the same name on a page, it doesn't allow editing"
// in our case it's category.DisplayOrder.
[SmartResourceDisplayName("Common.DisplayOrder")]
public int DisplayOrder1 { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,16 @@
.Columns(columns =>
{
columns.Bound(x => x.ProductAttribute)
.Width("16%");
columns.Bound(x => x.AttributeControlType)
.Width("16%");
columns.Bound(x => x.TextPrompt)
.Width("16%");
.Width("15%");
columns.Bound(x => x.AttributeControlType);
columns.Bound(x => x.TextPrompt);
columns.Bound(x => x.CustomData);
columns.Bound(x => x.IsRequired)
.Width("10%")
.ClientTemplate(@Html.SymbolForBool("IsRequired"))
.ClientTemplate(Html.SymbolForBool("IsRequired"))
.Centered();
columns.Bound(x => x.DisplayOrder1)
.Width("10%")
.Centered();
columns.Bound(x => x.ViewEditUrl)
.Width("16%")
.ClientTemplate(
"<a id='EditOptionsLink<#= Id #>' href='<#= ViewEditUrl #>' class='text-truncate'><#= ViewEditText #></a>" +
"<div id='OptionsSetsContainer<#= Id #>' style='display:none'><select class='form-control' id='OptionsSetsChoice<#= Id #>' data-valcount='<#= ValueCount #>'><#= OptionsSets #></select></div>"
Expand All @@ -91,7 +87,7 @@
commands.Edit().Localize(T);
commands.Delete().Localize(T);
})
.Width("20%")
.Width("15%")
.HtmlAttributes(new { align = "right" });
})
.ToolBar(commands => commands.Insert() )
Expand Down
42 changes: 23 additions & 19 deletions src/Presentation/SmartStore.Web/Controllers/CatalogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ public ProductDetailsModel PrepareProductDetailModel(
Name = attribute.ProductAttribute.GetLocalized(x => x.Name),
Description = attribute.ProductAttribute.GetLocalized(x => x.Description),
TextPrompt = attribute.TextPrompt,
CustomData = attribute.CustomData,
IsRequired = attribute.IsRequired,
AttributeControlType = attribute.AttributeControlType,
AllowedFileExtensions = _catalogSettings.FileUploadAllowedExtensions
Expand Down Expand Up @@ -1032,7 +1033,7 @@ public ProductDetailsModel PrepareProductDetailModel(
foreach (var attribute in model.ProductVariantAttributes)
{
var updatePreSelection = selectedValueIds.Any() && selectedValueIds.Intersect(attribute.Values.Select(x => x.Id)).Any();
var hideAttribute = true;
//var hideAttribute = true;

foreach (ProductDetailsModel.ProductVariantAttributeValueModel value in attribute.Values)
{
Expand All @@ -1058,30 +1059,33 @@ public ProductDetailsModel PrepareProductDetailModel(
value.IsDisabled = true;
value.IsHidden = product.HideUnavailableAttributes;

// Set title attribute for unavailable option.
if (product.DisplayStockAvailability && availabilityInfo.IsOutOfStock && availabilityInfo.IsActive)
if (!value.IsHidden)
{
value.Title = product.BackorderMode == BackorderMode.NoBackorders || product.BackorderMode == BackorderMode.AllowQtyBelow0
? res["Products.Availability.OutOfStock"]
: res["Products.Availability.Backordering"];
}
else
{
value.Title = res["Products.Availability.IsNotActive"];
// Set title attribute for unavailable option.
if (product.DisplayStockAvailability && availabilityInfo.IsOutOfStock && availabilityInfo.IsActive)
{
value.Title = product.BackorderMode == BackorderMode.NoBackorders || product.BackorderMode == BackorderMode.AllowQtyBelow0
? res["Products.Availability.OutOfStock"]
: res["Products.Availability.Backordering"];
}
else
{
value.Title = res["Products.Availability.IsNotActive"];
}
}
}

if (!value.IsDisabled && !value.IsHidden)
{
hideAttribute = false;
}
//if (!value.IsDisabled && !value.IsHidden)
//{
// hideAttribute = false;
//}
}

if (hideAttribute)
{
attribute.IsHidden = true;
attribute.IsRequired = false;
}
//if (hideAttribute)
//{
// attribute.IsHidden = true;
// attribute.IsRequired = false;
//}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@{
var controlId = Model.BuildControlId();
var items = Model.Values ?? new List<ChoiceItemModel>();
var items = Model.Values.Where(x => !x.IsHidden) ?? Enumerable.Empty<ChoiceItemModel>();
}

<div class="choice-boxes" id="[email protected]">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@{
var controlId = Model.BuildControlId();
var items = Model.Values ?? new List<ChoiceItemModel>();
var items = Model.Values.Where(x => !x.IsHidden) ?? Enumerable.Empty<ChoiceItemModel>();
var type = Model.AttributeControlType == AttributeControlType.Checkboxes ? "checkbox" : "radio";
// TODO: (mc) Replace .checkbox with .form-check
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

@{
var controlId = Model.BuildControlId();
var items = Model.Values ?? new List<ChoiceItemModel>();
var items = Model.Values.Where(x => !x.IsHidden) ?? Enumerable.Empty<ChoiceItemModel>();
}

<select id="@controlId" name="@controlId" class="form-control" @Html.Attr("disabled", "disabled", Model.IsDisabled)>
@if (!Model.IsRequired)
{
<option>@T("Common.Unspecified")</option>
}
else if (items.Count > 0 && !items.Any(x => x.IsPreSelected))
else if (items.Any() && !items.Any(x => x.IsPreSelected))
{
<option>@T("Common.PleaseSelect")</option>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@{
var controlId = Model.BuildControlId();
var items = Model.Values ?? new List<ChoiceItemModel>();
var items = Model.Values.Where(x => !x.IsHidden) ?? Enumerable.Empty<ChoiceItemModel>();

// TODO: (mc) Replace .radio with .form-radio
}
Expand Down

0 comments on commit 5b0329b

Please sign in to comment.