-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetAccountLoyaltyCoupons.cs
61 lines (49 loc) · 2.3 KB
/
GetAccountLoyaltyCoupons.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using Feature.LoyaltyPoints.Website.Managers;
using Feature.LoyaltyPoints.Website.Models;
using Sitecore.Commerce.Core;
using Sitecore.Commerce.Engine;
using Sitecore.Commerce.Engine.Connect.Entities;
using Sitecore.Commerce.Engine.Connect.Pipelines;
using Sitecore.Commerce.Entities;
using Sitecore.Commerce.EntityViews;
using Sitecore.Commerce.Pipelines;
using Sitecore.Commerce.Services;
using Sitecore.Commerce.Services.Customers;
using Sitecore.Diagnostics;
namespace Feature.LoyaltyPoints.Website.Pipelines
{
public class GetCustomerCoupons: Sitecore.Commerce.Engine.Connect.Pipelines.PipelineProcessor
{
public IEntityFactory EntityFactory { get; set; }
public GetCustomerCoupons(IEntityFactory entityFactory)
{
Assert.ArgumentNotNull((object)entityFactory, nameof(entityFactory));
this.EntityFactory = entityFactory;
}
public override void Process(ServicePipelineArgs args)
{
// Below in lieu of PipelineUtility.ValidateArguments, which is used by Sitecore's Commerce.Engine.Connect processors, but is internal.
GetCouponsRequest request = args.Request as GetCouponsRequest;
GetCouponsResult result = args.Result as GetCouponsResult;
Assert.IsNotNull(request, $"args.Request is null or not of type {nameof(GetCouponsRequest)}.");
Assert.IsNotNull(result, $"args.Result is null or not of type {nameof(GetCouponsResult)}.");
Container container = this.GetContainer(request.Shop.Name, string.Empty, request.CustomerId, "", args.Request.CurrencyCode, new DateTime?());
EntityView entityView = this.GetEntityView(container, request.CustomerId, string.Empty, "LoyaltyCoupons", string.Empty, result);
if (result == null || result.Success == false)
{
return;
}
var couponList = entityView.ChildViews.OfType<EntityView>().Where(v=>v.Name=="Coupon").Select(ConvertEntityToCoupon).ToList();
result.Coupons = couponList;
}
private Coupon ConvertEntityToCoupon(EntityView ev)
{
return new Coupon(ev);
}
}
}