private bool TryResolveSubmittedOrder(CartBase cart, out ManagerResponse <SubmitVisitorOrderResult, Order> managerResponse)
        {
            var getVisitorOrdersRequest = new GetVisitorOrdersRequest(cart.CustomerId, cart.ShopName);
            GetVisitorOrdersResult getVisitorOrdersResult = this.orderServiceProvider.GetVisitorOrders(getVisitorOrdersRequest);

            if (getVisitorOrdersResult.Success)
            {
                // Getting the latest order
                OrderHeader orderHeader = getVisitorOrdersResult.OrderHeaders.OrderByDescending(x => x.OrderDate).FirstOrDefault();
                if (orderHeader != null)
                {
                    var getVisitorOrderRequest = new GetVisitorOrderRequest(orderHeader.OrderID, orderHeader.CustomerId, orderHeader.ShopName);

                    GetVisitorOrderResult getVisitorOrderResult =
                        this.orderServiceProvider.GetVisitorOrder(getVisitorOrderRequest);

                    if (getVisitorOrderResult.Order != null)
                    {
                        managerResponse = new ManagerResponse <SubmitVisitorOrderResult, Order>(
                            new SubmitVisitorOrderResult {
                            Order = getVisitorOrderResult.Order, Success = true
                        },
                            getVisitorOrderResult.Order);

                        return(true);
                    }
                }
            }

            managerResponse = null;
            return(false);
        }
        public ManagerResponse <GetPartiesResult, IEnumerable <Party> > GetCurrentCustomerParties(
            string shopName,
            string contactId)
        {
            var getPartiesResult = new GetPartiesResult();

            ManagerResponse <GetUserResult, CommerceUser> user = this.GetUser(contactId);

            if (!user.ServiceProviderResult.Success || user.Result == null)
            {
                return(new ManagerResponse <GetPartiesResult, IEnumerable <Party> >(getPartiesResult, null));
            }

            var customer = new CommerceCustomer {
                ExternalId = user.Result.ExternalId
            };

            return(this.GetParties(customer));
        }
示例#3
0
        public void GetProductPrice(Product product)
        {
            if (product == null)
            {
                return;
            }

            bool includeVariants = product.Variants != null && product.Variants.Count > 0;
            ManagerResponse <GetProductPricesResult, IDictionary <string, Price> > productPrices = this.pricingManager.GetProductPrices(product.CatalogName, product.ProductId, includeVariants, null);

            if (productPrices == null || !productPrices.ServiceProviderResult.Success || productPrices.Result == null)
            {
                return;
            }

            if (productPrices.Result.TryGetValue(product.ProductId, out Price price))
            {
                var commercePrice = (CommercePrice)price;
                product.CurrencyCode  = price.CurrencyCode;
                product.ListPrice     = price.Amount;
                product.AdjustedPrice = commercePrice.ListPrice;
            }

            if (!includeVariants)
            {
                return;
            }

            foreach (Variant variant in product.Variants)
            {
                if (productPrices.Result.TryGetValue(variant.VariantId, out price))
                {
                    CommercePrice commercePrice = (CommercePrice)price;
                    variant.CurrencyCode  = commercePrice.CurrencyCode;
                    variant.ListPrice     = commercePrice.Amount;
                    variant.AdjustedPrice = commercePrice.ListPrice;
                }
            }
        }