Пример #1
0
        private Product ParseProductFromSlug(string slug)
        {
            Product result = null;

            if (!string.IsNullOrEmpty(slug))
            {
                result = HccApp.CatalogServices.Products.FindBySlug(slug);
                if (result == null || result.Status == ProductStatus.Disabled)
                {
                    // Check for custom URL
                    var url = HccApp.ContentServices.CustomUrls.FindByRequestedUrl(slug, CustomUrlType.Product);
                    if (url != null)
                    {
                        var redirectUrl = HccUrlBuilder.RouteHccUrl(HccRoute.ProductReview,
                                                                    new { slug = url.RedirectToUrl });
                        if (url.IsPermanentRedirect)
                        {
                            Response.RedirectPermanent(redirectUrl);
                        }
                        else
                        {
                            Response.Redirect(redirectUrl);
                        }
                    }
                    StoreExceptionHelper.ShowInfo(Localization.GetString("ProductNotFound"));
                }
            }

            return(result);
        }
Пример #2
0
        private ProductPageViewModel LoadProductModel(string slug)
        {
            CustomUrl customUrl;
            var       product = HccApp.ParseProductBySlug(slug, out customUrl);

            if (customUrl != null && !IsConcreteItemModule)
            {
                var redirectUrl = HccUrlBuilder.RouteHccUrl(HccRoute.Product, new { slug = customUrl.RedirectToUrl });
                if (customUrl.IsPermanentRedirect)
                {
                    Response.RedirectPermanent(redirectUrl);
                }
                else
                {
                    Response.Redirect(redirectUrl);
                }
            }
            if (product == null)
            {
                StoreExceptionHelper.ShowInfo(Localization.GetString("ProductNotFound"));
            }
            else if (product.Status != ProductStatus.Active)
            {
                StoreExceptionHelper.ShowInfo(Localization.GetString("ProductNotActive"));
            }
            else if (!HccApp.CatalogServices.TestProductAccess(product))
            {
                StoreExceptionHelper.ShowInfo(Localization.GetString("ProductNotEnoughPermission"));
            }

            var model = new ProductPageViewModel {
                LocalProduct = product
            };

            LoadImageUrls(model);
            model.Prices = CreateProductPrices(product);
            LoadRelatedItems(model);
            LoadBundledItems(model);
            model.IsAvailableForWishList = SessionManager.IsUserAuthenticated(HccApp);
            model.AllowReviews           = product.AllowReviews.HasValue
                ? product.AllowReviews.Value
                : HccApp.CurrentStore.Settings.AllowProductReviews;
            LoadAlternateImages(model);
            model.PreRenderedTypeValues = product.RenderTypeProperties();
            model.SwatchHtml            = ImageHelper.GenerateSwatchHtmlForProduct(product, HccApp);
            model.LineItemId            = Request.QueryString["LineItemId"].ConvertToNullable <long>();

            // make the minimum quantity be the new default if necessary, otherwise use the actual default (1)
            if (product.MinimumQty > 0)
            {
                model.Quantity = product.MinimumQty;
            }

            LoadGiftCardAmounts(model);

            return(model);
        }
        private CategoryPageViewModel LoadCategoryModel(string slug, string preContentColumnId,
                                                        string postContentColumnId)
        {
            Category cat = null;

            if (!string.IsNullOrWhiteSpace(slug))
            {
                CustomUrl customUrl;
                cat = HccApp.ParseCategoryBySlug(slug, out customUrl);
                if (customUrl != null && !IsConcreteItemModule)
                {
                    var redirectUrl = HccUrlBuilder.RouteHccUrl(HccRoute.Category, new { slug = customUrl.RedirectToUrl });
                    if (customUrl.IsPermanentRedirect)
                    {
                        Response.RedirectPermanent(redirectUrl);
                    }
                    else
                    {
                        Response.Redirect(redirectUrl);
                    }
                }
                if (cat == null)
                {
                    StoreExceptionHelper.ShowInfo(Localization.GetString("CategoryNotFound"));
                }
                else if (!HccApp.CatalogServices.TestCategoryAccess(cat))
                {
                    StoreExceptionHelper.ShowInfo(Localization.GetString("CategoryNotEnoughPermission"));
                }
            }
            else
            {
                cat = new Category
                {
                    Bvin = string.Empty,
                    PreContentColumnId  = preContentColumnId,
                    PostContentColumnId = postContentColumnId
                };
            }

            return(new CategoryPageViewModel {
                LocalCategory = cat
            });
        }
        private OrderViewModel LoadReceiptOrderModel()
        {
            if (Request.Params["id"] != null)
            {
                var o = HccApp.OrderServices.Orders.FindForCurrentStore(Request.Params["id"]);
                if (o == null)
                {
                    StoreExceptionHelper.ShowError(Localization.GetString("OrderNotFound"));
                }

                if (o.CustomProperties.GetProperty("hcc", "allowpasswordreset") == "1" &&
                    MembershipProviderConfig.PasswordRetrievalEnabled)
                {
                    ViewBag.AllowPasswordReset = true;
                    ViewBag.Email     = o.UserEmail;
                    ViewBag.OrderBvin = o.bvin;
                }
                else
                {
                    ViewBag.AllowPasswordReset = false;

                    if (HccApp.CurrentCustomerId != o.UserID)
                    {
                        StoreExceptionHelper.ShowInfo(Localization.GetString("PleaseLogin"));
                    }
                }

                var model = new OrderViewModel(o);

                var paySummary = HccApp.OrderServices.PaymentSummary(o);
                ViewBag.OrderPaymentSummary = paySummary;

                if (o.IsRecurring)
                {
                    foreach (var item in o.Items)
                    {
                        item.RecurringBilling.LoadPaymentInfo(HccApp);
                    }
                }

                // File Downloads
                var fileDownloads = new List <ProductFile>();
                if (o.PaymentStatus == OrderPaymentStatus.Paid && o.StatusCode != OrderStatusCode.OnHold)
                {
                    foreach (var item in o.Items)
                    {
                        if (item.ProductId != string.Empty)
                        {
                            var productFiles = HccApp.CatalogServices.ProductFiles.FindByProductId(item.ProductId);
                            foreach (var file in productFiles)
                            {
                                fileDownloads.Add(file);
                            }
                        }
                    }
                }
                ViewBag.FileDownloads = fileDownloads;

                if (!string.IsNullOrEmpty(SessionManager.AnalyticsOrderId))
                {
                    HccApp.AnalyticsService.RegisterEvent(HccApp.CurrentCustomerId, ActionTypes.ChekoutCompleted, null);
                    RenderAnalytics(o);
                    SessionManager.AnalyticsOrderId = string.Empty;
                }

                return(model);
            }
            StoreExceptionHelper.ShowError(Localization.GetString("OrderNumberMissing"));

            return(null);
        }