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

            if (entityView.Name != context.GetPolicy <CartUiPolicy>().RemoveGiftCardPaymentActionName)
            {
                return(entityView);
            }

            var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

            var paymentComponent = cart.GetComponent <GiftCardPaymentComponent>();

            try
            {
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "GiftCard Id",
                    IsHidden   = true,
                    IsRequired = true,
                    RawValue   = string.IsNullOrEmpty(paymentComponent.GiftCardCode) ? string.Empty : paymentComponent.GiftCardCode
                });
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
            }

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

            if (entityView.Name != context.GetPolicy <CartUiPolicy>().EditLineItemActionName)
            {
                return(entityView);
            }

            var entityViewArgument = this._commerceCommander.Command <ViewCommander>().CurrentEntityViewArgument(context.CommerceContext);
            var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

            var line = cart.Lines.FirstOrDefault(element => element.ItemId.Equals(entityView.ItemId));

            try
            {
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name         = "Quantity",
                    IsHidden     = false,
                    IsRequired   = true,
                    RawValue     = line.Quantity,
                    OriginalType = "System.int"
                });
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            if (entityView == null ||
                !entityView.Action.Equals(context.GetPolicy <CartUiPolicy>().RemoveVoucherActionName, StringComparison.OrdinalIgnoreCase))
            {
                return(entityView);
            }

            try
            {
                var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

                if (cart == null || cart.DateCreated == cart.DateUpdated)
                {
                    return(entityView);
                }

                var voucherIdProperty = entityView.Properties[1];

                await _removeCouponCommand.Process(context.CommerceContext, entityView.EntityId, voucherIdProperty.Value);
            }

            catch (Exception ex)
            {
                context.Logger.LogError($"{this.Name}.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }
Exemple #4
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            if (entityView == null ||
                !entityView.Action.Equals(context.GetPolicy <CartUiPolicy>().RemoveLineItemActionName, StringComparison.OrdinalIgnoreCase))
            {
                return(entityView);
            }

            try
            {
                var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

                if (cart == null || cart.DateCreated == cart.DateUpdated)
                {
                    return(entityView);
                }

                var line = cart.Lines.FirstOrDefault(element => element.ItemId.Equals(entityView.ItemId));

                cart = await _removeCartLineCommand.Process(context.CommerceContext, entityView.EntityId, line);
            }

            catch (Exception ex)
            {
                context.Logger.LogError($"{this.Name}.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }
Exemple #5
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            if (entityView == null ||
                !entityView.Action.Equals(context.GetPolicy <CartUiPolicy>().AddPhysicalFulfillmentActionName, StringComparison.OrdinalIgnoreCase))
            {
                return(entityView);
            }

            try
            {
                var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

                if (cart == null || cart.DateCreated == cart.DateUpdated)
                {
                    return(entityView);
                }

                var addressName = entityView.Properties[1];
                var firstName   = entityView.Properties[2];
                var lastName    = entityView.Properties[3];
                var city        = entityView.Properties[4];
                var address1    = entityView.Properties[5];
                var country     = entityView.Properties[6];
                var zipCode     = entityView.Properties[7];
                var stateCode   = entityView.Properties[8];
                var id          = entityView.Properties[9];

                var physicalFulfillmentComponent = new PhysicalFulfillmentComponent()
                {
                    Name          = addressName.Value,
                    Id            = string.IsNullOrEmpty(id.Value) ? Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture) : id.Value,
                    ShippingParty = new Party()
                    {
                        AddressName   = addressName.Value,
                        FirstName     = firstName.Value,
                        LastName      = lastName.Value,
                        Address1      = address1.Value,
                        City          = city.Value,
                        Country       = country.Value,
                        ZipPostalCode = zipCode.Value,
                        StateCode     = stateCode.Value
                    },
                    FulfillmentMethod = new EntityReference()
                    {
                        EntityTarget = "B146622D-DC86-48A3-B72A-05EE8FFD187A",
                        Name         = "Ground"
                    }
                };

                await _setCartFulfillmentCommand.Process(context.CommerceContext, entityView.EntityId, physicalFulfillmentComponent);
            }

            catch (Exception ex)
            {
                context.Logger.LogError($"{this.Name}.PathNotFound: Message={ex.Message}");
            }

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

            if (entityView.Name != context.GetPolicy <CartUiPolicy>().RemoveLineItemActionName)
            {
                return(entityView);
            }

            var entityViewArgument = this._commerceCommander.Command <ViewCommander>().CurrentEntityViewArgument(context.CommerceContext);
            var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

            string[] cartLineInformation = entityView.ItemId.Split('|');
            try
            {
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Cart",
                    IsHidden   = true,
                    IsRequired = true,
                    RawValue   = cart.Id
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Catalog",
                    IsHidden   = true,
                    IsRequired = true,
                    RawValue   = cartLineInformation[0]
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "ProductID",
                    IsHidden   = true,
                    IsRequired = true,
                    RawValue   = cartLineInformation[1]
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "VariantID",
                    IsHidden   = true,
                    IsRequired = true,
                    RawValue   = cartLineInformation[2]
                });
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
            }

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

            if (string.IsNullOrEmpty(entityView.EntityId))
            {
                return(entityView);
            }

            var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

            if (cart == null || cart.DateCreated == cart.DateUpdated)
            {
                return(entityView);
            }

            if (!string.IsNullOrEmpty(entityView.Action))
            {
                return(entityView);
            }

            var entityViewArgument = _viewCommander.CurrentEntityViewArgument(context.CommerceContext);

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

            entityView.UiHint = "Flat";
            entityView.Icon   = pluginPolicy.Icon;

            var name = entityView.EntityId;

            try
            {
                entityViewArgument.Entity = cart;

                this.AddTotalsView(entityView, context.CommerceContext, cart);
                this.AddAdjustmentsView(entityView, context.CommerceContext, cart);
                this.AddLineItemView(entityView, context.CommerceContext, cart);
                this.AddVoucherView(entityView, context.CommerceContext, cart);
                this.AddFulfillmentView(entityView, context.CommerceContext, cart);
                this.AddPaymentView(entityView, context.CommerceContext, cart);
                this.AddContactView(entityView, context.CommerceContext, cart);
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }
Exemple #8
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            if (entityView == null ||
                !entityView.Action.Equals(context.GetPolicy <CartUiPolicy>().AddGiftCardPaymentActionName, StringComparison.OrdinalIgnoreCase))
            {
                return(entityView);
            }

            try
            {
                var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

                if (cart == null || cart.DateCreated == cart.DateUpdated)
                {
                    return(entityView);
                }

                var     giftCardCodeProperty = entityView.Properties[1];
                var     amountProperty       = entityView.Properties[2];
                decimal amount = !string.IsNullOrEmpty(amountProperty.Value) ? decimal.Parse(amountProperty.Value) : cart.Totals.GrandTotal.Amount;

                var paymentComponent = new GiftCardPaymentComponent()
                {
                    PaymentMethod = new EntityReference()
                    {
                        Name         = "GiftCard",
                        EntityTarget = "B5E5464E-C851-4C3C-8086-A4A874DD2DB0"
                    },
                    GiftCardCode = giftCardCodeProperty.Value,
                    Amount       = new Money(amount)
                };

                await _addPaymentsCommand.Process(context.CommerceContext, entityView.EntityId, new List <PaymentComponent>()
                {
                    paymentComponent
                });
            }

            catch (Exception ex)
            {
                context.Logger.LogError($"{this.Name}.PathNotFound: Message={ex.Message}");
            }

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

            if (entityView.Name != context.GetPolicy <CartUiPolicy>().RemoveVoucherActionName)
            {
                return(entityView);
            }

            var entityViewArgument = this._commerceCommander.Command <ViewCommander>().CurrentEntityViewArgument(context.CommerceContext);
            var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

            var couponComponent = cart.GetComponent <CartCouponsComponent>();

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

            var foundcoupon = couponComponent.List.FirstOrDefault(element => element.Promotion.EntityTarget.Equals(entityView.ItemId));

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

            try
            {
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Voucher ID",
                    IsHidden   = true,
                    IsRequired = true,
                    RawValue   = foundcoupon.CouponId
                });
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            if (entityView == null ||
                !entityView.Action.Equals(context.GetPolicy <CartUiPolicy>().RemoveGiftCardPaymentActionName, StringComparison.OrdinalIgnoreCase))
            {
                return(entityView);
            }

            try
            {
                var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

                if (cart == null || cart.DateCreated == cart.DateUpdated)
                {
                    return(entityView);
                }

                var giftCardCodeProperty  = entityView.Properties[1];
                var giftCardCodeFormValue = giftCardCodeProperty.Value;
                var paymentComponent      = cart.GetComponent <GiftCardPaymentComponent>();
                if (!paymentComponent.GiftCardCode.Equals(giftCardCodeFormValue))
                {
                    return(entityView);
                }

                await _removePaymentsCommand.Process(context.CommerceContext, entityView.EntityId, new List <PaymentComponent>()
                {
                    paymentComponent
                });
            }

            catch (Exception ex)
            {
                context.Logger.LogError($"{this.Name}.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            if (entityView == null ||
                !entityView.Action.Equals(context.GetPolicy <CartUiPolicy>().AddLineItemActionName, StringComparison.OrdinalIgnoreCase))
            {
                return(entityView);
            }

            try
            {
                var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

                if (cart == null || cart.DateCreated == cart.DateUpdated)
                {
                    return(entityView);
                }

                var catalog   = entityView.Properties[1];
                var productId = entityView.Properties[2];
                var variantId = entityView.Properties[3];
                var quantity  = entityView.Properties[4];

                cart = await _addCartLineCommand.Process(context.CommerceContext, entityView.EntityId, new CartLineComponent()
                {
                    ItemId   = string.Join("|", catalog.Value, productId.Value, variantId.Value),
                    Quantity = int.Parse(quantity.Value)
                });
            }

            catch (Exception ex)
            {
                context.Logger.LogError($"{this.Name}.PathNotFound: Message={ex.Message}");
            }

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

            if (entityView.Name != context.GetPolicy <CartUiPolicy>().AddPhysicalFulfillmentActionName)
            {
                return(entityView);
            }

            var cart = await _getCartCommand.Process(context.CommerceContext, entityView.EntityId, false);

            var physicalFulfillment = cart.GetComponent <PhysicalFulfillmentComponent>();

            try
            {
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Address Name",
                    IsHidden   = false,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.ShippingParty?.AddressName
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "First Name",
                    IsHidden   = false,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.ShippingParty?.FirstName
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Last Name",
                    IsHidden   = false,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.ShippingParty?.LastName
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "City",
                    IsHidden   = false,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.ShippingParty?.City
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Street & House Number",
                    IsHidden   = false,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.ShippingParty?.Address1
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Country Code",
                    IsHidden   = false,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.ShippingParty?.Country
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Zip Code",
                    IsHidden   = false,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.ShippingParty?.ZipPostalCode
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "State Code",
                    IsHidden   = false,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.ShippingParty?.StateCode
                });
                entityView.Properties.Add(
                    new ViewProperty
                {
                    Name       = "Id",
                    IsHidden   = true,
                    IsRequired = true,
                    RawValue   = physicalFulfillment.Id
                });
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Content.SynchronizeContentPath.PathNotFound: Message={ex.Message}");
            }

            return(entityView);
        }