Exemple #1
0
        public OrderLinesViewModel GetOrderLinesRenderingModel(IVisitorContext visitorContext, string orderId)
        {
            OrderLinesViewModel model = ModelProvider.GetModel <OrderLinesViewModel>();

            Init(model);
            if (string.IsNullOrEmpty(orderId))
            {
                return(OrderLinesMockData.InitializeMockData(model));
            }

            ManagerResponse <GetVisitorOrderResult, Order> orderDetails = OrderManager.GetOrderDetails(StorefrontContext.CurrentStorefront, visitorContext, orderId);

            if (!orderDetails.ServiceProviderResult.Success || orderDetails.Result == null)
            {
                string systemMessage = StorefrontContext.GetSystemMessage("Could not retrieve order details!", true);
                model.ErrorMessage = systemMessage;
                return(model);
            }
            model.Initialize(orderDetails.Result);
            return(model);
        }
Exemple #2
0
        public JsonResult AddCartLine(IContext context, string productId, string variantId, string quantity = "1.0")
        {
            BaseJsonResult     model                       = new BaseJsonResult(context, StorefrontContext);
            CommerceStorefront currentStorefront           = StorefrontContext.CurrentStorefront;
            ManagerResponse <CartResult, Cart> currentCart = _cartManager.GetCurrentCart(_visitorContext, StorefrontContext, false);

            if (!currentCart.ServiceProviderResult.Success || currentCart.Result == null)
            {
                string systemMessage = StorefrontContext.GetSystemMessage("Cart Not Found Error", true);
                currentCart.ServiceProviderResult.SystemMessages.Add(new SystemMessage
                {
                    Message = systemMessage
                });
                model.SetErrors(currentCart.ServiceProviderResult);
                return(model);
            }

            List <CartLineArgument> list = new List <CartLineArgument>();

            list.Add(new CartLineArgument
            {
                CatalogName = StorefrontContext.CurrentStorefront.Catalog,
                ProductId   = productId,
                VariantId   = variantId,
                Quantity    = decimal.Parse(quantity)
            });

            ManagerResponse <CartResult, Cart> managerResponse = _cartManager.AddLineItemsToCart(currentStorefront, _visitorContext, currentCart.Result, list);

            if (!managerResponse.ServiceProviderResult.Success)
            {
                model.SetErrors(managerResponse.ServiceProviderResult);
                return(model);
            }
            model.Success = true;
            return(base.Json(model));
        }
Exemple #3
0
        public override List <Item> GetNavigationCategories()
        {
            var objList = new List <Item>();

            try
            {
                var index       = CommerceTypeLoader.CreateInstance <ICommerceSearchManager>().GetIndex();
                var storeHelper = new StoreHelper();
                var storeId     = storeHelper.GetCookie()?.StoreId ?? ((Models.CommerceStorefront)StorefrontContext.CurrentStorefront).DefaultStoreID;
                var idString    = ((Models.CommerceStorefront)StorefrontContext.CurrentStorefront).GetStartNavigationCategoryID(storeId).Guid.ToString();
                using (var searchContext = index.CreateSearchContext(SearchSecurityOptions.Default))
                {
                    var list = searchContext.GetQueryable <CommerceCategorySearchResultItem>()
                               .Where(item => item.SitecoreId == idString)
                               .Where(item => item.Language == CurrentLanguageName)
                               .Select(p => p).ToList();
                    if (list.Count > 0)
                    {
                        objList = ExtractChildrenCategories(list[0]);
                    }
                }
            }
            catch (DirectoryNotFoundException ex)
            {
                Helpers.LogErrorMessage(StorefrontContext.GetSystemMessage("Search Index Directory Not Found Error", true), ex, ex);
            }
            catch (IndexNotFoundException ex)
            {
                Helpers.LogErrorMessage(StorefrontContext.GetSystemMessage("Search Index Not Found Error", true), ex, ex);
            }
            catch
            {
                throw;
            }

            return(objList);
        }