Last active
March 2, 2018 21:30
-
-
Save websterian/441789c60f45fb13041e80ed723541ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------------------------------------------------------------------------------------- | |
// <copyright file="OrderCouponsController.cs" company="Sitecore Corporation"> | |
// Copyright (c) Sitecore Corporation 1999-2017 | |
// </copyright> | |
// <summary> | |
// Defines the OrderCouponsController 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 Coupons; | |
using Model; | |
using Pricing; | |
public class OrderCouponsController : CommerceController | |
{ | |
/// <summary> | |
/// Initializes a new instance of the <see cref="OrderCouponsController"/> class. | |
/// </summary> | |
/// <param name="serviceProvider"> | |
/// The service provider. | |
/// </param> | |
/// <param name="globalEnvironment"> | |
/// The global environment. | |
/// </param> | |
public OrderCouponsController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) | |
: base(serviceProvider, globalEnvironment) | |
{ | |
} | |
[HttpGet] | |
[Route("Get")] | |
public async Task<IActionResult> Get() | |
{ | |
//Here you should can add some caching... | |
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<OrderCoupon>(); | |
foreach (var order in orders.Items) | |
{ | |
var coupons = order.GetComponent<CartCouponsComponent>(); | |
var reportingCoupon = new OrderCoupon(); | |
reportingCoupon.OrderId = order.Id; | |
reportingCoupon.List = coupons.List; | |
cartLineComponent.Add(reportingCoupon); | |
} | |
return Ok(cartLineComponent); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment