Esempio n. 1
0
 protected virtual void CheckIfEditing(
     IVisitorContext visitorContext,
     CustomBaseCheckoutDataJsonResult result)
 {
     if ((result.Cart == null || result.Cart.Shipments == null ? 0 : (result.Cart.Shipments.Count > 0 ? 1 : 0)) == 0)
     {
         return;
     }
     foreach (ShippingInfoJsonResult shipment1 in result.Cart.Shipments)
     {
         ShippingInfoJsonResult shipment = shipment1;
         if (shipment.LineIDs != null && shipment.LineIDs.Count > 0)
         {
             CartLineJsonResult cartLineJsonResult = result.Cart.Lines.Find((l => l.ExternalCartLineId.Equals(shipment.LineIDs[0], StringComparison.OrdinalIgnoreCase)));
             if (cartLineJsonResult != null && cartLineJsonResult.ShippingOptions != null && cartLineJsonResult.ShippingOptions.Count <ShippingOptionJsonResult>() > 0)
             {
                 ShippingOptionJsonResult optionJsonResult = cartLineJsonResult.ShippingOptions.ElementAt <ShippingOptionJsonResult>(0);
                 if (optionJsonResult != null)
                 {
                     shipment.EditModeShippingOptionType = optionJsonResult.ShippingOptionType;
                     if (optionJsonResult.ShippingOptionType == ShippingOptionType.ShipToAddress)
                     {
                         AddressJsonResult addressJsonResult = result.Cart.Parties.Find((Predicate <AddressJsonResult>)(p => p.ExternalId.Equals(shipment.PartyID, StringComparison.OrdinalIgnoreCase)));
                         if (addressJsonResult != null)
                         {
                             GetShippingMethodsInputModel inputModel = new GetShippingMethodsInputModel()
                             {
                                 ShippingPreferenceType = ShippingOptionType.ShipToAddress.Value.ToString((IFormatProvider)CultureInfo.InvariantCulture),
                                 ShippingAddress        = new PartyInputModel()
                             };
                             inputModel.ShippingAddress.ExternalId    = addressJsonResult.ExternalId;
                             inputModel.ShippingAddress.Address1      = addressJsonResult.Address1;
                             inputModel.ShippingAddress.City          = addressJsonResult.City;
                             inputModel.ShippingAddress.State         = addressJsonResult.State;
                             inputModel.ShippingAddress.ZipPostalCode = addressJsonResult.ZipPostalCode;
                             inputModel.ShippingAddress.Country       = addressJsonResult.Country;
                             inputModel.ShippingAddress.IsPrimary     = addressJsonResult.IsPrimary;
                             inputModel.Lines = new List <CartLineInputModel>();
                             ShippingMethodsJsonResult shippingMethods = this.GetShippingMethods(visitorContext, inputModel);
                             if (shippingMethods != null)
                             {
                                 shipment.ShipmentEditModel = this.ModelProvider.GetModel <ShipmentEditModeDataJsonResult>();
                                 shipment.ShipmentEditModel.ShippingMethods = shippingMethods.ShippingMethods;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public virtual void Initialize(Sitecore.Commerce.Entities.Carts.Cart cart, dynamic cartLineList)
        {
            //todo: the entire feature for which this modificaiton was added needs to be re-evaluated against 9.1 and the code updated
            List <dynamic> expandedCartLines = (List <dynamic>)cartLineList;

            this.Email       = cart.Email;
            this.TaxTotal    = cart.Total.TaxTotal.Amount.ToCurrency();
            this.Total       = cart.Total.Amount.ToCurrency();
            this.TotalAmount = cart.Total.Amount;
            this.PromoCodes  = cart.GetPropertyValue("PromoCodes") as IEnumerable <string>;
            this.Lines       = new List <ShoppingCartLineJsonResult>();
            foreach (CartLine line in cart.Lines)
            {
                ShoppingCartLineJsonResult model = this.ModelProvider.GetModel <ShoppingCartLineJsonResult>();

                //todo: these should not be null, replace with real params
                model.Initialize(line, null, null);

                dynamic expandedCartLine = expandedCartLines.Where(l => l.ExternalCartLineId == line.ExternalCartLineId).FirstOrDefault();
                if (expandedCartLine != null)
                {
                    model.SetProductType(expandedCartLine);
                }
                this.Lines.Add(model);
            }
            this.Shipments = new List <ShippingInfoJsonResult>();
            if (cart.Shipping != null && cart.Shipping.Any <ShippingInfo>())
            {
                foreach (ShippingInfo shippingInfo in cart.Shipping)
                {
                    ShippingInfoJsonResult model = this.ModelProvider.GetModel <ShippingInfoJsonResult>();
                    model.Initialize(shippingInfo);
                    this.Shipments.Add(model);
                }
            }
            this.Parties = new List <AddressJsonResult>();
            if (cart.Parties != null && cart.Parties.Any <Party>())
            {
                foreach (Party party in cart.Parties)
                {
                    AddressJsonResult model = this.ModelProvider.GetModel <AddressJsonResult>();
                    model.Initialize(party);
                    this.Parties.Add(model);
                }
            }
            this.Payments = new List <PaymentInfoJsonResult>();
            if (cart.Payment != null && cart.Payment.Any <PaymentInfo>())
            {
                foreach (PaymentInfo paymentInfo in cart.Payment)
                {
                    PaymentInfoJsonResult model = this.ModelProvider.GetModel <PaymentInfoJsonResult>();
                    model.Initialize(paymentInfo);
                    this.Payments.Add(model);
                }
            }
            if (cart.AccountingCustomerParty == null)
            {
                return;
            }
            this.AccountingParty         = this.ModelProvider.GetModel <PartyLinkJsonResult>();
            this.AccountingParty.Name    = cart.AccountingCustomerParty.Name;
            this.AccountingParty.PartyID = cart.AccountingCustomerParty.PartyID;

            if (!(cart is CommerceCart))
            {
                return;
            }
            CommerceTotal total = (CommerceTotal)cart.Total;

            this.Discount      = (cart.Lines.Sum <CartLine>((Func <CartLine, Decimal>)(lineitem => ((CommerceTotal)lineitem.Total).LineItemDiscountAmount)) + ((CommerceTotal)cart.Total).OrderLevelDiscountAmount).ToCurrency();
            this.Subtotal      = total.Subtotal.ToCurrency();
            this.ShippingTotal = total.ShippingTotal.ToCurrency();
        }