Created
March 2, 2018 21:37
-
-
Save websterian/8da074b6d150dfa54918378f38922770 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="OrderDiscountAdjustmentsController.cs" company="Sitecore Corporation"> | |
// Copyright (c) Sitecore Corporation 1999-2017 | |
// </copyright> | |
// <summary> | |
// Defines the OrderDiscountAdjustmentsController 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; | |
public class OrderDiscountAdjustmentsController : 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 OrderDiscountAdjustmentsController(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 repAdjustments = new List<OrderDiscountAdjustment>(); | |
foreach (var order in orders.Items) | |
{ | |
foreach (var adjustment in order.Adjustments) | |
{ | |
if(adjustment.AdjustmentType == "Discount") | |
{ | |
var repAdjustment = new OrderDiscountAdjustment(); | |
repAdjustment.Adjustment = new Money(adjustment.Adjustment.CurrencyCode, adjustment.Adjustment.Amount); | |
repAdjustment.DisplayName = adjustment.DisplayName; | |
repAdjustment.Name = adjustment.Name; | |
repAdjustment.OrderId = order.Id; | |
repAdjustment.Id = Guid.NewGuid().ToString(); | |
repAdjustments.Add(repAdjustment); | |
} | |
} | |
} | |
return Ok(repAdjustments); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment