Created
March 27, 2018 20:46
-
-
Save websterian/43932c6f2ce097a0e08b64974ea870e2 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
namespace Sitecore.Commerce.Plugin.AdventureWorks | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.Extensions.Logging; | |
using Sitecore.Commerce.Core; | |
using Sitecore.Commerce.Plugin.Carts; | |
using Sitecore.Commerce.Plugin.Orders; | |
using Sitecore.Framework.Conditions; | |
using Sitecore.Framework.Pipelines; | |
using Payments; | |
using Entities; | |
[PipelineDisplayName("PersistTransactionOrderLinkBlock")] | |
public class PersistTransactionOrderLinkBlock : PipelineBlock<Order, Order, CommercePipelineExecutionContext> | |
{ | |
/// <summary> | |
/// The find entity pipeline | |
/// </summary> | |
private readonly IFindEntityPipeline findEntityPipeline; | |
/// <summary> | |
/// The _persist entity pipeline. | |
/// </summary> | |
private readonly IPersistEntityPipeline persistEntityPipeline; | |
/// <summary> | |
/// Initializes a new instance of the <see cref="UpdateCouponUsageBlock"/> class. | |
/// </summary> | |
/// <param name="findEntityPipeline"> | |
/// The find entity pipeline. | |
/// </param> | |
/// <param name="persistEntityPipeline"> | |
/// The persist Entity Pipeline. | |
/// </param> | |
public PersistTransactionOrderLinkBlock(IFindEntityPipeline findEntityPipeline, IPersistEntityPipeline persistEntityPipeline) | |
{ | |
this.findEntityPipeline = findEntityPipeline; | |
this.persistEntityPipeline = persistEntityPipeline; | |
} | |
/// <summary> | |
/// The run. | |
/// </summary> | |
/// <param name="order"> | |
/// The order. | |
/// </param> | |
/// <param name="context"> | |
/// The context. | |
/// </param> | |
/// <returns> | |
/// The <see cref="Task"/>. | |
/// </returns> | |
public override async Task<Order> Run(Order order, CommercePipelineExecutionContext context) | |
{ | |
var payment = order.GetComponent<FederatedPaymentComponent>(); | |
var link = new TransactionIdToOrderLink(payment.TransactionId, order.Id); | |
var returnedLink = await persistEntityPipeline.Run(new PersistEntityArgument(link), context); | |
//Here is how to get the order from somewhere else in code by transactionid | |
var foundLink = findEntityPipeline.Run(new FindEntityArgument(typeof(TransactionIdToOrderLink), payment.TransactionId), context).Result as TransactionIdToOrderLink; | |
var foundOrder = findEntityPipeline.Run(new FindEntityArgument(typeof(Order), foundLink.OrderId), context).Result as Order; | |
return order; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment