예제 #1
0
        public string RenderToProductInformation(int productId)
        {
            var discountModel = BuyInTimeService.GetByProduct(productId, DateTime.Now);

            if (discountModel == null)
            {
                return(string.Empty);
            }

            var actionTitle = ModuleSettingsProvider.GetSettingValue <string>("BuyInTimeActionTitle", ModuleStringId);
            var countdown   = discountModel.DateExpired != null
                                ? string.Format(BuyInTimeService.CountdownScript, ((DateTime)discountModel.DateExpired).ToString("dd.MM.yyyy HH:mm:ss"))
                                : string.Empty;

            return(string.Format("<div class=\"buy-in-time-product\"><div class=\"buy-in-time-action-b\">{0}</div> {1}</div>", actionTitle, countdown));
        }
예제 #2
0
        public ProductLabel GetLabel()
        {
            var labelCode = ModuleSettingsProvider.GetSettingValue <string>("BuyInTimeLabel", ModuleStringId);

            if (labelCode.IsNullOrEmpty())
            {
                return(null);
            }

            var productDiscounts = BuyInTimeService.GetProductDiscountsList(DateTime.Now);

            if (productDiscounts == null || productDiscounts.Count == 0)
            {
                return(null);
            }

            return(new ProductLabel()
            {
                LabelCode = labelCode,
                ProductIds = productDiscounts.Select(p => p.ProductId).ToList()
            });
        }
예제 #3
0
 public bool UpdateModule()
 {
     return(BuyInTimeService.UpdateBuyInTimeModule());
 }
예제 #4
0
 public bool UninstallModule()
 {
     return(BuyInTimeService.UninstallBuyInTimeModule());
 }
예제 #5
0
 public bool InstallModule()
 {
     return(BuyInTimeService.InstallBuyInTimeModule() && BuyInTimeService.UpdateBuyInTimeModule());
 }
예제 #6
0
        public string RenderMainPageAfterCarousel()
        {
            var cacheKey = BuyInTimeService.CacheKey + BuyInTimeService.eShowMode.Vertical;

            if (CacheManager.Contains(cacheKey))
            {
                return(CacheManager.Get <string>(cacheKey));
            }

            var action           = BuyInTimeService.GetByShowMode((int)BuyInTimeService.eShowMode.Vertical, DateTime.Now);
            var actionHorizontal = BuyInTimeService.GetByShowMode((int)BuyInTimeService.eShowMode.Horizontal, DateTime.Now);

            if (actionHorizontal != null && action != null && action.Id < actionHorizontal.Id)
            {
                CacheManager.Insert(cacheKey, "");
                return(string.Empty);
            }

            if (action != null)
            {
                if (action.IsRepeat && action.DateExpired < DateTime.Now)
                {
                    action.DateExpired = BuyInTimeService.GetExpireDateTime(action.DateExpired, action.DaysRepeat);
                }

                var actionTitle = ModuleSettingsProvider.GetSettingValue <string>("BuyInTimeActionTitle", ModuleStringId);
                var countdown   = string.Format(BuyInTimeService.CountdownScript, action.DateExpired.ToString("dd.MM.yyyy HH:mm:ss"));

                var actionText = action.ActionText.Replace("#ActionTitle#", actionTitle)
                                 .Replace("#Countdown#", countdown);

                var product = ProductService.GetProduct(action.ProductId);
                if (product == null)
                {
                    return(actionText);
                }

                var offer = product.Offers.FirstOrDefault(o => o.Main) ?? product.Offers.FirstOrDefault();
                if (offer == null)
                {
                    return(actionText);
                }

                actionText =
                    actionText.Replace("#ProductPicture#", action.Picture.IsNotEmpty()
                        ? string.Format("<img src=\"modules/{0}/pictures/{1}\" />", ModuleStringId.ToLower(), action.Picture)
                        : string.Empty)
                    .Replace("#ProductLink#",
                             UrlService.GetLink(ParamType.Product, product.UrlPath, product.ProductId))
                    .Replace("#ProductName#", product.Name)
                    .Replace("#OldPrice#", CatalogService.GetStringPrice(offer.Price).Replace("руб", "р"))
                    .Replace("#NewPrice#",
                             CatalogService.GetStringPrice(offer.Price, action.DiscountInTime).Replace("руб", "р"))
                    .Replace("#DiscountPrice#",
                             CatalogService.GetStringPrice(offer.Price * action.DiscountInTime / 100).Replace("руб", "р"))
                    .Replace("#DiscountPercent#", action.DiscountInTime.ToString("0.##"));

                CacheManager.Insert(cacheKey, actionText);

                return(actionText);
            }

            return(string.Empty);
        }
예제 #7
0
 public List <ProductDiscount> GetProductDiscountsList()
 {
     return(BuyInTimeService.GetProductDiscountsList(DateTime.Now));
 }
예제 #8
0
        public float GetDiscount(int productId)
        {
            var model = BuyInTimeService.GetByProduct(productId, DateTime.Now);

            return(model != null ? model.Discount : 0);
        }