Custom mesh using Telerik pluggin in nopcommerce 2.8

I am working on nopcommerce2.8 version. I had a problem implementing the telerik plugin to create a new grid. I am implementing a concept in which I want to give a different price for a product for different customers. Therefore, in order to set a new price for different customers, in the admin panel I create a grid on the product editing page using telerik. I created a new tab to display this data. I can display the name and price of the customer in the grid, but I cannot call the update function when I click the update button after editing the row. The same update function, which I also called to delete the grid line, so when I click the "Delete the same update function" button, I start the trigger. I think some settings were skipped in the view. You are welcome,help me fix this update issue.

The model, view, and controller of my nopcommerce in the section below.

Thank.

//Model
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using FluentValidation.Attributes;
using Nop.Admin.Models.Customers;
using Nop.Admin.Validators.Catalog;
using Nop.Web.Framework;
using Nop.Web.Framework.Localization;
using Nop.Web.Framework.Mvc;
using Telerik.Web.Mvc;

namespace Nop.Admin.Models.Catalog
{
    public partial class CustomerProductPriceModel : BaseNopModel
    {
        public int Customer_Id { get; set; }
        [NopResourceDisplayName("Customer Name")]
        public string Customer_name { get; set; }

        [NopResourceDisplayName("Price")]
        public decimal Price { get; set; }

        [NopResourceDisplayName("Unit")]
        public string Units { get; set; }

    }
}

// view

  @(Html.Telerik().Grid<CustomerProductPriceModel>()
        .Name("Grid")
        .DataKeys(x =>
                    {
                        x.Add(y => y.Customer_Id);
                    })
                     .DataBinding(dataBinding =>
                    {
                            dataBinding.Ajax()
                            .Select("CustomerProductPriceList", "ProductVariant", new { productVariantId = Model.Id })
                            .Update("CustomerPriceUpdate", "ProductVariant", new { productVariantId = Model.Id })
                             .Delete("CustomerPriceUpdate", "ProductVariant", new { productVariantId = Model.Id });
                    })
        .Columns(columns =>
        {
            columns.Bound(y => y.Customer_name).Width(200).ReadOnly();
            columns.Bound(y => y.Price).Width(100);

            columns.Command(commands =>
            {
                commands.Edit().Text(T("Admin.Common.Edit").Text);
                commands.Delete().Text(T("Admin.Common.Delete").Text);
            }).Width(180);

        })
        .Editable(x =>
                {
                    x.Mode(GridEditMode.InLine);
                })
        .EnableCustomBinding(true)

      )


    // controller

    [GridAction(EnableCustomBinding = true)]
        public ActionResult CustomerPriceUpdate(GridCommand command, CustomerProductPriceModel model, int productVariantId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();


             return CustomerProductPriceList(command, productVariantId);
        }


       [HttpPost, GridAction(EnableCustomBinding = true)]
        public ActionResult CustomerProductPriceList(GridCommand command, int productVariantId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();

            var productVariant = _productService.GetProductVariantById(productVariantId);
            if (productVariant == null)
                throw new ArgumentException("No product variant found with the specified id");

            var CustomerPrices = PrepareCustomerProductPriceModel(productVariant.Product.Id);
            var CustomerPricesa = CustomerPrices
               .Select(x =>
               {
                   return new CustomerProductPriceModel()
                   {
                       Customer_Id = x.Customer_Id,
                       Price = x.Price,
                       Units = x.Units,
                       Customer_name = x.Customer_name
                   };
               })
               .ToList();
            var model = new GridModel<CustomerProductPriceModel>
            {
                Data = CustomerPricesa,
                Total = CustomerPrices.Count
            };
            return new JsonResult
            {
                Data = model
            };
        }
+5
source share
1 answer

Is there a reason not to use the built-in customer price levels already in place in nopCommerce, or do you want to immediately display all prices?

0
source

All Articles