Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CommandsController.cs" company="Sitecore Corporation">
// Copyright (c) Sitecore Corporation 1999-2017
// </copyright>
// <summary>
// Defines the OrderLinesController controller.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Sitecore.Commerce.Plugin.Reporting.Controller
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Sitecore.Commerce.Core;
using Sitecore.Commerce.Plugin.Orders;
using Core.Commands;
using Model;
/// <summary>
/// The resend order controller.
/// </summary>
public class OrderLinesController : CommerceController
{
/// <summary>
/// Initializes a new instance of the <see cref="OrderLinesController"/> class.
/// </summary>
/// <param name="serviceProvider">
/// The service provider.
/// </param>
/// <param name="globalEnvironment">
/// The global environment.
/// </param>
public OrderLinesController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment)
: base(serviceProvider, globalEnvironment)
{
}
[HttpGet]
[Route("Get")]
public async Task<IActionResult> Get()
{
var findOrdersCommand = this.Command<FindEntitiesInListCommand>();
var orders = await findOrdersCommand.Process<Order>(this.CurrentContext, CommerceEntity.ListName<Order>(), 0, int.MaxValue);
if (orders == null)
{
return null;
}
var cartLineComponent = new List<OrderLine>();
foreach (var order in orders.Items)
{
foreach(var orderLine in order.Lines)
{
var reportingLine = new OrderLine();
reportingLine.Adjustments = orderLine.Adjustments;
reportingLine.OrderId = order.Id;
reportingLine.Quantity = orderLine.Quantity;
reportingLine.ItemId = orderLine.ItemId;
reportingLine.Name = orderLine.Name;
reportingLine.Totals = orderLine.Totals;
reportingLine.UnitListPrice = orderLine.UnitListPrice;
cartLineComponent.Add(reportingLine);
}
}
return Ok(cartLineComponent);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment