public ShipmentType(IDynamicPropertyResolverService dynamicPropertyResolverService)
        {
            Field(x => x.Id, nullable: true).Description("Shipment Id");
            Field(x => x.ShipmentMethodCode, nullable: true).Description("Shipment method code");
            Field(x => x.ShipmentMethodOption, nullable: true).Description("Shipment method option");
            Field(x => x.FulfillmentCenterId, nullable: true).Description("Fulfillment center id");
            ExtendableField <CartAddressType>("deliveryAddress",
                                              "Delivery address",
                                              resolve: context => context.Source.DeliveryAddress);
            Field(x => x.VolumetricWeight, nullable: true).Description("Value of volumetric weight");
            Field(x => x.WeightUnit, nullable: true).Description("Value of weight unit");
            Field(x => x.Weight, nullable: true).Description("Value of weight");
            Field(x => x.MeasureUnit, nullable: true).Description("Value of measurement units");
            Field(x => x.Height, nullable: true).Description("Value of height");
            Field(x => x.Length, nullable: true).Description("Value of length");
            Field(x => x.Width, nullable: true).Description("Value of width");
            Field <MoneyType>("price",
                              "Price",
                              resolve: context => context.Source.Price.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("priceWithTax",
                              "Price with tax",
                              resolve: context => context.Source.PriceWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("total",
                              "Total",
                              resolve: context => context.Source.Total.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("totalWithTax",
                              "Total with tax",
                              resolve: context => context.Source.TotalWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("discountAmount",
                              "Discount amount",
                              resolve: context => context.Source.DiscountAmount.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("discountAmountWithTax",
                              "Discount amount with tax",
                              resolve: context => context.Source.DiscountAmountWithTax.ToMoney(context.GetCart().Currency));
            Field <ListGraphType <CartShipmentItemType> >("items",
                                                          "Items",
                                                          resolve: context => context.Source.Items);
            Field <MoneyType>("taxTotal",
                              "Tax total",
                              resolve: context => context.Source.TaxTotal.ToMoney(context.GetCart().Currency));
            Field(x => x.TaxPercentRate, nullable: true).Description("Tax percent rate");
            Field(x => x.TaxType, nullable: true).Description("Tax type");
            Field <ListGraphType <TaxDetailType> >("taxDetails",
                                                   "Tax details",
                                                   resolve: context => context.Source.TaxDetails);
            Field <ListGraphType <DiscountType> >("discounts",
                                                  "Discounts",
                                                  resolve: context => context.Source.Discounts);
            Field <CurrencyType>("currency",
                                 "Currency",
                                 resolve: context => context.GetCart().Currency);

            ExtendableField <ListGraphType <DynamicPropertyValueType> >(
                "dynamicProperties",
                "Cart shipment dynamic property values",
                QueryArgumentPresets.GetArgumentForDynamicProperties(),
                context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source, context.GetArgumentOrValue <string>("cultureName")));
        }
        public PaymentType(IDynamicPropertyResolverService dynamicPropertyResolverService)
        {
            Field(x => x.Id, nullable: true).Description("Payment Id");
            Field(x => x.OuterId, nullable: true).Description("Value of payment outer id");
            Field(x => x.PaymentGatewayCode, nullable: true).Description("Value of payment gateway code");
            Field <CurrencyType>("currency",
                                 "Currency",
                                 resolve: context => context.GetCart().Currency);
            Field <MoneyType>("amount",
                              "Amount",
                              resolve: context => context.Source.Amount.ToMoney(context.GetCart().Currency));
            ExtendableField <CartAddressType>("billingAddress",
                                              "Billing address",
                                              resolve: context => context.Source.BillingAddress);
            Field <MoneyType>("price",
                              "Price",
                              resolve: context => context.Source.Price.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("priceWithTax",
                              "Price with tax",
                              resolve: context => context.Source.PriceWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("total",
                              "Total",
                              resolve: context => context.Source.Total.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("totalWithTax",
                              "Total with tax",
                              resolve: context => context.Source.TotalWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("discountAmount",
                              "Discount amount",
                              resolve: context => context.Source.DiscountAmount.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("discountAmountWithTax",
                              "Discount amount with tax",
                              resolve: context => context.Source.DiscountAmountWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("taxTotal",
                              "Tax total",
                              resolve: context => context.Source.TaxTotal.ToMoney(context.GetCart().Currency));
            Field(x => x.TaxPercentRate, nullable: true).Description("Tax percent rate");
            Field(x => x.TaxType, nullable: true).Description("Tax type");
            Field <ListGraphType <TaxDetailType> >("taxDetails",
                                                   "Tax details",
                                                   resolve: context => context.Source.TaxDetails);
            Field <ListGraphType <DiscountType> >("discounts",
                                                  "Discounts",
                                                  resolve: context => context.Source.Discounts);

            ExtendableField <ListGraphType <DynamicPropertyValueType> >(
                "dynamicProperties",
                "Cart payment dynamic property values",
                QueryArgumentPresets.GetArgumentForDynamicProperties(),
                context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source, context.GetArgumentOrValue <string>("cultureName")));
        }
Exemplo n.º 3
0
        public CartType(
            ICartAvailMethodsService cartAvailMethods,
            IDynamicPropertyResolverService dynamicPropertyResolverService,
            ICartValidationContextFactory cartValidationContextFactory)
        {
            Field(x => x.Cart.Id, nullable: true).Description("Shopping cart ID");
            Field(x => x.Cart.Name, nullable: false).Description("Shopping cart name");
            Field(x => x.Cart.Status, nullable: true).Description("Shopping cart status");
            Field(x => x.Cart.StoreId, nullable: true).Description("Shopping cart store ID");
            Field(x => x.Cart.ChannelId, nullable: true).Description("Shopping cart channel ID");
            Field <BooleanGraphType>("hasPhysicalProducts",
                                     "Has physical products",
                                     resolve: context => AbstractTypeFactory <CartHasPhysicalProductsSpecification> .TryCreateInstance().IsSatisfiedBy(context.Source.Cart));
            Field(x => x.Cart.IsAnonymous, nullable: true).Description("Displays whether the shopping cart is anonymous");
            //PT-5425: Add fields
            //Field(x => x.Customer, nullable: true).Description("Shopping cart user");
            Field(x => x.Cart.CustomerId, nullable: true).Description("Shopping cart user ID");
            Field(x => x.Cart.CustomerName, nullable: true).Description("Shopping cart user name");
            Field(x => x.Cart.OrganizationId, nullable: true).Description("Shopping cart organization ID");
            Field(x => x.Cart.IsRecuring, nullable: true).Description("Displays whether the shopping cart is recurring");
            Field(x => x.Cart.Comment, nullable: true).Description("Shopping cart text comment");
            Field(x => x.Cart.PurchaseOrderNumber, nullable: true).Description("Purchase order number");

            // Characteristics
            Field(x => x.Cart.VolumetricWeight, nullable: true).Description("Shopping cart volumetric weight value");
            Field(x => x.Cart.WeightUnit, nullable: true).Description("Shopping cart weight unit value");
            Field(x => x.Cart.Weight, nullable: true).Description("Shopping cart weight value");
            //PT-5425: Add fields
            //Field(x => x.MeasureUnit, nullable: true).Description("Shopping cart measurement unit value");
            //Field(x => x.Height, nullable: true).Description("Shopping cart height");
            //Field(x => x.Length, nullable: true).Description("Shopping cart length value");
            //Field(x => x.Width, nullable: true).Description("Shopping cart width value");

            // Money
            Field <MoneyType>("total",
                              "Shopping cart total",
                              resolve: context => context.Source.Cart.Total.ToMoney(context.Source.Currency));
            Field <MoneyType>("subTotal",
                              "Shopping cart subtotal",
                              resolve: context => context.Source.Cart.SubTotal.ToMoney(context.Source.Currency));
            Field <MoneyType>("subTotalWithTax",
                              "Subtotal with tax",
                              resolve: context => context.Source.Cart.SubTotalWithTax.ToMoney(context.Source.Currency));
            Field <MoneyType>("extendedPriceTotal",
                              "Total extended price",
                              resolve: context => context.Source.LineItems.Sum(i => i.ExtendedPrice).ToMoney(context.Source.Currency));
            Field <MoneyType>("extendedPriceTotalWithTax",
                              "Total extended price with tax",
                              resolve: context => context.Source.LineItems.Sum(i => i.ExtendedPriceWithTax).ToMoney(context.Source.Currency));
            Field <CurrencyType>("currency",
                                 "Currency",
                                 resolve: context => context.Source.Currency);
            Field <MoneyType>("taxTotal",
                              "Total tax",
                              resolve: context => context.Source.Cart.TaxTotal.ToMoney(context.Source.Currency));
            Field(x => x.Cart.TaxPercentRate, nullable: true).Description("Tax percentage");
            Field(x => x.Cart.TaxType, nullable: true).Description("Shipping tax type");
            Field <ListGraphType <TaxDetailType> >("taxDetails",
                                                   "Tax details",
                                                   resolve: context => context.Source.Cart.TaxDetails);
            Field <MoneyType>(nameof(ShoppingCart.Fee).ToCamelCase(), resolve: context => context.Source.Cart.Fee.ToMoney(context.Source.Currency));

            // Shipping
            Field <MoneyType>("shippingPrice",
                              "Shipping price",
                              resolve: context => context.Source.Cart.ShippingTotal.ToMoney(context.Source.Currency));
            Field <MoneyType>("shippingPriceWithTax",
                              "Shipping price with tax",
                              resolve: context => context.Source.Cart.ShippingTotalWithTax.ToMoney(context.Source.Currency));
            Field <MoneyType>("shippingTotal",
                              "Total shipping",
                              resolve: context => context.Source.Cart.ShippingTotal.ToMoney(context.Source.Currency));
            Field <MoneyType>("shippingTotalWithTax",
                              "Total shipping with tax",
                              resolve: context => context.Source.Cart.ShippingTotalWithTax.ToMoney(context.Source.Currency));
            ExtendableField <ListGraphType <ShipmentType> >("shipments",
                                                            "Shipments",
                                                            resolve: context => context.Source.Cart.Shipments);

            FieldAsync <ListGraphType <ShippingMethodType> >("availableShippingMethods", resolve: async context =>
            {
                var rates = await cartAvailMethods.GetAvailableShippingRatesAsync(context.Source);
                //store the pair ShippingMethodType and cart aggregate in the user context for future usage in the ShippingMethodType fields resolvers
                if (rates != null)
                {
                    rates.Apply(x => context.UserContext[x.GetCacheKey()] = context.Source);
                }
                return(rates);
            });

            // Payment
            Field <MoneyType>("paymentPrice",
                              "Payment price",
                              resolve: context => context.Source.Cart.PaymentTotal.ToMoney(context.Source.Currency));
            Field <MoneyType>("paymentPriceWithTax",
                              "Payment price with tax",
                              resolve: context => context.Source.Cart.PaymentTotalWithTax.ToMoney(context.Source.Currency));
            Field <MoneyType>("paymentTotal",
                              "Total payment",
                              resolve: context => context.Source.Cart.PaymentTotal.ToMoney(context.Source.Currency));
            Field <MoneyType>("paymentTotalWithTax",
                              "Total payment with tax",
                              resolve: context => context.Source.Cart.PaymentTotalWithTax.ToMoney(context.Source.Currency));
            ExtendableField <ListGraphType <PaymentType> >("payments",
                                                           "Payments",
                                                           resolve: context => context.Source.Cart.Payments);
            FieldAsync <ListGraphType <PaymentMethodType> >("availablePaymentMethods",
                                                            "Available payment methods",
                                                            resolve: async context =>
            {
                var methods = await cartAvailMethods.GetAvailablePaymentMethodsAsync(context.Source);
                //store the pair ShippingMethodType and cart aggregate in the user context for future usage in the ShippingMethodType fields resolvers
                if (methods != null)
                {
                    methods.Apply(x => context.UserContext[x.Id] = context.Source);
                }
                return(methods);
            });
            //PT-5425: Add fields
            //Field<ListGraphType<PaymentPlanType>>("paymentPlan", resolve: context => context.Source.PaymentPlan);

            //PT-5425: Add fields Extended money
            //Field<MoneyType>("extendedPriceTotal", resolve: context => context.Source.ExtendedPriceTotal);
            //Field<MoneyType>("extendedPriceTotalWithTax", resolve: context => context.Source.ExtendedPriceTotalWithTax);

            // Handling totals
            Field <MoneyType>("handlingTotal",
                              "Total handling",
                              resolve: context => context.Source.Cart.HandlingTotal.ToMoney(context.Source.Currency));
            Field <MoneyType>("handlingTotalWithTax",
                              "Total handling with tax",
                              resolve: context => context.Source.Cart.HandlingTotalWithTax.ToMoney(context.Source.Currency));

            // Discounts
            Field <MoneyType>("discountTotal",
                              "Total discount",
                              resolve: context => context.Source.Cart.DiscountTotal.ToMoney(context.Source.Currency));

            Field <MoneyType>("discountTotalWithTax",
                              "Total discount with tax",
                              resolve: context => context.Source.Cart.DiscountTotalWithTax.ToMoney(context.Source.Currency));

            Field <MoneyType>("subTotalDiscount",
                              "Subtotal discount",
                              resolve: context => context.Source.Cart.SubTotalDiscount.ToMoney(context.Source.Currency));

            Field <MoneyType>("subTotalDiscountWithTax",
                              "Subtotal discount with tax",
                              resolve: context => context.Source.Cart.SubTotalDiscountWithTax.ToMoney(context.Source.Currency));

            Field <ListGraphType <DiscountType> >("discounts",
                                                  "Discounts",
                                                  resolve: context => context.Source.Cart.Discounts);

            // Addresses
            ExtendableField <ListGraphType <CartAddressType> >("addresses",
                                                               "Addresses",
                                                               resolve: context => context.Source.Cart.Addresses);

            // Gifts
            FieldAsync <ListGraphType <GiftItemType> >("gifts", "Gifts", resolve: async context =>
            {
                var availableGifts = await cartAvailMethods.GetAvailableGiftsAsync(context.Source);
                return(availableGifts.Where(x => x.LineItemId != null));
            });
            FieldAsync <ListGraphType <GiftItemType> >("availableGifts", "Available Gifts", resolve: async context =>
                                                       await cartAvailMethods.GetAvailableGiftsAsync(context.Source)
                                                       );

            // Items
            ExtendableField <ListGraphType <LineItemType> >("items",
                                                            "Items",
                                                            resolve: context => context.Source.LineItems);

            Field <IntGraphType>("itemsCount",
                                 "Item count",
                                 resolve: context => context.Source.LineItems.Count());
            Field <IntGraphType>("itemsQuantity",
                                 "Quantity of items",
                                 resolve: context => context.Source.LineItems.Sum(x => x.Quantity));
            //PT-5425: Add fields
            //Field<LineItemType>("recentlyAddedItem", resolve: context => context.Source.Cart.RecentlyAddedItem);

            // Coupons
            Field <ListGraphType <CouponType> >("coupons",
                                                "Coupons",
                                                resolve: context => context.Source.Coupons);

            // Other
            ExtendableField <ListGraphType <DynamicPropertyValueType> >(
                "dynamicProperties",
                "Cart dynamic property values",
                QueryArgumentPresets.GetArgumentForDynamicProperties(),
                context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source.Cart, context.GetArgumentOrValue <string>("cultureName")));

            FieldAsync <BooleanGraphType>("isValid", "Shows whether the cart is valid",
                                          QueryArgumentPresets.GetArgumentsForCartValidator(),
                                          resolve: async context =>
            {
                var ruleSet = context.GetArgumentOrValue <string>("ruleSet");
                await EnsureThatCartValidatedAsync(context.Source, cartValidationContextFactory, ruleSet);
                return(context.Source.IsValid);
            },
                                          deprecationReason: "Deprecated, because of useless (no need to know validation state without details). Use validationErrors field."
                                          );

            FieldAsync <ListGraphType <ValidationErrorType> >("validationErrors", "A set of errors in case the cart is invalid",
                                                              QueryArgumentPresets.GetArgumentsForCartValidator(),
                                                              resolve: async context =>
            {
                var ruleSet = context.GetArgumentOrValue <string>("ruleSet");
                await EnsureThatCartValidatedAsync(context.Source, cartValidationContextFactory, ruleSet);
                return(context.Source.ValidationErrors.OfType <CartValidationError>());
            });
            Field(x => x.Cart.Type, nullable: true).Description("Shopping cart type");
        }
        public OrderShipmentType(IDynamicPropertyResolverService dynamicPropertyResolverService)
        {
            Field(x => x.Id);
            Field(x => x.OperationType);
            Field(x => x.ParentOperationId, true);
            Field(x => x.Number);
            Field(x => x.IsApproved);
            Field(x => x.Status, true);
            Field(x => x.Comment, true);
            Field(x => x.OuterId, true);
            Field(x => x.IsCancelled);
            Field(x => x.CancelledDate, true);
            Field(x => x.CancelReason, true);
            Field(x => x.ObjectType);

            Field(x => x.OrganizationId, true);
            Field(x => x.OrganizationName, true);
            Field(x => x.FulfillmentCenterId, true);
            Field(x => x.FulfillmentCenterName, true);
            Field(x => x.EmployeeId, true);
            Field(x => x.EmployeeName, true);
            Field(x => x.ShipmentMethodCode, true);
            Field(x => x.ShipmentMethodOption, true);
            Field <OrderShippingMethodType>(nameof(Shipment.ShippingMethod).ToCamelCase(), resolve: x => x.Source.ShippingMethod);
            Field(x => x.CustomerOrderId, true);
            Field(x => x.WeightUnit, true);
            Field(x => x.Weight, true);
            Field(x => x.MeasureUnit, true);
            Field(x => x.Height, true);
            Field(x => x.Length, true);
            Field(x => x.Width, true);
            ExtendableField <OrderAddressType>(nameof(Shipment.DeliveryAddress).ToCamelCase(), resolve: x => x.Source.DeliveryAddress);

            Field(x => x.TaxType, true);
            Field(x => x.TaxPercentRate);

            Field(x => x.TrackingNumber, true);
            Field(x => x.TrackingUrl, true);
            Field(x => x.DeliveryDate, true);

            Field <MoneyType>(nameof(Shipment.Price).ToCamelCase(), resolve: context => new Money(context.Source.Price, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(Shipment.PriceWithTax).ToCamelCase(), resolve: context => new Money(context.Source.PriceWithTax, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(Shipment.Total).ToCamelCase(), resolve: context => new Money(context.Source.Total, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(Shipment.TotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.TotalWithTax, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(Shipment.DiscountAmount).ToCamelCase(), resolve: context => new Money(context.Source.DiscountAmount, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(Shipment.DiscountAmountWithTax).ToCamelCase(), resolve: context => new Money(context.Source.DiscountAmountWithTax, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(Shipment.TaxTotal).ToCamelCase(), resolve: context => new Money(context.Source.TaxTotal, context.GetOrderCurrency()));
            Field <CurrencyType>(nameof(Shipment.Currency).ToCamelCase(), resolve: context => context.GetOrderCurrency());

            Field <NonNullGraphType <ListGraphType <OrderTaxDetailType> > >(nameof(Shipment.TaxDetails), resolve: x => x.Source.TaxDetails);
            Field <NonNullGraphType <ListGraphType <OrderShipmentItemType> > >(nameof(Shipment.Items), resolve: x => x.Source.Items);
            Field <NonNullGraphType <ListGraphType <OrderShipmentPackageType> > >(nameof(Shipment.Packages), resolve: x => x.Source.Packages);
            ExtendableField <NonNullGraphType <ListGraphType <PaymentInType> > >(nameof(Shipment.InPayments), resolve: x => x.Source.InPayments);
            Field <NonNullGraphType <ListGraphType <OrderDiscountType> > >(nameof(Shipment.Discounts), resolve: x => x.Source.Discounts);

            ExtendableField <ListGraphType <DynamicPropertyValueType> >(
                "dynamicProperties",
                "Customer order Shipment dynamic property values",
                QueryArgumentPresets.GetArgumentForDynamicProperties(),
                context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source, context.GetArgumentOrValue <string>("cultureName")));
        }
        public OrderLineItemType(IMediator mediator, IDataLoaderContextAccessor dataLoader, IDynamicPropertyResolverService dynamicPropertyResolverService)
        {
            Field(x => x.Id);
            Field(x => x.ProductType, true);
            Field(x => x.Name);
            Field(x => x.Comment, true);
            Field(x => x.ImageUrl, true);
            Field(x => x.IsGift, true);
            Field(x => x.ShippingMethodCode, true);
            Field(x => x.FulfillmentLocationCode, true);
            Field(x => x.FulfillmentCenterId, true);
            Field(x => x.FulfillmentCenterName, true);
            Field(x => x.OuterId, true);
            Field(x => x.WeightUnit, true);
            Field(x => x.Weight, true);
            Field(x => x.MeasureUnit, true);
            Field(x => x.Height, true);
            Field(x => x.Length, true);
            Field(x => x.Width, true);
            Field(x => x.IsCancelled);
            Field(x => x.CancelledDate, true);
            Field(x => x.CancelReason, true);
            Field(x => x.ObjectType);

            Field(x => x.CategoryId, true);
            Field(x => x.CatalogId);

            Field(x => x.Sku);
            Field(x => x.PriceId, true);
            Field <MoneyType>(nameof(LineItem.Price).ToCamelCase(), resolve: context => new Money(context.Source.Price, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.PriceWithTax).ToCamelCase(), resolve: context => new Money(context.Source.PriceWithTax, context.GetOrderCurrency()));
            Field(x => x.TaxType, true);
            Field(x => x.TaxPercentRate);
            Field(x => x.ReserveQuantity);
            Field(x => x.Quantity);
            Field(x => x.ProductId);

            Field <CurrencyType>(nameof(LineItem.Currency).ToCamelCase(), resolve: context => context.GetOrderCurrency());
            Field <MoneyType>(nameof(LineItem.DiscountAmount).ToCamelCase(), resolve: context => new Money(context.Source.DiscountAmount, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.DiscountAmountWithTax).ToCamelCase(), resolve: context => new Money(context.Source.DiscountAmountWithTax, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.DiscountTotal).ToCamelCase(), resolve: context => new Money(context.Source.DiscountTotal, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.DiscountTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.DiscountTotalWithTax, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.ExtendedPrice).ToCamelCase(), resolve: context => new Money(context.Source.ExtendedPrice, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.ExtendedPriceWithTax).ToCamelCase(), resolve: context => new Money(context.Source.ExtendedPriceWithTax, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.PlacedPrice).ToCamelCase(), resolve: context => new Money(context.Source.PlacedPrice, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.PlacedPriceWithTax).ToCamelCase(), resolve: context => new Money(context.Source.PlacedPriceWithTax, context.GetOrderCurrency()));
            Field <MoneyType>(nameof(LineItem.TaxTotal).ToCamelCase(), resolve: context => new Money(context.Source.TaxTotal, context.GetOrderCurrency()));
            Field <NonNullGraphType <ListGraphType <OrderTaxDetailType> > >(nameof(LineItem.TaxDetails), resolve: x => x.Source.TaxDetails);
            Field <NonNullGraphType <ListGraphType <OrderDiscountType> > >(nameof(LineItem.Discounts), resolve: x => x.Source.Discounts);

            var productField = new FieldType
            {
                Name     = "product",
                Type     = GraphTypeExtenstionHelper.GetActualType <ProductType>(),
                Resolver = new FuncFieldResolver <LineItem, IDataLoaderResult <ExpProduct> >(context =>
                {
                    var includeFields = context.SubFields.Values.GetAllNodesPaths();
                    var loader        = dataLoader.Context.GetOrAddBatchLoader <string, ExpProduct>("order_lineItems_products", async(ids) =>
                    {
                        //Get currencies and store only from one order.
                        //We intentionally ignore the case when there are ma be the orders with the different currencies and stores in the resulting set
                        var order   = context.GetValueForSource <CustomerOrderAggregate>().Order;
                        var request = new LoadProductsQuery
                        {
                            StoreId       = order.StoreId,
                            CurrencyCode  = order.Currency,
                            ObjectIds     = ids.ToArray(),
                            IncludeFields = includeFields.ToArray()
                        };
                        if (!context.UserContext.ContainsKey("storeId"))
                        {
                            context.UserContext.Add("storeId", order.StoreId);
                        }

                        var response = await mediator.Send(request);

                        return(response.Products.ToDictionary(x => x.Id));
                    });

                    return(loader.LoadAsync(context.Source.ProductId));
                })
            };

            AddField(productField);

            ExtendableField <ListGraphType <DynamicPropertyValueType> >(
                "dynamicProperties",
                "Customer order Line item dynamic property values",
                QueryArgumentPresets.GetArgumentForDynamicProperties(),
                context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source, context.GetArgumentOrValue <string>("cultureName")));
        }
        public CustomerOrderType(
            IDynamicPropertyResolverService dynamicPropertyResolverService,
            IPaymentMethodsSearchService paymentMethodsSearchService)
        {
            Field(x => x.Order.Id);
            Field(x => x.Order.OperationType);
            Field(x => x.Order.ParentOperationId, true);
            Field(x => x.Order.Number);
            Field(x => x.Order.IsApproved);
            Field(x => x.Order.Status, true);
            Field(x => x.Order.Comment, true);
            Field(x => x.Order.OuterId, true);
            Field(x => x.Order.IsCancelled);
            Field(x => x.Order.CancelledDate, true);
            Field(x => x.Order.CancelReason, true);
            Field(x => x.Order.ObjectType);
            Field(x => x.Order.CustomerId);
            Field(x => x.Order.CustomerName, true);
            Field(x => x.Order.ChannelId, true);
            Field(x => x.Order.StoreId);
            Field(x => x.Order.StoreName, true);
            Field(x => x.Order.OrganizationId, true);
            Field(x => x.Order.OrganizationName, true);
            Field(x => x.Order.EmployeeId, true);
            Field(x => x.Order.EmployeeName, true);
            Field(x => x.Order.ShoppingCartId, true);
            Field(x => x.Order.IsPrototype);
            Field(x => x.Order.SubscriptionNumber, true);
            Field(x => x.Order.SubscriptionId, true);
            Field <MoneyType>(nameof(CustomerOrder.Fee).ToCamelCase(), resolve: context => context.Source.Order.Fee.ToMoney(context.Source.Currency));
            Field(x => x.Order.PurchaseOrderNumber, true);
            Field(x => x.Order.FeeWithTax);
            Field(x => x.Order.FeeTotal);
            Field(x => x.Order.FeeTotalWithTax);
            Field(x => x.Order.TaxType, true);

            Field(x => x.Order.TaxPercentRate);
            Field(x => x.Order.LanguageCode, true);
            Field(x => x.Order.CreatedDate);
            Field(x => x.Order.CreatedBy, true);
            Field(x => x.Order.ModifiedDate, true);
            Field(x => x.Order.ModifiedBy, true);

            Field <CurrencyType>(nameof(CustomerOrder.Currency).ToCamelCase(), resolve: context => context.Source.Currency);
            Field <MoneyType>(nameof(CustomerOrder.Total).ToCamelCase(), resolve: context => new Money(context.Source.Order.Total, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.TaxTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.TaxTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.DiscountAmount).ToCamelCase(), resolve: context => new Money(context.Source.Order.DiscountAmount, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.SubTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.SubTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.SubTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.SubTotalWithTax, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.SubTotalDiscount).ToCamelCase(), resolve: context => new Money(context.Source.Order.SubTotalDiscount, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.SubTotalDiscountWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.SubTotalDiscountWithTax, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.SubTotalTaxTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.SubTotalTaxTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.ShippingTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.ShippingTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.ShippingTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.ShippingTotalWithTax, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.ShippingSubTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.ShippingSubTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.ShippingSubTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.ShippingSubTotalWithTax, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.ShippingDiscountTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.ShippingDiscountTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.ShippingDiscountTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.ShippingDiscountTotalWithTax, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.ShippingTaxTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.ShippingTaxTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.PaymentTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.PaymentTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.PaymentTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.PaymentTotalWithTax, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.PaymentSubTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.PaymentSubTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.PaymentSubTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.PaymentSubTotalWithTax, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.PaymentDiscountTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.PaymentDiscountTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.PaymentDiscountTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.PaymentDiscountTotalWithTax, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.PaymentTaxTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.PaymentTaxTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.DiscountTotal).ToCamelCase(), resolve: context => new Money(context.Source.Order.DiscountTotal, context.Source.Currency));
            Field <MoneyType>(nameof(CustomerOrder.DiscountTotalWithTax).ToCamelCase(), resolve: context => new Money(context.Source.Order.DiscountTotalWithTax, context.Source.Currency));

            ExtendableField <NonNullGraphType <ListGraphType <OrderAddressType> > >(nameof(CustomerOrder.Addresses), resolve: x => x.Source.Order.Addresses);
            ExtendableField <NonNullGraphType <ListGraphType <OrderLineItemType> > >(nameof(CustomerOrder.Items), resolve: x => x.Source.Order.Items);
            ExtendableField <NonNullGraphType <ListGraphType <PaymentInType> > >(nameof(CustomerOrder.InPayments),
                                                                                 arguments: new QueryArguments(
                                                                                     new QueryArgument <IntGraphType> {
                Name = "after"
            },
                                                                                     new QueryArgument <IntGraphType> {
                Name = "first"
            },
                                                                                     new QueryArgument <StringGraphType> {
                Name = "sort"
            }
                                                                                     ),
                                                                                 resolve: x =>
            {
                var skip = x.GetArgument("after", 0);
                var take = x.GetArgument("first", 20);
                var sort = x.GetArgument <string>("sort");

                var payments  = x.Source.Order.InPayments ?? new List <PaymentIn>();
                var queryable = payments.AsQueryable();

                if (!string.IsNullOrEmpty(sort))
                {
                    var sortInfos = SortInfo.Parse(sort).ToList();
                    queryable     = queryable.OrderBySortInfos(sortInfos);
                }

                queryable = queryable.Skip(skip).Take(take);

                var result = queryable.ToList();
                return(result);
            });

            ExtendableField <ListGraphType <OrderShipmentType> >(nameof(CustomerOrder.Shipments), resolve: x => x.Source.Order.Shipments);

            Field <NonNullGraphType <ListGraphType <OrderTaxDetailType> > >(nameof(CustomerOrder.TaxDetails), resolve: x => x.Source.Order.TaxDetails);

            ExtendableField <ListGraphType <DynamicPropertyValueType> >(
                "dynamicProperties",
                "Customer order dynamic property values",
                QueryArgumentPresets.GetArgumentForDynamicProperties(),
                context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source.Order, context.GetArgumentOrValue <string>("cultureName")));

            ExtendableField <ListGraphType <StringGraphType> >("coupons", resolve: x => x.Source.GetCustomerOrderCoupons());

            ExtendableField <ListGraphType <OrderDiscountType> >("discounts", resolve: x => x.Source.Order.Discounts);

            FieldAsync <ListGraphType <OrderPaymentMethodType> >("availablePaymentMethods",
                                                                 "Available payment methods",
                                                                 resolve: async context =>
            {
                var criteria = new PaymentMethodsSearchCriteria
                {
                    IsActive = true,
                    StoreId  = context.Source.Order.StoreId,
                };

                var searchService = (ISearchService <PaymentMethodsSearchCriteria, PaymentMethodsSearchResult, PaymentMethod>)paymentMethodsSearchService;
                var result        = await searchService.SearchAsync(criteria);

                result.Results?.Apply(x => context.UserContext[x.Id] = context.Source);

                return(result.Results);
            });
        }
Exemplo n.º 7
0
        public PaymentInType(IDynamicPropertyResolverService dynamicPropertyResolverService, ICustomerOrderAggregateRepository customerOrderAggregateRepository)
        {
            Field(x => x.Id);
            Field(x => x.OrganizationId, true);
            Field(x => x.OrganizationName, true);
            Field(x => x.CustomerName, true);
            Field(x => x.CustomerId);
            Field(x => x.Purpose, true);
            Field(x => x.GatewayCode, true);
            Field(x => x.IncomingDate, true);
            Field(x => x.OuterId, true);
            Field(x => x.OperationType);
            Field(x => x.Number);
            Field(x => x.IsApproved);
            Field(x => x.Status, true);
            Field(x => x.Comment, true);
            Field(x => x.IsCancelled);
            Field(x => x.CancelledDate, true);
            Field(x => x.CancelReason, true);
            Field(x => x.ParentOperationId, true);
            Field(x => x.ObjectType);
            Field(x => x.CreatedDate);
            Field(x => x.ModifiedDate, true);
            Field(x => x.CreatedBy, true);
            Field(x => x.ModifiedBy, true);
            Field(x => x.AuthorizedDate, true);
            Field(x => x.CapturedDate, true);
            Field(x => x.VoidedDate, true);
            Field(x => x.OrderId, true);

            Field <MoneyType>(nameof(PaymentIn.Price).ToCamelCase(), resolve: context => new Money(context.Source.Price, context.GetOrderCurrencyByCode(context.Source.Currency)));
            Field <MoneyType>(nameof(PaymentIn.Sum).ToCamelCase(), resolve: context => new Money(context.Source.Sum, context.GetOrderCurrencyByCode(context.Source.Currency)));
            Field <MoneyType>("tax", resolve: context => new Money(context.Source.TaxTotal, context.GetOrderCurrencyByCode(context.Source.Currency)));
            ExtendableField <OrderPaymentMethodType>(nameof(PaymentIn.PaymentMethod), resolve: context => context.Source.PaymentMethod);
            Field <CurrencyType>(nameof(PaymentIn.Currency), resolve: context => context.GetOrderCurrencyByCode(context.Source.Currency));
            ExtendableField <OrderAddressType>(nameof(PaymentIn.BillingAddress), resolve: context => context.Source.BillingAddress);

            Field <ListGraphType <PaymentTransactionType> >(nameof(PaymentIn.Transactions), resolve: x => x.Source.Transactions);
            //PT-5383: Add additional properties to XOrder types:
            //public IList<Operation> ChildrenOperations);

            ExtendableField <NonNullGraphType <CustomerOrderType> >(
                "order",
                "Associated Order",
                null,
                context =>
            {
                if (!string.IsNullOrEmpty(context.Source.OrderId))
                {
                    return(customerOrderAggregateRepository.GetOrderByIdAsync(context.Source.OrderId));
                }

                return(null);
            }
                );

            ExtendableField <ListGraphType <DynamicPropertyValueType> >(
                "dynamicProperties",
                "Customer order Payment dynamic property values",
                QueryArgumentPresets.GetArgumentForDynamicProperties(),
                context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source, context.GetArgumentOrValue <string>("cultureName")));
        }
        public LineItemType(IMediator mediator, IDataLoaderContextAccessor dataLoader, IDynamicPropertyResolverService dynamicPropertyResolverService)
        {
            var productField = new FieldType
            {
                Name     = "product",
                Type     = GraphTypeExtenstionHelper.GetActualType <ProductType>(),
                Resolver = new FuncFieldResolver <LineItem, IDataLoaderResult <ExpProduct> >(context =>
                {
                    var includeFields = context.SubFields.Values.GetAllNodesPaths();
                    var loader        = dataLoader.Context.GetOrAddBatchLoader <string, ExpProduct>("order_lineItems_products", async(ids) =>
                    {
                        //Get currencies and store only from one cart.
                        //We intentionally ignore the case when there are ma be the carts with the different currencies and stores in the resulting set
                        var cart    = context.GetValueForSource <CartAggregate>().Cart;
                        var request = new LoadProductsQuery
                        {
                            StoreId       = cart.StoreId,
                            CurrencyCode  = cart.Currency,
                            ObjectIds     = ids.ToArray(),
                            IncludeFields = includeFields.ToArray()
                        };

                        var response = await mediator.Send(request);

                        return(response.Products.ToDictionary(x => x.Id));
                    });
                    return(loader.LoadAsync(context.Source.ProductId));
                })
            };

            AddField(productField);

            //Field<MoneyType>("paymentPlan", resolve: context => context.Source.PaymentPlan);
            Field <IntGraphType>("inStockQuantity",
                                 "In stock quantity",
                                 resolve: context => context.GetCart().CartProducts[context.Source.ProductId]?.AvailableQuantity ?? 0);
            Field <StringGraphType>("warehouseLocation",
                                    "Warehouse location",
                                    resolve: context => context.GetCart().CartProducts[context.Source.ProductId]?.Inventory?.FulfillmentCenter?.Address?.ToString());

            Field <BooleanGraphType>("IsValid",
                                     "Shows whether this is valid",
                                     resolve: context => !context.GetCart().ValidationErrors.GetEntityCartErrors(context.Source).Any());
            Field <ListGraphType <ValidationErrorType> >("validationErrors",
                                                         "Validation errors",
                                                         resolve: context => context.GetCart().ValidationErrors.GetEntityCartErrors(context.Source));

            Field(x => x.CatalogId, nullable: true).Description("Catalog ID value");
            Field(x => x.CategoryId, nullable: true).Description("Category ID value");
            Field(x => x.CreatedDate, nullable: true).Description("Line item create date");
            Field(x => x.Height, nullable: true).Description("Height value");
            Field(x => x.Id, nullable: false).Description("Line item ID");
            Field(x => x.ImageUrl, nullable: true).Description("Value of line item image absolute URL");
            Field(x => x.IsGift, nullable: true).Description("flag of line item is a gift");
            Field(x => x.IsReadOnly, nullable: true).Description("Shows whether this is read-only");
            Field(x => x.IsReccuring, nullable: true).Description("Shows whether the line item is recurring");
            Field(x => x.LanguageCode, nullable: true).Description("Culture name in the ISO 3166-1 alpha-3 format");
            Field(x => x.Length, nullable: true).Description("Length value");
            Field(x => x.MeasureUnit, nullable: true).Description("Measurement unit value");
            Field(x => x.Name, nullable: true).Description("Line item name value");
            Field(x => x.Note, nullable: true).Description("Line item comment value");
            Field(x => x.ObjectType, nullable: true).Description("Line item quantity value");
            Field(x => x.ProductId, nullable: true).Description("Product ID value");
            Field(x => x.ProductType, nullable: true).Description("Product type: Physical, Digital, or Subscription");
            Field(x => x.Quantity, nullable: true).Description("Line item quantity value");
            Field(x => x.RequiredShipping, nullable: true).Description("Requirement for line item shipping");
            Field(x => x.ShipmentMethodCode, nullable: true).Description("Line item shipping method code value");
            Field(x => x.Sku, nullable: true).Description("Product SKU value");
            Field(x => x.TaxPercentRate, nullable: true).Description("Total shipping tax amount value");
            Field(x => x.TaxType, nullable: true).Description("Shipping tax type value");
            Field(x => x.ThumbnailImageUrl, nullable: true).Description("Value of line item thumbnail image absolute URL");
            Field(x => x.VolumetricWeight, nullable: true).Description("Volumetric weight value");
            Field(x => x.Weight, nullable: true).Description("Shopping cart weight value");
            Field(x => x.WeightUnit, nullable: true).Description("Weight unit value");
            Field(x => x.Width, nullable: true).Description("Width value");
            Field(x => x.FulfillmentCenterId, nullable: true).Description("Line item fulfillment center ID value");
            Field(x => x.FulfillmentCenterName, nullable: true).Description("Line item fulfillment center name value");
            Field <ListGraphType <DiscountType> >("discounts",
                                                  "Discounts",
                                                  resolve: context => context.Source.Discounts);
            Field <ListGraphType <TaxDetailType> >("taxDetails",
                                                   "Tax details",
                                                   resolve: context => context.Source.TaxDetails);
            Field <MoneyType>("discountAmount",
                              "Discount amount",
                              resolve: context => context.Source.DiscountAmount.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("discountAmountWithTax",
                              "Discount amount with tax",
                              resolve: context => context.Source.DiscountAmountWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("discountTotal",
                              "Total discount",
                              resolve: context => context.Source.DiscountTotal.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("discountTotalWithTax",
                              "Total discount with tax",
                              resolve: context => context.Source.DiscountTotalWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("extendedPrice",
                              "Extended price",
                              resolve: context => context.Source.ExtendedPrice.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("extendedPriceWithTax",
                              "Extended price with tax",
                              resolve: context => context.Source.ExtendedPriceWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("listPrice",
                              "List price",
                              resolve: context => context.Source.ListPrice.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("listPriceWithTax",
                              "List price with tax",
                              resolve: context => context.Source.ListPriceWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("placedPrice",
                              "Placed price",
                              resolve: context => context.Source.PlacedPrice.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("placedPriceWithTax",
                              "Placed price with tax",
                              resolve: context => context.Source.PlacedPriceWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("salePrice",
                              "Sale price",
                              resolve: context => context.Source.SalePrice.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("salePriceWithTax",
                              "Sale price with tax",
                              resolve: context => context.Source.SalePriceWithTax.ToMoney(context.GetCart().Currency));
            Field <MoneyType>("taxTotal",
                              "Tax total",
                              resolve: context => context.Source.TaxTotal.ToMoney(context.GetCart().Currency));

            ExtendableField <ListGraphType <DynamicPropertyValueType> >(
                "dynamicProperties",
                "Cart line item dynamic property values",
                QueryArgumentPresets.GetArgumentForDynamicProperties(),
                context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source, context.GetArgumentOrValue <string>("cultureName")));
        }