how to get the list of id of goods on the page of the view of the OrderSummary file

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
how to get the list of id of goods on the page of the view of the OrderSummary file in the form ['1234', '4567']

thanks!
6 years ago
Go to Nop.Web==>Models==>ShoppingCart.cs and list of int named ProductIds. At constructor of the ShoppingCart Class add a new instance of the list of int like bellow.


  public ShoppingCartModel()
        {
            Items = new List<ShoppingCartItemModel>();
            Warnings = new List<string>();
            EstimateShipping = new EstimateShippingModel();
            DiscountBox = new DiscountBoxModel();
            GiftCardBox = new GiftCardBoxModel();
            CheckoutAttributes = new List<CheckoutAttributeModel>();
            OrderReviewData = new OrderReviewDataModel();

            ButtonPaymentMethodActionNames = new List<string>();
            ButtonPaymentMethodControllerNames = new List<string>();
            ButtonPaymentMethodRouteValues = new List<RouteValueDictionary>();

            ProductIds = new List<int>();
        }

      
public List<int> ProductIds { get; set; }


Now go to the Nop.Web==>Controllers==>ShoppingCartController.cs and add the bellow code at OrderSummary method.

 
foreach (var item in model.Items)
{
    model.ProductIds.Add(item.ProductId);
}


Now at view, you can get a list of products ids that are added to the shopping cart. To get the ProductsId at view use the below code.

@Model.ProductIds
6 years ago
sina.islam wrote:
Go to Nop.Web==>Models==>ShoppingCart.cs and list of int named ProductIds. At constructor of the ShoppingCart Class add a new instance of the list of int like bellow.


  public ShoppingCartModel()
        {
            Items = new List<ShoppingCartItemModel>();
            Warnings = new List<string>();
            EstimateShipping = new EstimateShippingModel();
            DiscountBox = new DiscountBoxModel();
            GiftCardBox = new GiftCardBoxModel();
            CheckoutAttributes = new List<CheckoutAttributeModel>();
            OrderReviewData = new OrderReviewDataModel();

            ButtonPaymentMethodActionNames = new List<string>();
            ButtonPaymentMethodControllerNames = new List<string>();
            ButtonPaymentMethodRouteValues = new List<RouteValueDictionary>();

            ProductIds = new List<int>();
        }

      
public List<int> ProductIds { get; set; }


Now go to the Nop.Web==>Controllers==>ShoppingCartController.cs and add the bellow code at OrderSummary method.

 
foreach (var item in model.Items)
{
    model.ProductIds.Add(item.ProductId);
}


Now at view, you can get a list of products ids that are added to the shopping cart. To get the ProductsId at view use the below code.

@Model.ProductIds


Can not get list in view without using source code?
6 years ago
gnikitsin wrote:
Go to Nop.Web==>Models==>ShoppingCart.cs and list of int named ProductIds. At constructor of the ShoppingCart Class add a new instance of the list of int like bellow.


  public ShoppingCartModel()
        {
            Items = new List<ShoppingCartItemModel>();
            Warnings = new List<string>();
            EstimateShipping = new EstimateShippingModel();
            DiscountBox = new DiscountBoxModel();
            GiftCardBox = new GiftCardBoxModel();
            CheckoutAttributes = new List<CheckoutAttributeModel>();
            OrderReviewData = new OrderReviewDataModel();

            ButtonPaymentMethodActionNames = new List<string>();
            ButtonPaymentMethodControllerNames = new List<string>();
            ButtonPaymentMethodRouteValues = new List<RouteValueDictionary>();

            ProductIds = new List<int>();
        }

      
public List<int> ProductIds { get; set; }


Now go to the Nop.Web==>Controllers==>ShoppingCartController.cs and add the bellow code at OrderSummary method.

 
foreach (var item in model.Items)
{
    model.ProductIds.Add(item.ProductId);
}


Now at view, you can get a list of products ids that are added to the shopping cart. To get the ProductsId at view use the below code.

@Model.ProductIds

Can not get list in view without using source code?


Yes, Try like ==>

@{
    var productIds = Model.Items.Select(p=>p.ProductId).ToList();
}

//Sohel
6 years ago
nopStation wrote:
Go to Nop.Web==>Models==>ShoppingCart.cs and list of int named ProductIds. At constructor of the ShoppingCart Class add a new instance of the list of int like bellow.


  public ShoppingCartModel()
        {
            Items = new List<ShoppingCartItemModel>();
            Warnings = new List<string>();
            EstimateShipping = new EstimateShippingModel();
            DiscountBox = new DiscountBoxModel();
            GiftCardBox = new GiftCardBoxModel();
            CheckoutAttributes = new List<CheckoutAttributeModel>();
            OrderReviewData = new OrderReviewDataModel();

            ButtonPaymentMethodActionNames = new List<string>();
            ButtonPaymentMethodControllerNames = new List<string>();
            ButtonPaymentMethodRouteValues = new List<RouteValueDictionary>();

            ProductIds = new List<int>();
        }

      
public List<int> ProductIds { get; set; }


Now go to the Nop.Web==>Controllers==>ShoppingCartController.cs and add the bellow code at OrderSummary method.

 
foreach (var item in model.Items)
{
    model.ProductIds.Add(item.ProductId);
}


Now at view, you can get a list of products ids that are added to the shopping cart. To get the ProductsId at view use the below code.

@Model.ProductIds

Can not get list in view without using source code?

Yes, Try like ==>

@{
    var productIds = Model.Items.Select(p=>p.ProductId).ToList();
}

//Sohel


thanks sohel
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.