Example #1
0
        public CustomDeliveryDataJsonResult GetDeliveryData(
            IVisitorContext visitorContext)
        {
            CustomDeliveryDataJsonResult model = this.ModelProvider.GetModel <CustomDeliveryDataJsonResult>();

            if (!this.Context.IsExperienceEditor)
            {
                try
                {
                    ManagerResponse <CartResult, Sitecore.Commerce.Entities.Carts.Cart> currentCart = this.CartManager.GetCurrentCart(visitorContext, this.StorefrontContext, true);
                    if (!currentCart.ServiceProviderResult.Success)
                    {
                        model.SetErrors((ServiceProviderResult)currentCart.ServiceProviderResult);
                        return(model);
                    }
                    Sitecore.Commerce.Entities.Carts.Cart result = currentCart.Result;

                    if (result.Lines != null)
                    {
                        if (result.Lines.Any <CartLine>())
                        {
                            model.Initialize(result, visitorContext);
                            this.AddShippingOptionsToModel(model, result);
                            if (model.Success)
                            {
                                this.AddEmailShippingMethodToResult(model, result);
                                if (model.Success)
                                {
                                    //This is the method we need to add for adding the available states to the delivery Json result which will be consumed by knock out to display the states dictionary in the dropdown.
                                    this.AddAvailableRegions((CustomDeliveryDataJsonResult)model);
                                    this.AddAvailableCountries((CustomBaseCheckoutDataJsonResult)model);
                                    if (model.Success)
                                    {
                                        if (Context.User.IsAuthenticated)
                                        {
                                            this.AddCustomUserInfo((CustomBaseCheckoutDataJsonResult)model);
                                        }
                                        if (model.Success)
                                        {
                                            this.CheckIfEditing(visitorContext, model);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message, ex, (object)this);
                    model.SetErrors(nameof(GetDeliveryData), ex);
                    return(model);
                }
            }
            return(model);
        }
Example #2
0
        protected virtual void AddEmailShippingMethodToResult(
            CustomDeliveryDataJsonResult jsonResult,
            Sitecore.Commerce.Entities.Carts.Cart cart)
        {
            ShippingMethod emailShippingMethod1 = (ShippingMethod)null;
            ManagerResponse <GetShippingMethodsResult, ShippingMethod> emailShippingMethod2 = this.ShippingManager.GetEmailShippingMethod(this.StorefrontContext.CurrentStorefront, cart);

            if (emailShippingMethod2.ServiceProviderResult.Success)
            {
                emailShippingMethod1 = emailShippingMethod2.Result;
            }
            else
            {
                jsonResult.SetErrors((ServiceProviderResult)emailShippingMethod2.ServiceProviderResult);
            }
            jsonResult.InitializeEmailShippingMethod(emailShippingMethod1);
        }
        public virtual OrderReviewDataJsonResult GetReviewData(IVisitorContext visitorContext)
        {
            OrderReviewDataJsonResult model = this.ModelProvider.GetModel <OrderReviewDataJsonResult>();

            if (!Context.PageMode.IsExperienceEditor)
            {
                try
                {
                    ManagerResponse <CartResult, Sitecore.Commerce.Entities.Carts.Cart> currentCart = this.CartManager.GetCurrentCart(visitorContext, this.StorefrontContext, true);
                    if (!currentCart.ServiceProviderResult.Success)
                    {
                        model.SetErrors((ServiceProviderResult)currentCart.ServiceProviderResult);
                        return(model);
                    }
                    Sitecore.Commerce.Entities.Carts.Cart result = currentCart.Result;
                    if (result.Lines != null)
                    {
                        if (result.Lines.Any <CartLine>())
                        {
                            model.Initialize(result, visitorContext);
                            this.AddUserInfo(visitorContext, (BaseCheckoutDataJsonResult)model);
                            if (model.Success)
                            {
                                this.CheckForDigitalProductInCart(model, result);
                                model.CurrencyCode = result.CurrencyCode;
                                model.BenefitsData = new BenefitsDataJsonResult(result);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message, ex, (object)this);
                    model.SetErrors(nameof(GetReviewData), ex);
                    return(model);
                }
            }
            return(model);
        }
Example #4
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();
        }
        protected virtual void CheckForDigitalProductInCart(ReviewDataJsonResult jsonResult, Sitecore.Commerce.Entities.Carts.Cart cart)
        {
            ManagerResponse <GetShippingOptionsResult, List <ShippingOption> > shippingPreferences = this.ShippingManager.GetShippingPreferences(cart);

            if (!shippingPreferences.ServiceProviderResult.Success)
            {
                jsonResult.SetErrors((ServiceProviderResult)shippingPreferences.ServiceProviderResult);
            }
            else
            {
                foreach (LineShippingOption lineShippingOption in shippingPreferences.ServiceProviderResult.LineShippingPreferences.ToList <LineShippingOption>())
                {
                    List <ShippingOption>       shippingOptions = lineShippingOption.ShippingOptions;
                    Func <ShippingOption, bool> func            = (Func <ShippingOption, bool>)(o => o.ShippingOptionType.Value == CartFeatureConstants.DataTemplates.FixedValues.ElectronicDeliveryShippingOptionValue);
                    Func <ShippingOption, bool> predicate       = func;
                    if (shippingOptions.Where <ShippingOption>(predicate).Count <ShippingOption>() >= 1)
                    {
                        jsonResult.HasDigitalProduct = true;
                        break;
                    }
                }
            }
        }
Example #6
0
        protected virtual void AddShippingOptionsToModel(CustomDeliveryDataJsonResult jsonResult, Sitecore.Commerce.Entities.Carts.Cart cart)
        {
            ManagerResponse <GetShippingOptionsResult, List <ShippingOption> > shippingPreferences = this.ShippingManager.GetShippingPreferences(cart);

            if (!shippingPreferences.ServiceProviderResult.Success)
            {
                jsonResult.SetErrors((ServiceProviderResult)shippingPreferences.ServiceProviderResult);
            }
            else
            {
                List <ShippingOption>     list1 = shippingPreferences.ServiceProviderResult.ShippingOptions.ToList <ShippingOption>();
                List <LineShippingOption> list2 = shippingPreferences.ServiceProviderResult.LineShippingPreferences.ToList <LineShippingOption>();
                jsonResult.InitializeShippingOptions(list1);
                jsonResult.InitializeLineItemShippingOptions(list2);
            }
        }