Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
@model ProductModel
@{
var area = ViewContext.RouteData.Values["area"]?.ToString();
//a product the store may see but not change (see BaseProductController.Edit)
bool readOnly = ViewBag.IsReadOnly == true;
}
<div class="grand-card">
<div class="grand-card__header">
<h2 class="grand-card__title"></h2>
@if (!readOnly)
{
<a id="btnAddNewAttributes" href="@(Url.Action("ProductAttributeMappingPopup", "Product", new { productId = Model.Id, area = area }))" class="btn btn-outline-secondary btn-sm"><i class="bi bi-plus-lg"></i> @Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.AddNew"]</a>
}
</div>
<partial name="Partials/WidgetZone.ProductAttributes.Top" model="Model"/>
<div class="grand-card__body grand-card__body--flush">
<admin-grid id="productattributemappings-grid"
read-only="@readOnly"
read-url="@Url.Action("ProductAttributeMappingList", "Product", new { productId = Model.Id, area = area })"
destroy-url="@Url.Action("ProductAttributeMappingDelete", "Product", new { area = area })"
pager="Compact"
auto-bind="false"
confirm-destroy="true"
on-data-bound="bindProductAttributeMappingPopups"
on-detail-init="@(readOnly ? null : "addProductAttributeValueButton")">
<grid-text name="validationRulesLink" value="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.ValidationRules.Link"]"/>
<grid-text name="edit" value="@Loc[$"{Scope.ResourceKeyPrefix}.Common.Edit"]"/>
<grid-column field="ProductAttributeId" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.Fields.Attribute"]" width="190">
<cell-template>
@if (readOnly)
{
<span>{{ ProductAttribute }}</span>
}
else
{
<a class="text-decoration-none btnMagnificPopup" href="@Url.Action("ProductAttributeMappingPopup", "Product", new { area = area })/?productId=@(Model.Id)&productAttributeMappingId={{ Id }}">{{ ProductAttribute }}<br/></a>
}
</cell-template>
</grid-column>
<grid-column field="TextPrompt" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.Fields.TextPrompt"]" width="120"/>
<grid-column field="IsRequired" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.Fields.IsRequired"]" width="50" align="Center">
<cell-template>
<i data-if="IsRequired" class="bi bi-check-lg" aria-hidden="true" style="color:green"></i>
<i data-else class="bi bi-x-lg" aria-hidden="true" style="color:red"></i>
</cell-template>
</grid-column>
<grid-column field="AttributeControlTypeId" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.Fields.AttributeControlType"]" width="140">
<cell-template>
{{ AttributeControlType }} <br/>
@*ValidationRulesString is markup the server builds (labels and encoded values joined with <br />)*@
@if (readOnly)
{
<span data-if="ValidationRulesAllowed">{{{ ValidationRulesString }}}</span>
}
else
{
<span data-if="ValidationRulesAllowed"><a class="btnMagnificPopup" href="@Url.Action("ProductAttributeValidationRulesPopup", "Product", new { area = area })/{{ Id }}?&productId=@(Model.Id)&btnId=btnRefreshProductAttributes&formId=product-form">{{ $texts.validationRulesLink }}</a><br/>{{{ ValidationRulesString }}}</span>
}
</cell-template>
</grid-column>
@if (!readOnly)
{
<grid-column field="ConditionAllowed" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.Condition"]" width="80">
<cell-template>
<span data-if="ConditionAllowed"><a class="btnMagnificPopup" href="@Url.Action("ProductAttributeConditionPopup", "Product", new { area = area })/?productId=@(Model.Id)&productAttributeMappingId={{ Id }}&btnId=btnRefreshProductAttributes&formId=product-form">{{ $texts.edit }}</a><br/></span>
</cell-template>
</grid-column>
}
@*attribute values: drop-down list, radio list, checkboxes, color and image squares; text controls have none*@
<grid-detail read-url="@Url.Action("ProductAttributeValueList", "Product", new { productId = Model.Id, area = area })"
destroy-url="@Url.Action("ProductAttributeValueDelete", "Product", new { productId = Model.Id, area = area })"
param="productAttributeMappingId:Id,pam:Id"
confirm-destroy="true"
visible-if="AttributeControlTypeId != 4 && AttributeControlTypeId != 10 && AttributeControlTypeId != 30"
on-data-bound="bindProductAttributeValuePopups">
<grid-column field="Name" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.Values.Fields.Name"]">
<cell-template>
@if (readOnly)
{
<span>{{ Name }}</span>
}
else
{
<a class="text-decoration-none btnProductAttributeValueEditPopup" data-id="{{ Id }}" onclick="this.classList.add('active')" href="@Url.Action("ProductAttributeValueEditPopup", "Product", new { area = area })/{{ Id }}?productId=@(Model.Id)&productAttributeMappingId={{ ProductAttributeMappingId }}&btnId=btnRefreshProductAttributesValues&formId=product-form">{{ Name }}</a>
}
</cell-template>
</grid-column>
<grid-commands destroy="true" title="@Loc[$"{Scope.ResourceKeyPrefix}.Common.Delete"]"/>
</grid-detail>
<grid-commands destroy="true" width="50"/>
</admin-grid>
</div>
<partial name="Partials/WidgetZone.ProductAttributes.Bottom" model="Model"/>
</div>
<script>
$(document).ready(function () {
$('#btnAddNewAttributes').magnificPopup({
type: 'ajax',
settings: { cache: false, async: false },
midClick: true,
callbacks: {
parseAjax: function (mfpResponse) {
mfpResponse.data = $('<div></div>').html(mfpResponse.data);
},
ajaxContentAdded: function () {
$('.mfp-wrap').removeAttr('tabindex');
}
}
});
});
function bindProductAttributeMappingPopups() {
$('.btnMagnificPopup').magnificPopup({
type: 'ajax',
settings: { cache: false, async: false },
midClick: true,
callbacks: {
parseAjax: function (mfpResponse) {
mfpResponse.data = $('<div></div>').html(mfpResponse.data);
},
ajaxContentAdded: function () {
$('.mfp-wrap').removeAttr('tabindex');
}
}
});
}
//the values grid of a mapping: data-id lets btnRefreshProductAttributesValues find it, and
//its "Add new" button opens the value popup for that mapping
function addProductAttributeValueButton(e) {
var mappingId = e.data.Id;
$(e.detailElement).attr('data-id', mappingId);
var button = $('<a class="btn btn-default btn-sm btnProductAttributeValueEditPopup" onclick="this.classList.add(\'active\')"></a>')
.attr('data-id', mappingId)
.attr('href', '@Url.Action("ProductAttributeValueCreatePopup", "Product", new { area = area })/?productAttributeMappingId=' + encodeURIComponent(mappingId) + '&[email protected]&formId=product-form&btnId=btnRefreshProductAttributesValues')
.html('@Loc[$"{Scope.ResourceKeyPrefix}.Common.AddNew"]');
$('<div class="grand-grid-toolbar"></div>').append(button).prependTo(e.detailElement);
}
function bindProductAttributeValuePopups() {
$('.btnProductAttributeValueEditPopup').magnificPopup({
type: 'ajax',
settings: { cache: false, async: false },
midClick: true,
callbacks: {
parseAjax: function (mfpResponse) {
mfpResponse.data = $('<div></div>').html(mfpResponse.data);
},
ajaxContentAdded: function () {
$('.mfp-wrap').removeAttr('tabindex');
$('.mfp-wrap').attr("data-id", $('.btnProductAttributeValueEditPopup.active').data("id"));
if (document.querySelector('.mfp-wrap').dataset.prodid !== undefined) {
var id = document.querySelector('.mfp-wrap').dataset.prodid;
var name = document.querySelector('.mfp-wrap').dataset.prodname;
$('#AttributeValueTypeId').val('10').change();
$('#AssociatedProductId').val(id);
$('#associate-product-name').html(name);
}
},
close: function () {
$('.mfp-wrap').removeAttr('data-prodid');
$('.mfp-wrap').removeAttr('data-prodname');
$('.btnProductAttributeValueEditPopup.active').removeClass('active');
$('#AttributeValueTypeId').val('0').change();
}
}
});
}
</script>
<input type="submit" id="btnRefreshProductAttributes" style="display: none"/>
<input type="button" id="btnRefreshProductAttributesValues" style="display: none"/>
<script>
$(document).ready(function () {
$('#btnRefreshProductAttributes').click(function () {
//refresh grid
var grid = GrandAdmin.grids.get("#productattributemappings-grid");
grid.dataSource.read();
//return false to don't reload a page
return false;
});
$('#btnRefreshProductAttributesValues').click(function (e) {
//refresh grid value
var dataid = $(this).attr("data-id");
var grid = GrandAdmin.grids.get('[data-id="' + dataid + '"]');
grid.dataSource.read();
//return false to don't reload a page
return false;
});
});
</script>