Skip to content

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.

10.5 KB
Raw Blame
@using Grand.Business.Core.Interfaces.Common.Directory
@using Grand.Business.Core.Interfaces.Common.Stores
@model ProductAttributeCombinationModel
@inject IStoreService _storeService
@inject IGroupService _groupService
@{
    Layout = "";
    ViewBag.Title = string.IsNullOrEmpty(Model.Id) ? Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.AddTitle"] : Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.Update"];
}
<form id="AttributeCombinationPopup" asp-area="@Constants.AreaAdmin" asp-controller="Product" asp-action="AttributeCombinationPopup" enctype="multipart/form-data"
      asp-route-productId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["productId"])"
      asp-route-Id="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["Id"])"
      asp-route-btnId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["btnId"])"
      asp-route-formId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["formId"])">


<div asp-validation-summary="All"></div>
<input asp-for="Id" type="hidden"/>
<input asp-for="ProductId" type="hidden"/>

<admin-popup title="@(string.IsNullOrEmpty(Model.Id) ? Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.AddTitle"] : Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.Update"])" icon="bi-grid-3x3-gap">
    @if (Model.Warnings.Count > 0)
    {
        <div class="note note-danger">
            @foreach (var warning in Model.Warnings)
            {
                @warning
                <br/>
            }
        </div>
    }
    @if (string.IsNullOrEmpty(Model.Id))
    {
        <partial name="Partials/ProductAttributes" model="Model.ProductAttributes"/>
    }
    else
    {
        <div class="grand-field">
            <span class="grand-field__label">@Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.Fields.Attributes"]</span>
            <div>@Html.Raw(Model.Attributes)</div>
        </div>
    }

    <div class="grand-fields grand-fields--2col">
        @if (!Model.UseMultipleWarehouses)
        {
            <admin-field asp-for="StockQuantity" size="md"/>
            <admin-field asp-for="ReservedQuantity" size="md"/>
        }
        <admin-field asp-for="Sku"/>
        <admin-field asp-for="Text"/>
        <admin-field asp-for="Mpn"/>
        <admin-field asp-for="Gtin"/>
        <admin-field asp-for="OverriddenPrice" suffix="@Model.PrimaryStoreCurrencyCode" size="md"/>
        <admin-field asp-for="NotifyAdminForQuantityBelow" size="md"/>
        <admin-field asp-for="AllowOutOfStockOrders"/>
    </div>

    @if (Model.UseMultipleWarehouses)
    {
        @* indexed model binding: every row posts WarehouseInventoryModels[i].* with the form *@
        <div id="pnlMultipleWarehouses">
            @if (Model.WarehouseInventoryModels.Count > 0)
            {
                <table class="table table-sm align-middle">
                    <thead>
                    <tr>
                        <th>@Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.Warehouse"]</th>
                        <th class="text-center">@Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.WarehouseUsed"]</th>
                        <th>@Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.StockQuantity"]</th>
                        <th>@Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.ReservedQuantity"]</th>
                    </tr>
                    </thead>
                    <tbody>
                    @for (var i = 0; i < Model.WarehouseInventoryModels.Count; i++)
                    {
                        var item = Model.WarehouseInventoryModels[i];
                        <tr>
                            <td>
                                @item.WarehouseName
                                <input asp-for="@Model.WarehouseInventoryModels[i].WarehouseId" type="hidden"/>
                            </td>
                            <td class="text-center">
                                <input asp-for="@Model.WarehouseInventoryModels[i].WarehouseUsed" class="form-check-input"/>
                            </td>
                            <td>
                                <admin-input asp-for="@Model.WarehouseInventoryModels[i].StockQuantity"/>
                            </td>
                            <td>
                                <admin-input asp-for="@Model.WarehouseInventoryModels[i].ReservedQuantity"/>
                            </td>
                        </tr>
                    }
                    </tbody>
                </table>
            }
            else
            {
                <p class="grand-field__hint">@Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.Warehouse.NotDefined"]</p>
            }
        </div>
    }

    <admin-field asp-for="PictureId">
        @* one radio per product picture, and a "no picture" one; the pictures are the labels *@
        <ul class="grand-picture-choice">
            <li>
                <input type="radio" name="@Html.NameFor(x => x.PictureId)" value="0" id="id_image_0"
                       @if (!string.IsNullOrEmpty(Model.PictureId))
                       {
                           <text> checked="checked" </text>
                       }>
                <label for="id_image_0">
                    @Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.Fields.Picture.NoPicture"]
                </label>
            </li>
            @foreach (var picture in Model.ProductPictureModels)
            {
                <li>
                    <input type="radio" name="@Html.NameFor(x => x.PictureId)" value="@picture.PictureId" id="[email protected]"
                           @if (picture.PictureId == Model.PictureId)
                           {
                               <text> checked="checked" </text>
                           }>
                    <label for="[email protected]">
                        <img src="@picture.PictureUrl" alt="" title="">
                    </label>
                </li>
            }
        </ul>
    </admin-field>

    <div class="grand-popup__actions">
        <vc:admin-widget widget-zone="product_details_attribute_combination_buttons" additional-data="Model"/>
        <button class="btn btn-primary" type="submit" name="save">
            <i class="bi bi-check-lg"></i> @Loc["Admin.Common.Save"]
        </button>
    </div>

    @if (!string.IsNullOrEmpty(Model.Id))
    {
        <admin-card title="@($"{Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.TierPrices"]} [{Model.PrimaryStoreCurrencyCode}]")" icon="bi-tags" flush>
            @{
                var tierPriceStores = new List<SelectListItem> { new(Loc["Admin.Settings.AllSettings.Fields.StoreName.AllStores"], "") };
                tierPriceStores.AddRange((await _storeService.GetAllStores()).Select(store => new SelectListItem(store.Shortcut ?? "", store.Id)));
                var tierPriceCustomerGroups = new List<SelectListItem> { new(Loc["Admin.Catalog.Products.TierPrices.Fields.CustomerGroup.All"], "") };
                tierPriceCustomerGroups.AddRange((await _groupService.GetAllCustomerGroups(showHidden: true)).Select(group => new SelectListItem(group.Name ?? "", group.Id)));
            }
            <admin-grid id="tierprices-grid"

                        read-url="@Url.Action("ProductAttributeCombinationTierPriceList", "Product", new { productId = Model.ProductId, productAttributeCombinationId = Model.Id, area = Constants.AreaAdmin })"

                        create-url="@Url.Action("ProductAttributeCombinationTierPriceInsert", "Product", new { productId = Model.ProductId, productAttributeCombinationId = Model.Id, area = Constants.AreaAdmin })"

                        update-url="@Url.Action("ProductAttributeCombinationTierPriceUpdate", "Product", new { productId = Model.ProductId, productAttributeCombinationId = Model.Id, area = Constants.AreaAdmin })"

                        destroy-url="@Url.Action("ProductAttributeCombinationTierPriceDelete", "Product", new { productId = Model.ProductId, productAttributeCombinationId = Model.Id, area = Constants.AreaAdmin })"

                        pager="Compact"

                        edit-mode="Inline">

                <grid-toolbar-create/>

                @* the "All" choices were ' ' in the Kendo lists; the controller trims both to "" *@

                <grid-column field="StoreId" title="@Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.TierPrices.Store"]" width="250" editor="Select" options="tierPriceStores" text-field="Store"/>

                <grid-column field="CustomerGroupId" title="@Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.TierPrices.CustomerGroup"]" width="250" editor="Select" options="tierPriceCustomerGroups" text-field="CustomerGroup"/>

                <grid-column field="Quantity" title="@Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.TierPrices.Quantity"]" width="150" format="{0:0}" editor="Integer" default-value="0"/>

                <grid-column field="Price" title="@Loc["Admin.Catalog.Products.ProductAttributes.AttributeCombinations.TierPrices.Price"]" width="150" editor="Numeric" decimals="4" default-value="0"/>

                <grid-commands edit="true" destroy="true" width="200"/>

            </admin-grid>
        </admin-card>
    }
</admin-popup>
<script>
        var mfp = $.magnificPopup.instance;
        $("#AttributeCombinationPopup").submit(function (e) {
            e.preventDefault();
            var form = $(this);
            var url = form.attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data: form.serialize(),
                success: function (data) {
                    if (data == "") {
                        mfp.close();
                        $('#btnRefreshCombinations').click();
                    } else {
                        $.magnificPopup.open({
                            items: {
                                src: data,
                                type: 'inline'
                            },
                            callbacks: {
                                open: function () {
                                    $('.mfp-wrap').removeAttr('tabindex');
                                }
                            }
                        });
                    }
                }
            });
        });
    </script>
</form>