@model ProductDetailsModel
@using Nop.Core
@using Nop.Core.Domain.Catalog
@using Nop.Core.Domain.Media
@using System.Text
@using Nop.Services.Catalog
@using Nop.Services.Media
@inject IDownloadService downloadService
@inject CatalogSettings catalogSettings
@if (Model.ProductAttributes.Count > 0)
{
if (Model.AllowAddingOnlyExistingAttributeCombinations && catalogSettings.AttributeValueOutOfStockDisplayType == AttributeValueOutOfStockDisplayType.Disable)
{
}
//dynamic update support
var attributesHaveConditions = Model.ProductAttributes.Any(x => x.HasCondition);
var attributesHaveAssociatedPictures = Model.ProductAttributes.Any(x => x.ProductId > 0);
var attributeChangeScriptsBuilder = new StringBuilder();
var attributeChangeHandlerFuncName = $"attribute_change_handler_{Model.Id}";
if (catalogSettings.AjaxProcessAttributeChange)
{
if (Model.AllowAddingOnlyExistingAttributeCombinations && catalogSettings.AttributeValueOutOfStockDisplayType == AttributeValueOutOfStockDisplayType.Disable)
{
}
else
{
//generate change event script
foreach (var attribute in Model.ProductAttributes)
{
var controlId = $"{NopCatalogDefaults.ProductAttributePrefix}{attribute.Id}";
switch (attribute.AttributeControlType)
{
case AttributeControlType.DropdownList:
{
attributeChangeScriptsBuilder.AppendFormat("$('#{0}').on('change', function(){{{1}();}});\n", controlId, attributeChangeHandlerFuncName);
}
break;
case AttributeControlType.RadioList:
case AttributeControlType.ColorSquares:
case AttributeControlType.ImageSquares:
{
foreach (var attributeValue in attribute.Values)
{
attributeChangeScriptsBuilder.AppendFormat("$('#{0}_{1}').on('click', function(){{{2}();}});\n", controlId, attributeValue.Id, attributeChangeHandlerFuncName);
}
}
break;
case AttributeControlType.Checkboxes:
case AttributeControlType.ReadonlyCheckboxes:
{
foreach (var attributeValue in attribute.Values)
{
attributeChangeScriptsBuilder.AppendFormat("$('#{0}_{1}').on('click', function(){{{2}();}});\n", controlId, attributeValue.Id, attributeChangeHandlerFuncName);
}
}
break;
default:
break;
}
}
}
foreach (var attribute in Model.ProductAttributes)
{
foreach (var attributeValue in attribute.Values.Where(value => value.CustomerEntersQty))
{
var controlId = $"{NopCatalogDefaults.ProductAttributePrefix}{attribute.Id}";
attributeChangeScriptsBuilder.AppendFormat("$('#{0}_{1}_qty').on('input propertychange paste', function(){{{2}();}});\n", controlId, attributeValue.Id, attributeChangeHandlerFuncName);
}
}
//render scripts
//almost the same implementation is used in the \Views\Product\_RentalInfo.cshtml file
}
}