Esempio n. 1
0
        private async Task ReserveIt(CommerceContext commerceContext, string id)
        {
            var entity = await _commander.GetEntity <CommerceEntity>(commerceContext, id, autoCreate : true);

            entity.Id = id;
            await _commander.PersistEntity(commerceContext, entity);
        }
Esempio n. 2
0
        public async Task <UserPluginOptions> CurrentUserSettings(CommerceContext commerceContext, CommerceCommander commerceCommander)
        {
            var userPluginOptionsId = $"Entity-UserPluginOptions-{commerceContext.CurrentCsrId().Replace("\\", "|")}";

            var userPluginOptions = await commerceCommander.GetEntity <UserPluginOptions>(commerceContext, userPluginOptionsId, true);

            if (!userPluginOptions.IsPersisted)
            {
                userPluginOptions.Id = userPluginOptionsId;
            }

            return(userPluginOptions);
        }
Esempio n. 3
0
        public async Task <UserPluginOptions> CurrentUserSettings(CommerceContext commerceContext, CommerceCommander commerceCommander)
        {
            var userPluginOptionsId = $"Entity-UserPluginOptions-{commerceContext.CurrentCsrId().Replace("\\", "|")}";

            var userPluginOptions = await commerceCommander
                                    .GetEntity <UserPluginOptions>(commerceContext, userPluginOptionsId)
                                    ?? new UserPluginOptions
            {
                Id = userPluginOptionsId
            };

            return(userPluginOptions);
        }
Esempio n. 4
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Condition.Requires(entityView).IsNotNull($"{Name}: The argument cannot be null");

            var pluginPolicy = context.GetPolicy <PluginPolicy>();

            OrdersTotals orderTotals = null;

            if (entityView.EntityId.Contains("Entity-Customer-"))
            {
                var entityViewArgument = _commerceCommander.Command <ViewCommander>().CurrentEntityViewArgument(context.CommerceContext);
                orderTotals = await _commerceCommander.GetEntity <OrdersTotals>(context.CommerceContext, $"Order_Totals_ByCust_{entityViewArgument.EntityId.Replace("Entity-Customer-", "")}", true);

                if (!orderTotals.IsPersisted)
                {
                    return(entityView);
                }
            }

            else if (entityView.Name == "OrdersDashboard")
            {
                orderTotals = await _commerceCommander.GetEntity <OrdersTotals>(context.CommerceContext, "Orders_Totals", true);

                if (!orderTotals.IsPersisted)
                {
                    return(entityView);
                }
            }

            if (orderTotals == null)
            {
                return(entityView);
            }

            if (orderTotals.IsPersisted)
            {
                var ordersTotalsView = new EntityView
                {
                    Name        = "Orders.Enhancements.Totals",
                    DisplayName = "Order Totals",
                    UiHint      = "Flat",
                    DisplayRank = 10,
                    Icon        = pluginPolicy.Icon,
                    ItemId      = string.Empty,
                };
                entityView.ChildViews.Add(ordersTotalsView);

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Orders",
                    IsHidden   = false,
                    IsReadOnly = true,
                    RawValue   = orderTotals.OrderCount
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "GrandTotal",
                    IsHidden   = false,
                    IsReadOnly = true,
                    RawValue   = orderTotals.Totals.GrandTotal.AsCurrency()
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Payments",
                    IsHidden   = false,
                    IsReadOnly = true,
                    RawValue   = orderTotals.Totals.PaymentsTotal.AsCurrency()
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "SubTotal",
                    IsHidden   = false,
                    IsReadOnly = true,
                    RawValue   = orderTotals.Totals.SubTotal.AsCurrency()
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Updated",
                    IsHidden   = false,
                    IsReadOnly = true,
                    RawValue   = orderTotals.DateUpdated.Value.ToString("yyyy-MMM-dd hh:mm")
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Version",
                    IsHidden   = false,
                    IsReadOnly = true,
                    RawValue   = orderTotals.Version
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name        = "LastRecord",
                    DisplayName = "Last Record",
                    IsHidden    = false,
                    IsReadOnly  = true,
                    RawValue    = orderTotals.LastSkip
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name        = "LastRunStart",
                    DisplayName = "Last Run Start",
                    IsHidden    = false,
                    IsReadOnly  = true,
                    RawValue    = orderTotals.LastRunStarted.ToString("yyyy-MMM-dd hh:mm")
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name        = "LastRunEnd",
                    DisplayName = "Last Run End",
                    IsHidden    = false,
                    IsReadOnly  = true,
                    RawValue    = orderTotals.LastRunEnded.ToString("yyyy-MMM-dd hh:mm")
                });

                ordersTotalsView.Properties.Add(
                    new ViewProperty
                {
                    Name        = "Run Time",
                    DisplayName = "Run Time (s)",
                    IsHidden    = false,
                    IsReadOnly  = true,
                    RawValue    = (orderTotals.LastRunEnded - orderTotals.LastRunStarted).TotalSeconds.ToString()
                });

                if (orderTotals.Adjustments.Count > 0)
                {
                    foreach (var adjustment in orderTotals.Adjustments)
                    {
                        adjustment.Adjustment.CurrencyCode = "USD";
                        ordersTotalsView.Properties.Add(
                            new ViewProperty
                        {
                            Name       = adjustment.Name,
                            IsHidden   = false,
                            IsReadOnly = true,
                            RawValue   = adjustment.Adjustment
                        });
                    }
                }
            }
            return(entityView);
        }
Esempio n. 5
0
        /// <summary>
        /// Runs the specified argument.
        /// </summary>
        /// <param name="arg">The argument.</param>
        /// <param name="context">The context.</param>
        /// <returns>The <see cref="Order"/></returns>
        public override async Task <Order> Run(Order arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull($"{Name}: The order cannot be null.");

            if (!arg.HasComponent <FederatedPaymentComponent>() ||
                !arg.Status.Equals(context.GetPolicy <KnownOrderStatusPolicy>().Released, StringComparison.OrdinalIgnoreCase))
            {
                return(arg);
            }

            var knownOrderStatuses = context.GetPolicy <KnownOrderStatusPolicy>();

            var payment = arg.GetComponent <FederatedPaymentComponent>();
            var salesActivityReference = arg.SalesActivity.FirstOrDefault(sa => sa.Name.Equals(payment.Id, StringComparison.OrdinalIgnoreCase));

            if (string.IsNullOrEmpty(payment.TransactionId) || salesActivityReference == null)
            {
                payment.TransactionStatus = knownOrderStatuses.Problem;
                arg.Status = knownOrderStatuses.Problem;

                await context.CommerceContext.AddMessage(
                    context.GetPolicy <KnownResultCodes>().Error,
                    "InvalidOrMissingPropertyValue",
                    new object[]
                {
                    "TransactionId"
                },
                    "Invalid or missing value for property 'TransactionId'.")
                .ConfigureAwait(false);

                return(arg);
            }

            var salesActivity = await _commander
                                .GetEntity <SalesActivity>(context.CommerceContext, salesActivityReference.EntityTarget, salesActivityReference.EntityTargetUniqueId)
                                .ConfigureAwait(false);

            if (salesActivity == null)
            {
                payment.TransactionStatus = knownOrderStatuses.Problem;
                arg.Status = knownOrderStatuses.Problem;

                await context.CommerceContext.AddMessage(
                    context.GetPolicy <KnownResultCodes>().Error,
                    "EntityNotFound",
                    new object[]
                {
                    salesActivityReference.EntityTarget
                },
                    $"Entity '{salesActivityReference.EntityTarget}' was not found.")
                .ConfigureAwait(false);

                return(arg);
            }

            var knowSalesActivitiesStatus = context.GetPolicy <KnownSalesActivityStatusesPolicy>();

            if (payment.TransactionStatus.Equals(knownOrderStatuses.Problem, StringComparison.OrdinalIgnoreCase))
            {
                salesActivity.PaymentStatus = knowSalesActivitiesStatus.Problem;
            }

            await SettleSalesActivity(salesActivity, context).ConfigureAwait(false);

            payment.TransactionStatus = salesActivity.GetComponent <FederatedPaymentComponent>().TransactionStatus;
            if (salesActivity.PaymentStatus.Equals(knowSalesActivitiesStatus.Problem, StringComparison.OrdinalIgnoreCase))
            {
                arg.Status = knownOrderStatuses.Problem;
            }

            var knownSalesActivityLists = context.GetPolicy <KnownOrderListsPolicy>();
            var listToAssignTo          = !salesActivity.PaymentStatus.Equals(knowSalesActivitiesStatus.Settled, StringComparison.OrdinalIgnoreCase)
                ? knownSalesActivityLists.ProblemSalesActivities
                : knownSalesActivityLists.SettledSalesActivities;
            var argument = new MoveEntitiesInListsArgument(knownSalesActivityLists.SettleSalesActivities, listToAssignTo, new List <string>
            {
                salesActivity.Id
            });
            await _commander.Pipeline <IMoveEntitiesInListsPipeline>().Run(argument, context.CommerceContext.PipelineContextOptions).ConfigureAwait(false);

            await _commander.PersistEntity(context.CommerceContext, salesActivity).ConfigureAwait(false);

            return(arg);
        }
Esempio n. 6
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Condition.Requires(entityView).IsNotNull($"{Name}: The argument cannot be null");

            if (entityView.Name != "DevOps-PullEnvironment")
            {
                return(entityView);
            }

            var entityViewArgument = _commerceCommander.Command <ViewCommander>().CurrentEntityViewArgument(context.CommerceContext);

            if (entityViewArgument.Entity == null)
            {
                var appService = await _commerceCommander
                                 .GetEntity <AppService>(context.CommerceContext, entityView.ItemId);

                if (appService == null)
                {
                }
                else
                {
                    var serviceUri = $"http://{appService.Host}/commerceops/Environments";

                    try
                    {
                        var jsonResponse = await _commerceCommander.Command <JsonCommander>()
                                           .Process(context.CommerceContext, serviceUri);

                        dynamic dynJson = JsonConvert.DeserializeObject(jsonResponse.Json);

                        var environments = dynJson.value;

                        var templateViewProperty = new ViewProperty
                        {
                            Name        = "Environment",
                            DisplayName = "Selected Environment",
                            IsHidden    = false,
                            IsRequired  = true,
                            RawValue    = string.Empty
                        };

                        entityView.Properties.Add(templateViewProperty);

                        var availableSelections = templateViewProperty.GetPolicy <AvailableSelectionsPolicy>();

                        foreach (var environment in environments)
                        {
                            availableSelections.List.Add(new Selection {
                                Name = environment.Name, DisplayName = environment.Name, IsDefault = false
                            });
                        }

                        entityView.Properties.Add(new ViewProperty
                        {
                            Name        = "NameAs",
                            DisplayName = "Name Environment As",
                            IsHidden    = false,
                            IsRequired  = false,
                            RawValue    = string.Empty
                        });
                    }
                    catch (Exception ex)
                    {
                        context.Logger.LogError($"DevOps.FormPullEnvironment.Exception: Message={ex.Message}");
                    }
                }
            }
            return(entityView);
        }
        /// <summary>The execute.</summary>
        /// <param name="entityView">The argument.</param>
        /// <param name="context">The context.</param>
        /// <returns>The <see cref="EntityView"/>.</returns>
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Condition.Requires(entityView).IsNotNull($"{Name}: The argument cannot be null");

            var entityViewArgument = _commerceCommander.Command <ViewCommander>().CurrentEntityViewArgument(context.CommerceContext);

            if (!(entityViewArgument.Entity is Customer))
            {
                return(entityView);
            }

            try
            {
                if (entityView.ChildViews.FirstOrDefault(p => p.Name == "CustomerEntitlements") is EntityView customerEntitlementsView)
                {
                    foreach (var entityViewChild in customerEntitlementsView.ChildViews.OfType <EntityView>())
                    {
                        var entitlement = await _commerceCommander
                                          .GetEntity <Entitlement>(context.CommerceContext, entityViewChild.ItemId)
                                          .ConfigureAwait(false);

                        var order = await _commerceCommander.GetEntity <Order>(context.CommerceContext, entitlement.Order.EntityTarget).ConfigureAwait(false);

                        var orderEntitlementsComponent = order.GetComponent <EntitlementsComponent>();
                        var entitlementLine            = orderEntitlementsComponent.Entitlements.FirstOrDefault(p => p.EntityTarget == entitlement.Id);
                        var orderLine            = order.Lines.First(p => p.Id == entitlementLine?.ItemTarget);
                        var cartProductComponent = orderLine.GetComponent <CartProductComponent>();
                        var imageId = cartProductComponent.Image.SitecoreId.Replace("-", "").Replace("{", "").Replace("}", "");

                        SitecoreConnectionPolicy connectionPolicy = context.GetPolicy <SitecoreConnectionPolicy>();
                        GlobalImagePolicy        globalPolicy     = context.GetPolicy <GlobalImagePolicy>();
                        var siteProtocol = connectionPolicy.Protocol;
                        var siteHost     = connectionPolicy.Host;

                        var properties = new List <ViewProperty>
                        {
                            new ViewProperty
                            {
                                Name         = "Image",
                                IsHidden     = false,
                                IsRequired   = false,
                                RawValue     = $"<img alt='This is the alternate' height=50 width=50 src='{siteProtocol}://{siteHost}/-/media/{imageId}.ashx'/>",
                                UiType       = "Html",
                                OriginalType = "Html"
                            },

                            new ViewProperty
                            {
                                Name       = "Name",
                                IsHidden   = false,
                                IsRequired = false,
                                RawValue   = cartProductComponent.Name
                            },

                            new ViewProperty
                            {
                                Name       = "Created",
                                IsHidden   = false,
                                IsRequired = false,
                                RawValue   = entitlement.DateCreated?.ToString("yyyy-MMM-dd hh:mm")
                            },

                            new ViewProperty
                            {
                                Name       = "Order",
                                IsHidden   = false,
                                IsRequired = false,
                                RawValue   = order.Id
                            },

                            new ViewProperty
                            {
                                Name       = "Gift Card Code",
                                IsHidden   = false,
                                IsRequired = false,
                                RawValue   = entitlement.FriendlyId
                            }
                        };

                        properties.AddRange(entityViewChild.Properties);
                        entityViewChild.Properties = properties;
                    }
                }
            }
            catch (Exception ex)
            {
                context.CommerceContext.LogException($"DigitalItems.Enhancements.EntityViewCustomerDigitalItems.Run.Exception", ex);
            }

            return(entityView);
        }
Esempio n. 8
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Condition.Requires(entityView).IsNotNull($"{Name}: The argument cannot be null");

            try
            {
                if (entityView.Name != "Master")
                {
                    return(entityView);
                }
                if (!entityView.EntityId.Contains("Entity-SellableItem-"))
                {
                    return(entityView);
                }

                var ebayConfig = await _commerceCommander.GetEntity <EbayConfigEntity>(context.CommerceContext, "Entity-EbayConfigEntity-Global", true);

                if (ebayConfig.HasComponent <EbayBusinessUserComponent>())
                {
                    var entityViewArgument = _commerceCommander.Command <ViewCommander>().CurrentEntityViewArgument(context.CommerceContext);

                    if (!(entityViewArgument.Entity is SellableItem))
                    {
                        return(entityView);
                    }

                    var item = (SellableItem)entityViewArgument.Entity;
                    if (item.HasComponent <EbayItemComponent>())
                    {
                        var ebayItemComponent = item.GetComponent <EbayItemComponent>();

                        var childView = new EntityView
                        {
                            Name        = "Ebay Marketplace Item",
                            UiHint      = "Flat",
                            Icon        = "market_stand",
                            DisplayRank = 200,
                            EntityId    = item.Id,
                            ItemId      = string.Empty
                        };
                        entityView.ChildViews.Add(childView);

                        childView.Properties.Add(
                            new ViewProperty
                        {
                            Name         = string.Empty,
                            IsHidden     = false,
                            IsReadOnly   = true,
                            OriginalType = "Html",
                            UiType       = "Html",
                            RawValue     = "<img alt='This is the alternate' height=50 width=100 src='https://www.paypalobjects.com/webstatic/en_AR/mktg/merchant/pages/sell-on-ebay/image-ebay.png' style=''/>"
                        });

                        childView.Properties.Add(
                            new ViewProperty
                        {
                            Name         = "EbayId",
                            IsHidden     = false,
                            IsReadOnly   = true,
                            UiType       = "Html",
                            OriginalType = "Html",
                            RawValue     = $"<a href='http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&item={ebayItemComponent.EbayId}&ssPageName=STRK:MESELX:IT&_trksid=p3984.m1558.l2649#ht_500wt_1157' target='_blank'>{ebayItemComponent.EbayId}</a> "
                        });

                        childView.Properties.Add(
                            new ViewProperty
                        {
                            Name       = "Status",
                            IsHidden   = false,
                            IsReadOnly = true,
                            RawValue   = ebayItemComponent.Status
                        });

                        if (ebayItemComponent.Status == "Ended")
                        {
                            childView.Properties.Add(
                                new ViewProperty
                            {
                                Name        = "ReasonEnded",
                                DisplayName = "Reason Ended",
                                IsHidden    = false,
                                IsReadOnly  = true,
                                RawValue    = ebayItemComponent.ReasonEnded
                            });
                        }

                        var history = "========================================<BR>";
                        foreach (var historyItem in ebayItemComponent.History)
                        {
                            history = history + $"{historyItem.EventDate.ToString("yyyy-MMM-dd hh:mm")}-{historyItem.EventMessage}-{historyItem.EventUser.Replace(@"sitecore\", "")}<BR>";
                        }

                        childView.Properties.Add(
                            new ViewProperty
                        {
                            Name         = "History",
                            IsHidden     = false,
                            IsReadOnly   = true,
                            UiType       = "Html",
                            OriginalType = "Html",
                            RawValue     = history
                        });

                        if (ebayItemComponent.Status == "Listed")
                        {
                            if (!string.IsNullOrEmpty(ebayItemComponent.EbayId))
                            {
                                var ebayItem = await _commerceCommander.Command <EbayCommand>().GetItem(context.CommerceContext, ebayItemComponent.EbayId);

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "EndTime",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = ebayItem.ListingDetails.EndTime
                                });

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "Sku",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = ebayItem.SKU
                                });

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "Price",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = new Money("USD", System.Convert.ToDecimal(ebayItem.StartPrice.Value))
                                });

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "Country",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = ebayItem.Country.ToString()
                                });

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "Currency",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = ebayItem.Currency.ToString()
                                });

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "Location",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = ebayItem.Location
                                });

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "ListingDuration",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = ebayItem.ListingDuration
                                });

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "Quantity",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = ebayItem.Quantity
                                });

                                childView.Properties.Add(
                                    new ViewProperty
                                {
                                    Name       = "PrimaryCategory",
                                    IsHidden   = false,
                                    IsReadOnly = true,
                                    RawValue   = ebayItem.PrimaryCategory.CategoryID
                                });

                                var ebayItemFeesView = new EntityView
                                {
                                    Name        = "Ebay Item Fees",
                                    UiHint      = "Flat",
                                    Icon        = "market_stand",
                                    DisplayRank = 200,
                                    EntityId    = item.Id,
                                    ItemId      = string.Empty
                                };
                                entityView.ChildViews.Add(ebayItemFeesView);

                                foreach (var fee in ebayItemComponent.Fees)
                                {
                                    ebayItemFeesView.Properties.Add(
                                        new ViewProperty
                                    {
                                        Name       = fee.Name,
                                        IsHidden   = false,
                                        IsReadOnly = true,
                                        RawValue   = fee.Adjustment
                                    });
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Ebay.DoActionEndItem.Exception: Message={ex.Message}");
                await context.CommerceContext.AddMessage("Error", "ItemEbayExtensions.Run.Exception", new object[] { ex }, ex.Message);
            }

            return(entityView);
        }