/// <summary> /// Save cart as payment plan /// </summary> /// <param name="cart"></param> private OrderReference SaveAsPaymentPlan(ICart cart) { var orderReference = _orderRepository.SaveAsPaymentPlan(cart); var paymentPlanSetting = cart.Properties["PaymentPlanSetting"] as PaymentPlanSetting; IPaymentPlan paymentPlan; paymentPlan = _orderRepository.Load <IPaymentPlan>(orderReference.OrderGroupId); paymentPlan.CycleMode = PaymentPlanCycle.Days; paymentPlan.CycleLength = paymentPlanSetting.CycleLength; paymentPlan.StartDate = DateTime.Now.AddDays(paymentPlanSetting.CycleLength); paymentPlan.EndDate = paymentPlanSetting.EndDate; paymentPlan.IsActive = paymentPlanSetting.IsActive; var principal = PrincipalInfo.CurrentPrincipal; AddNoteToCart(paymentPlan, $"Note: New payment plan placed by {principal.Identity.Name} in 'vnext site'.", OrderNoteTypes.System.ToString(), principal.GetContactId()); _orderRepository.Save(paymentPlan); paymentPlan.AdjustInventoryOrRemoveLineItems((item, validationIssue) => { }); _orderRepository.Save(paymentPlan); //create first order orderReference = _orderRepository.SaveAsPurchaseOrder(paymentPlan); var purchaseOrder = _orderRepository.Load(orderReference); OrderGroupWorkflowManager.RunWorkflow((OrderGroup)purchaseOrder, OrderGroupWorkflowManager.CartCheckOutWorkflowName); var noteDetailPattern = "New purchase order placed by {0} in {1} from payment plan {2}"; var noteDetail = string.Format(noteDetailPattern, ManagementHelper.GetUserName(PrincipalInfo.CurrentPrincipal.GetContactId()), "VNext site", (paymentPlan as PaymentPlan).Id); AddNoteToPurchaseOrder(purchaseOrder as IPurchaseOrder, noteDetail, OrderNoteTypes.System, PrincipalInfo.CurrentPrincipal.GetContactId()); _orderRepository.Save(purchaseOrder); paymentPlan.LastTransactionDate = DateTime.UtcNow; paymentPlan.CompletedCyclesCount++; _orderRepository.Save(paymentPlan); return(orderReference); }
/// <summary> /// Gets the name of the user. /// </summary> /// <returns></returns> protected string GetUserName() { Guid editorGuid = (Guid)DataBinder.Eval(DataItem, "EditorUID"); return(ManagementHelper.GetUserName(editorGuid)); }