public override OrderOperation ToModel(OrderOperation operation)
        {
            var order = operation as CustomerOrder;

            if (order == null)
            {
                throw new ArgumentException(@"operation argument must be of type CustomerOrder", nameof(operation));
            }

            order.CustomerId           = CustomerId;
            order.CustomerName         = CustomerName;
            order.StoreId              = StoreId;
            order.StoreName            = StoreName;
            order.OrganizationId       = OrganizationId;
            order.OrganizationName     = OrganizationName;
            order.EmployeeId           = EmployeeId;
            order.EmployeeName         = EmployeeName;
            order.DiscountAmount       = DiscountAmount;
            order.Total                = Total;
            order.SubTotal             = SubTotal;
            order.SubTotalWithTax      = SubTotalWithTax;
            order.ShippingTotal        = ShippingTotal;
            order.ShippingTotalWithTax = ShippingTotalWithTax;
            order.PaymentTotal         = PaymentTotal;
            order.PaymentTotalWithTax  = PaymentTotalWithTax;
            order.FeeTotal             = HandlingTotal;
            order.FeeTotalWithTax      = HandlingTotalWithTax;
            order.DiscountTotal        = DiscountTotal;
            order.DiscountTotalWithTax = DiscountTotalWithTax;
            order.DiscountAmount       = DiscountAmount;
            order.TaxTotal             = TaxTotal;
            order.IsPrototype          = IsPrototype;
            order.SubscriptionNumber   = SubscriptionNumber;
            order.SubscriptionId       = SubscriptionId;
            order.LanguageCode         = LanguageCode;
            order.TaxPercentRate       = TaxPercentRate;

            order.Discounts  = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList();
            order.Items      = Items.Select(x => x.ToModel(AbstractTypeFactory <LineItem> .TryCreateInstance())).ToList();
            order.Addresses  = Addresses.Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList();
            order.Shipments  = Shipments.Select(x => x.ToModel(AbstractTypeFactory <Shipment> .TryCreateInstance())).OfType <Shipment>().ToList();
            order.InPayments = InPayments.Select(x => x.ToModel(AbstractTypeFactory <PaymentIn> .TryCreateInstance())).OfType <PaymentIn>().ToList();
            order.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList();

            order.DynamicProperties = DynamicPropertyObjectValues.GroupBy(g => g.PropertyId).Select(x =>
            {
                var property    = AbstractTypeFactory <DynamicObjectProperty> .TryCreateInstance();
                property.Id     = x.Key;
                property.Name   = x.FirstOrDefault()?.PropertyName;
                property.Values = x.Select(v => v.ToModel(AbstractTypeFactory <DynamicPropertyObjectValue> .TryCreateInstance())).ToArray();
                return(property);
            }).ToArray();

            base.ToModel(order);

            Sum = order.Total;

            return(order);
        }
        public virtual ShoppingCart ToModel(ShoppingCart cart)
        {
            if (cart == null)
            {
                throw new ArgumentNullException(nameof(cart));
            }

            cart.Id           = Id;
            cart.CreatedBy    = CreatedBy;
            cart.CreatedDate  = CreatedDate;
            cart.ModifiedBy   = ModifiedBy;
            cart.ModifiedDate = ModifiedDate;

            cart.StoreId              = StoreId;
            cart.Fee                  = Fee;
            cart.FeeWithTax           = FeeWithTax;
            cart.Status               = Status;
            cart.Currency             = Currency;
            cart.ValidationType       = ValidationType;
            cart.CustomerId           = CustomerId;
            cart.CustomerName         = CustomerName;
            cart.IsAnonymous          = IsAnonymous;
            cart.IsRecuring           = IsRecuring;
            cart.LanguageCode         = LanguageCode;
            cart.Comment              = Comment;
            cart.OrganizationId       = OrganizationId;
            cart.Total                = Total;
            cart.SubTotal             = SubTotal;
            cart.SubTotalWithTax      = SubTotalWithTax;
            cart.ShippingTotal        = ShippingTotal;
            cart.ShippingTotalWithTax = ShippingTotalWithTax;
            cart.PaymentTotal         = PaymentTotal;
            cart.PaymentTotalWithTax  = PaymentTotalWithTax;
            cart.HandlingTotal        = HandlingTotal;
            cart.HandlingTotalWithTax = HandlingTotalWithTax;
            cart.DiscountTotal        = DiscountTotal;
            cart.DiscountTotalWithTax = DiscountTotalWithTax;
            cart.DiscountAmount       = DiscountAmount;
            cart.TaxTotal             = TaxTotal;
            cart.TaxPercentRate       = TaxPercentRate;
            cart.Type                 = Type;
            cart.Name                 = Name;

            cart.Discounts  = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList();
            cart.Items      = Items.Select(x => x.ToModel(AbstractTypeFactory <LineItem> .TryCreateInstance())).ToList();
            cart.Addresses  = Addresses.Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList();
            cart.Shipments  = Shipments.Select(x => x.ToModel(AbstractTypeFactory <Shipment> .TryCreateInstance())).ToList();
            cart.Payments   = Payments.Select(x => x.ToModel(AbstractTypeFactory <Payment> .TryCreateInstance())).ToList();
            cart.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList();
            cart.Coupons    = Coupons.Select(x => x.Code).ToList();

            // Assigning single coupon to preserve backwards compatibility with previous versions of CartModule
            cart.Coupon = cart.Coupons.FirstOrDefault();

            return(cart);
        }
        public override object Clone()
        {
            var result = base.Clone() as CustomerOrder;

            result.TaxDetails = TaxDetails?.Select(x => x.Clone()).OfType <TaxDetail>().ToList();
            result.Addresses  = Addresses?.Select(x => x.Clone()).OfType <Address>().ToList();
            result.InPayments = InPayments?.Select(x => x.Clone()).OfType <PaymentIn>().ToList();
            result.Items      = Items?.Select(x => x.Clone()).OfType <LineItem>().ToList();
            result.Shipments  = Shipments?.Select(x => x.Clone()).OfType <Shipment>().ToList();
            result.Discounts  = Discounts?.Select(x => x.Clone()).OfType <Discount>().ToList();

            return(result);
        }
Example #4
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as ShoppingCart;

            result.Discounts         = Discounts?.Select(x => x.Clone()).OfType <Discount>().ToList();
            result.Addresses         = Addresses?.Select(x => x.Clone()).OfType <Address>().ToList();
            result.Items             = Items?.Select(x => x.Clone()).OfType <LineItem>().ToList();
            result.Payments          = Payments?.Select(x => x.Clone()).OfType <Payment>().ToList();
            result.Shipments         = Shipments?.Select(x => x.Clone()).OfType <Shipment>().ToList();
            result.TaxDetails        = TaxDetails?.Select(x => x.Clone()).OfType <TaxDetail>().ToList();
            result.DynamicProperties = DynamicProperties?.Select(x => x.Clone()).OfType <DynamicObjectProperty>().ToList();

            return(result);
        }
Example #5
0
        public virtual ShoppingCart ToModel(ShoppingCart cart)
        {
            if (cart == null)
            {
                throw new ArgumentNullException(nameof(cart));
            }

            cart.InjectFrom(this);

            cart.Discounts  = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList();
            cart.Items      = Items.Select(x => x.ToModel(AbstractTypeFactory <LineItem> .TryCreateInstance())).ToList();
            cart.Addresses  = Addresses.Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList();
            cart.Shipments  = Shipments.Select(x => x.ToModel(AbstractTypeFactory <Shipment> .TryCreateInstance())).ToList();
            cart.Payments   = Payments.Select(x => x.ToModel(AbstractTypeFactory <Payment> .TryCreateInstance())).ToList();
            cart.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList();

            return(cart);
        }
        public override OrderOperation ToModel(OrderOperation operation)
        {
            var order = operation as CustomerOrder;

            if (order == null)
            {
                throw new ArgumentException(@"operation argument must be of type CustomerOrder", nameof(operation));
            }

            order.Discounts  = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList();
            order.Items      = Items.Select(x => x.ToModel(AbstractTypeFactory <LineItem> .TryCreateInstance())).ToList();
            order.Addresses  = Addresses.Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList();
            order.Shipments  = Shipments.Select(x => x.ToModel(AbstractTypeFactory <Shipment> .TryCreateInstance())).OfType <Shipment>().ToList();
            order.InPayments = InPayments.Select(x => x.ToModel(AbstractTypeFactory <PaymentIn> .TryCreateInstance())).OfType <PaymentIn>().ToList();
            order.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList();

            base.ToModel(order);

            Sum = order.Total;

            return(order);
        }
Example #7
0
        public override object Clone()
        {
            var result = base.Clone() as ShoppingCart;

            result.HandlingTotal        = HandlingTotal?.Clone() as Money;
            result.HandlingTotalWithTax = HandlingTotalWithTax?.Clone() as Money;
            result.DiscountAmount       = DiscountAmount?.Clone() as Money;
            result.Total                = Total?.Clone() as Money;
            result.SubTotal             = SubTotal?.Clone() as Money;
            result.SubTotalWithTax      = SubTotalWithTax?.Clone() as Money;
            result.ShippingPrice        = ShippingPrice?.Clone() as Money;
            result.ShippingPriceWithTax = ShippingPriceWithTax?.Clone() as Money;
            result.ShippingTotal        = ShippingTotal?.Clone() as Money;
            result.ShippingTotalWithTax = ShippingTotalWithTax?.Clone() as Money;
            result.PaymentPrice         = PaymentPrice?.Clone() as Money;
            result.PaymentPriceWithTax  = PaymentPriceWithTax?.Clone() as Money;
            result.PaymentTotal         = PaymentTotal?.Clone() as Money;
            result.PaymentTotalWithTax  = PaymentTotalWithTax?.Clone() as Money;
            result.HandlingTotal        = HandlingTotal?.Clone() as Money;
            result.HandlingTotalWithTax = HandlingTotalWithTax?.Clone() as Money;
            result.DiscountTotal        = DiscountTotal?.Clone() as Money;
            result.DiscountTotalWithTax = DiscountTotalWithTax?.Clone() as Money;
            result.TaxTotal             = TaxTotal?.Clone() as Money;

            if (Discounts != null)
            {
                result.Discounts = new List <Discount>(Discounts.Select(x => x.Clone() as Discount));
            }
            if (TaxDetails != null)
            {
                result.TaxDetails = new List <TaxDetail>(TaxDetails.Select(x => x.Clone() as TaxDetail));
            }
            if (DynamicProperties != null)
            {
                result.DynamicProperties = new List <DynamicProperty>(DynamicProperties.Select(x => x.Clone() as DynamicProperty));
            }
            if (ValidationErrors != null)
            {
                result.ValidationErrors = new List <ValidationError>(ValidationErrors.Select(x => x.Clone() as ValidationError));
            }
            if (Addresses != null)
            {
                result.Addresses = new List <Address>(Addresses.Select(x => x.Clone() as Address));
            }
            if (Items != null)
            {
                result.Items = new List <LineItem>(Items.Select(x => x.Clone() as LineItem));
            }
            if (Payments != null)
            {
                result.Payments = new List <Payment>(Payments.Select(x => x.Clone() as Payment));
            }
            if (Shipments != null)
            {
                result.Shipments = new List <Shipment>(Shipments.Select(x => x.Clone() as Shipment));
            }
            if (Coupons != null)
            {
                result.Coupons = new List <Coupon>(Coupons.Select(x => x.Clone() as Coupon));
            }
            if (AvailablePaymentMethods != null)
            {
                result.AvailablePaymentMethods = new List <PaymentMethod>(AvailablePaymentMethods.Select(x => x.Clone() as PaymentMethod));
            }

            return(result);
        }