Пример #1
0
        protected IEnumerable <Queue <string> > GetCustomRelatedProductList(
            CommerceOrder order,
            string productRelationshipName,
            string tag)
        {
            IEnumerable <Guid>     guids           = order.Lines.Select(x => x.Product.SitecoreProductItemId);
            List <Queue <string> > stringQueueList = new List <Queue <string> >();

            foreach (Guid guid in guids)
            {
                var parent = this.StorefrontContext.Context.Database.GetItem(guid.ToString());
                if (parent != null && this.ItemTypeProvider.GetItemType(parent) == Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Variant)
                {
                    parent = parent.Parent;
                }

                var field = (MultilistField)parent?.Fields[productRelationshipName];

                foreach (var id in field.TargetIDs)
                {
                    var rp = this.StorefrontContext.Context.Database.GetItem(id.ToString());
                    if (rp?.Fields[_tagsFieldName]?.Value?.Split('|').Contains(tag) == true)
                    {
                        stringQueueList.Add(new Queue <string>(new List <string>()
                        {
                            id.ToString()
                        }));
                    }
                }
            }
            return(stringQueueList);
        }
Пример #2
0
        private IEnumerable <OrderLineViewModel> CreateOrderLines(CommerceOrder commerceOrder)
        {
            foreach (var orderLine in commerceOrder.Lines)
            {
                if (orderLine.Product == null)
                {
                    continue;
                }
                var product      = CatalogManager.GetProduct(orderLine.Product.ProductId);
                var shippingInfo = GetOrderLineShippingInfo(commerceOrder, orderLine);

                yield return(new OrderLineViewModel()
                {
                    OrderLineId = orderLine.ExternalCartLineId,
                    Savings = ((CommerceTotal)orderLine.Total).LineItemDiscountAmount,
                    Image = GetProductImage(orderLine),
                    ProductUrl = product != null?LinkManager.GetDynamicUrl(product) : null,
                                     Title = (orderLine.Product as CommerceCartProduct)?.DisplayName ?? orderLine.Product?.ProductName,
                                     ProductColor = orderLine.Product.Properties["Color"]?.ToString(),
                                     ShippingMethodName = shippingInfo?.Properties["ShippingMethodName"]?.ToString(),
                                     ShippingAddress = GetShippingAddress(commerceOrder, shippingInfo),
                                     ShippingEmail = shippingInfo?.ElectronicDeliveryEmail,
                                     ItemPrice = orderLine.Product.Price.Amount,
                                     Total = orderLine.Total.Amount,
                                     Currency = orderLine.Total.CurrencyCode,
                                     Quantity = orderLine.Quantity,
                                     Adjustments = orderLine.Adjustments?.Select(a => a.Description) ?? Enumerable.Empty <string>(),
                                     Discount = ((CommerceTotal)orderLine.Total).LineItemDiscountAmount
                });
            }
        }
        /// <summary>
        /// Initializes the specified renderings.
        /// </summary>
        /// <param name="renderings">The renderings.</param>
        /// <param name="confirmationId">The confirmation identifier.</param>
        /// <param name="order">The order.</param>
        public void Initialize(Rendering renderings, string confirmationId, CommerceOrder order)
        {
            base.Initialize(renderings);

            this.ConfirmationId = confirmationId;
            this.OrderStatus    = StorefrontManager.GetOrderStatusName(order.Status);
        }
        public ManagerResponse <GetVisitorOrderResult, CommerceOrder> GetOrderDetails(CommerceStorefront storefront, IVisitorContext visitorContext, string orderId)
        {
            var order = new CommerceOrder
            {
                LastModified = DateTime.Now
            };

            return(new ManagerResponse <GetVisitorOrderResult, CommerceOrder>(new GetVisitorOrderResult(), order));
        }
Пример #5
0
        private static CommerceShippingInfo GetOrderLineShippingInfo(CommerceOrder commerceOrder, CartLine orderLine)
        {
            var uniqueShippingInfo = commerceOrder.Shipping.FirstOrDefault(shipping => shipping.LineIDs.ToList().Contains(orderLine.ExternalCartLineId) && shipping.LineIDs.Count == 1) as CommerceShippingInfo;

            if (uniqueShippingInfo != null)
            {
                return(uniqueShippingInfo);
            }
            return(commerceOrder.Shipping.FirstOrDefault(s => s.LineIDs.Contains(orderLine.ExternalCartLineId)) as CommerceShippingInfo);
        }
Пример #6
0
        private IParty GetShippingAddress(CommerceOrder commerceOrder, CommerceShippingInfo shippingInfo)
        {
            var linePartyId = shippingInfo?.PartyID;

            if (string.IsNullOrEmpty(linePartyId))
            {
                return(null);
            }
            return(commerceOrder.Parties.FirstOrDefault(p => p.ExternalId.Equals(linePartyId, StringComparison.OrdinalIgnoreCase))?.ToEntity());
        }
Пример #7
0
 private IEnumerable <IParty> GetShippingAddresses(CommerceOrder commerceOrder)
 {
     foreach (var shippingInfo in commerceOrder.Shipping)
     {
         var partyId = shippingInfo.PartyID;
         var party   = commerceOrder.Parties.FirstOrDefault(p => p.ExternalId.Equals(partyId, StringComparison.OrdinalIgnoreCase));
         if (party != null)
         {
             yield return(party.ToEntity());
         }
     }
 }
        public string RequestPayment(CommerceOrder order)
        {
            var request = new RequestPaymentRequest
            {
                CustomerId = order.CustomerId,
                OrderId    = order.OrderID
            };

            request.SetShopName(order.ShopName);

            return(RunPipeline <RequestPaymentRequest, RequestPaymentResult>("heidelpay.requestPayment", request).RedirectUrl);
        }
Пример #9
0
        public CommerceOrder GetCommerceOrder(string confirmationId)
        {
            CommerceOrder order = null;

            if (!string.IsNullOrWhiteSpace(confirmationId))
            {
                var response = this._orderManager.GetOrderDetails(this.CurrentStorefront, this.CurrentVisitorContext, confirmationId);

                if (response.ServiceProviderResult.Success)
                {
                    order = response.Result;
                }
            }

            return(order);
        }
        public ActionResult OrderConfirmation([Bind(Prefix = StorefrontConstants.QueryStrings.ConfirmationId)] string confirmationId)
        {
            var           viewModel = new OrderConfirmationViewModel();
            CommerceOrder order     = null;

            if (!string.IsNullOrWhiteSpace(confirmationId))
            {
                var response = this.OrderManager.GetOrderDetails(this.CurrentStorefront, this.CurrentVisitorContext, confirmationId);
                if (response.ServiceProviderResult.Success)
                {
                    order = response.Result;
                }
            }

            viewModel.Initialize(this.CurrentRendering, confirmationId, order);

            return(View(this.CurrentRenderingView, viewModel));
        }
Пример #11
0
        public IEnumerable <ID> CalculateCustomRecommendedProducts(
            CommerceOrder order,
            int maxNumberOfProducts,
            string productRelationshipName,
            string tag = "")
        {
            Condition.Requires(productRelationshipName).IsNotNullOrEmpty();
            List <ID> idList = new List <ID>();

            if (order.Lines.Count > 0)
            {
                var relatedProductList = string.IsNullOrEmpty(tag)
                    ? this.GetRelatedProductList(order, productRelationshipName)
                    : this.GetCustomRelatedProductList(order, productRelationshipName, tag);

                int num1 = relatedProductList.Select(x => x).Sum(y => y.Count());
                int num2 = maxNumberOfProducts < num1 ? maxNumberOfProducts : num1;
                while (idList.Count < num2)
                {
                    foreach (Queue <string> stringQueue in relatedProductList)
                    {
                        if (idList.Count != maxNumberOfProducts)
                        {
                            if (stringQueue.Count > 0)
                            {
                                ID id = new ID(stringQueue.Dequeue());
                                if (!idList.Contains(id))
                                {
                                    idList.Add(id);
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            return(idList);
        }
        public ActionResult OrderConfirmation([Bind(Prefix = ConfirmationIdQueryString)] string confirmationId)
        {
            var viewModel = new OrderConfirmationViewModel();

            if (!string.IsNullOrWhiteSpace(confirmationId))
            {
                var order = this.Session["NewOrder"] as CommerceOrder;
                if (order == null)
                {
                    order = new CommerceOrder()
                    {
                        Status = Sitecore.Commerce.Connect.DynamicsRetail.Texts.Pending
                    };
                    viewModel.Initialize(RenderingContext.Current.Rendering, order.TrackingNumber, OrderManager.GetOrderStatusName(order.Status));
                }

                viewModel.Initialize(RenderingContext.Current.Rendering, confirmationId, order.Status);
            }

            return(View(viewModel));
        }
Пример #13
0
 private IEnumerable <PaymentInfoViewModel> GetPaymentInfo(CommerceOrder commerceOrder)
 {
     foreach (var payment in commerceOrder.Payment)
     {
         var paymentInfo = new PaymentInfoViewModel();
         if (payment is CommerceCreditCardPaymentInfo)
         {
             var creditCard = payment as CommerceCreditCardPaymentInfo;
             paymentInfo.CardType         = creditCard.CardType;
             paymentInfo.CreditCardNumber = creditCard.CreditCardNumber;
             paymentInfo.CustomerName     = creditCard.CustomerNameOnPayment;
             paymentInfo.ExpirationMonth  = creditCard.ExpirationMonth;
             paymentInfo.ExpirationYear   = creditCard.ExpirationMonth;
             paymentInfo.PaymentType      = PaymentType.CreditCard;
             paymentInfo.Amount           = creditCard.Amount;
         }
         else if (payment is GiftCardPaymentInfo)
         {
             var giftCard = payment as GiftCardPaymentInfo;
             paymentInfo.PaymentType = PaymentType.GiftCard;
             paymentInfo.GiftCardId  = giftCard.PaymentMethodID;
             paymentInfo.Amount      = giftCard.Amount;
         }
         else if (payment is FederatedPaymentInfo)
         {
             var federated = payment as FederatedPaymentInfo;
             paymentInfo.PaymentType = PaymentType.Federated;
             paymentInfo.Amount      = federated.Amount;
         }
         else
         {
             continue;
         }
         yield return(paymentInfo);
     }
 }
Пример #14
0
 private static string GetOrderId(CommerceOrder commerceOrder)
 {
     //BUG? CommerceOrder returns a guid in OrderId - and should return the human readable ID which is in TrackingNumber
     return(commerceOrder.TrackingNumber);
 }
Пример #15
0
        /// <summary>
        /// The translate.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        protected override void Translate(TranslateOrderToEntityRequest request, Order source, CommerceOrder destination)
        {
            base.Translate(request, source, destination);

            if ((source.Components == null) || !source.Components.Any())
            {
                return;
            }

            // Sets all the properties from the custom components to the properties
            foreach (var component in source.Components)
            {
                foreach (var property in component.GetType().GetProperties())
                {
                    var name = component.GetType().Name + "_" + property.Name;
                    if (property.GetValue(component) != null)
                    {
                        destination.Properties[name] = property.GetValue(component);
                    }
                }
            }
        }