示例#1
0
        public async Task InitilizeData()
        {
            try
            {
                string accestoken     = Convert.ToString(Settings.Customer_Access_Token);
                char   quote          = '"';
                string modifiedString = quote + accestoken + quote;
                string query          = @"{customer(customerAccessToken:" + modifiedString + "){ id firstName lastName email phone createdAt lastIncompleteCheckout{id createdAt webUrl lineItems(first: 5){ edges{ node{quantity id title variant{ id price selectedOptions{name value}  image{ id originalSrc}}}}}}addresses(first: 3){edges{ node{ id firstName lastName address1 address2 city company country}}}orders(first: 3){edges{node{id orderNumber name email lineItems(first: 3){ edges{ node{quantity variant{ id image{ originalSrc}}}}}}}}}}";
                var    result         = await _apiService.GetCustomer(query);

                if (result != null)
                {
                    _lastIncomplete = result.data.customer.lastIncompleteCheckout;
                    CartList        = new ObservableCollection <Node>();
                    foreach (var item in result.data.customer.lastIncompleteCheckout.lineItems.edges)
                    {
                        CartList.Add(item.node);
                    }
                }
                else
                {
                    CartList = new ObservableCollection <Node>();
                }
                CostSummary   = CartList.Sum(s => Convert.ToDouble(s.variant.price) * s.quantity);
                ShippingPrice = 0;
                TotalQuantity = CartList.Count();
                TotalPrice    = ShippingPrice + CostSummary;
                if (CartList.Count > 0)
                {
                    IsViewVisible = true;
                }
                else
                {
                    IsViewVisible = false;
                }
            }
            catch (Exception ex)
            {
                CostSummary   = 0;
                ShippingPrice = 0;
                TotalPrice    = 0;
            }
        }