Ejemplo n.º 1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            object retVal = null;
            var    obj    = JObject.Load(reader);

            if (typeof(Store).IsAssignableFrom(objectType))
            {
                retVal = AbstractTypeFactory <Store> .TryCreateInstance();
            }
            else if (typeof(StoreSearchCriteria).IsAssignableFrom(objectType))
            {
                retVal = AbstractTypeFactory <StoreSearchCriteria> .TryCreateInstance();
            }
            else if (objectType == typeof(PaymentMethod))
            {
                var paymentGatewayCode = obj["code"].Value <string>();
                retVal = _paymentMethodsService.GetAllPaymentMethods().FirstOrDefault(x => x.Code.EqualsInvariant(paymentGatewayCode));
            }
            else if (objectType == typeof(ShippingMethod))
            {
                var shippingGatewayCode = obj["code"].Value <string>();
                retVal = _shippingMethodsService.GetAllShippingMethods().FirstOrDefault(x => x.Code.EqualsInvariant(shippingGatewayCode));
            }
            else if (objectType == typeof(TaxProvider))
            {
                var taxProviderCode = obj["code"].Value <string>();
                retVal = _taxService.GetAllTaxProviders().FirstOrDefault(x => x.Code.EqualsInvariant(taxProviderCode));
            }
            serializer.Populate(obj.CreateReader(), retVal);
            return(retVal);
        }
Ejemplo n.º 2
0
 private void PopulateStore(Store store, StoreEntity dbStore)
 {
     //Return all registered methods with store settings
     store.PaymentMethods = _paymentMethodRegistrar.GetAllPaymentMethods();
     foreach (var paymentMethod in store.PaymentMethods)
     {
         var dbStoredPaymentMethod = dbStore.PaymentMethods.FirstOrDefault(x => x.Code.EqualsInvariant(paymentMethod.Code));
         if (dbStoredPaymentMethod != null)
         {
             dbStoredPaymentMethod.ToModel(paymentMethod);
         }
     }
     store.ShippingMethods = _shippingMethodRegistrar.GetAllShippingMethods();
     foreach (var shippingMethod in store.ShippingMethods)
     {
         var dbStoredShippingMethod = dbStore.ShippingMethods.FirstOrDefault(x => x.Code.EqualsInvariant(shippingMethod.Code));
         if (dbStoredShippingMethod != null)
         {
             dbStoredShippingMethod.ToModel(shippingMethod);
         }
     }
     store.TaxProviders = _taxProviderRegistrar.GetAllTaxProviders();
     foreach (var taxProvider in store.TaxProviders)
     {
         var dbStoredTaxProvider = dbStore.TaxProviders.FirstOrDefault(x => x.Code.EqualsInvariant(taxProvider.Code));
         if (dbStoredTaxProvider != null)
         {
             dbStoredTaxProvider.ToModel(taxProvider);
         }
     }
 }
Ejemplo n.º 3
0
        protected virtual void LoadOrderDependencies(CustomerOrder order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }
            var shippingMethods = _shippingMethodsRegistrar.GetAllShippingMethods();

            if (!shippingMethods.IsNullOrEmpty())
            {
                foreach (var shipment in order.Shipments)
                {
                    shipment.ShippingMethod = shippingMethods.FirstOrDefault(x => x.Code.EqualsInvariant(shipment.ShipmentMethodCode));
                }
            }
            var paymentMethods = _paymentMethodsRegistrar.GetAllPaymentMethods();

            if (!paymentMethods.IsNullOrEmpty())
            {
                foreach (var payment in order.InPayments)
                {
                    payment.PaymentMethod = paymentMethods.FirstOrDefault(x => x.Code.EqualsInvariant(payment.GatewayCode));
                }
            }
        }
Ejemplo n.º 4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            object retVal;
            var    obj = JObject.Load(reader);

            if (objectType == typeof(PaymentMethod))
            {
                var paymentGatewayCode = obj["code"].Value <string>();
                retVal = _paymentMethodsRegistrar.GetAllPaymentMethods().FirstOrDefault(x => x.Code.EqualsInvariant(paymentGatewayCode));
            }
            else if (objectType == typeof(ShippingMethod))
            {
                var shippingGatewayCode = obj["code"].Value <string>();
                retVal = _shippingMethodsRegistrar.GetAllShippingMethods().FirstOrDefault(x => x.Code.EqualsInvariant(shippingGatewayCode));
            }
            else
            {
                var tryCreateInstance = typeof(AbstractTypeFactory <>).MakeGenericType(objectType).GetMethods().FirstOrDefault(x => x.Name.EqualsInvariant("TryCreateInstance") && x.GetParameters().Length == 0);
                retVal = tryCreateInstance?.Invoke(null, null);
            }
            //Reset ChildrenOperations property to prevent polymorphic deserialization  error
            var operation = retVal as IOperation;

            if (operation != null)
            {
                obj.Remove("childrenOperations");
                obj.Remove("ChildrenOperations");
            }

            var payment = operation as PaymentIn;

            if (payment != null)
            {
                var paymentStatus  = (obj["paymentStatus"] ?? obj["PaymentStatus"]).Value <string>();
                var hasStatusValue = Enum.IsDefined(typeof(PaymentStatus), paymentStatus);
                if (!hasStatusValue)
                {
                    obj["paymentStatus"] = PaymentStatus.Custom.ToString();
                }
            }

            serializer.Populate(obj.CreateReader(), retVal);
            return(retVal);
        }