Ejemplo n.º 1
0
        //create
        public ActionResult CategoryProductAttributeValueCreatePopup(int categoryProductAttributeId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var pva   = _categoryProductAttributeService.GetCategoryProductAttributeById(categoryProductAttributeId);
            var model = new CategoryProductAttributeValueModel();

            model.CategoryProductAttributeId = categoryProductAttributeId;


            //locales
            AddLocales(_languageService, model.Locales);
            return(View(model));
        }
Ejemplo n.º 2
0
        //edit
        public ActionResult CategoryProductAttributeValueEditPopup(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var pvav = _categoryProductAttributeService.GetCategoryProductAttributeValueById(id);

            if (pvav == null)
            {
                //No attribute value found with the specified id
                return(RedirectToAction("List", "Product"));
            }

            var model = new CategoryProductAttributeValueModel()
            {
                CategoryProductAttributeId = pvav.CategoryProductAttributeId,
                Name                   = pvav.Name,
                ColorSquaresRgb        = pvav.ColorSquaresRgb,
                DisplayColorSquaresRgb = false,
                //PriceAdjustment = pvav.PriceAdjustment,
                //WeightAdjustment = pvav.WeightAdjustment,
                IsPreSelected = pvav.IsPreSelected,
                DisplayOrder  = pvav.DisplayOrder,
                Popularvalue  = pvav.PopularValue,
                Realvalue     = pvav.RealValue
            };

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = pvav.GetLocalized(x => x.Name, languageId, false, false);
            });

            return(View(model));
        }
Ejemplo n.º 3
0
 public static CategoryProductAttributeValue ToEntity(this CategoryProductAttributeValueModel model, CategoryProductAttributeValue destination)
 {
     return(Mapper.Map(model, destination));
 }
Ejemplo n.º 4
0
 public static CategoryProductAttributeValue ToEntity(this CategoryProductAttributeValueModel model)
 {
     return(Mapper.Map <CategoryProductAttributeValueModel, CategoryProductAttributeValue>(model));
 }
Ejemplo n.º 5
0
        protected ProductDetailsModel PrepareProductDetailsPageModel(Product product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            var model = new ProductDetailsModel()
            {
                Id                   = product.Id,
                Name                 = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id),
                ShortDescription     = product.GetLocalized(x => x.ShortDescription, _workContext.WorkingLanguage.Id),
                FullDescription      = product.GetLocalized(x => x.FullDescription, _workContext.WorkingLanguage.Id),
                OrderingComments     = product.GetLocalized(x => x.AdminComment, _workContext.WorkingLanguage.Id, false),
                MetaKeywords         = product.GetLocalized(x => x.MetaKeywords, _workContext.WorkingLanguage.Id),
                MetaDescription      = product.GetLocalized(x => x.MetaDescription, _workContext.WorkingLanguage.Id),
                MetaTitle            = product.GetLocalized(x => x.MetaTitle, _workContext.WorkingLanguage.Id),
                SeName               = product.GetSeName(),
                MinimumOrderQuantity = product.MinimumOrderQuantity.HasValue ? product.MinimumOrderQuantity.Value : 1,
                Favorit              = _favoritsService.IsItemFavorit(_workContext.CurrentCustomer.Id, product.Id)
            };

            //template

            var templateCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_TEMPLATE_MODEL_KEY, product.ProductTemplateId);

            model.ProductTemplateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _productTemplateService.GetProductTemplateById(product.ProductTemplateId);
                if (template == null)
                {
                    template = _productTemplateService.GetAllProductTemplates().FirstOrDefault();
                }
                return(template.ViewPath);
            });

            //pictures
            model.DefaultPictureZoomEnabled = _mediaSettings.DefaultPictureZoomEnabled;
            var pictures = _pictureService.GetPicturesByProductId(product.Id);

            if (pictures.Count > 0)
            {
                //default picture
                model.DefaultPictureModel = new PictureModel()
                {
                    ImageUrl         = _pictureService.GetPictureUrl(pictures.FirstOrDefault()),
                    FullSizeImageUrl = _pictureService.GetPictureUrl(pictures.FirstOrDefault()),
                    Title            = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
                    AlternateText    = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
                };
                //all pictures
                int i = 0;
                foreach (var picture in pictures)
                {
                    model.PictureModels.Add(new PictureModel()
                    {
                        ImageUrl         = _pictureService.GetPictureUrl(picture),
                        FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
                        Title            = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
                        AlternateText    = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
                        Default          = i == 0
                    });
                    i++;
                }
            }
            else
            {
                //no images. set the default one
                model.DefaultPictureModel = new PictureModel()
                {
                    ImageUrl         = _pictureService.GetDefaultPictureUrl(_mediaSettings.ProductDetailsPictureSize),
                    FullSizeImageUrl = _pictureService.GetDefaultPictureUrl(),
                    Title            = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
                    AlternateText    = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
                };
            }

            List <CategoryProductAttributeGroup> _attrGroups         = product.ProductAttributes.Select(x => x.CategoryProductAttribute.CategoryProductGroup).Distinct().ToList();
            List <CategoryAttributeModel>        DisplayedAttributes = new List <CategoryAttributeModel>();

            foreach (var _aG in _attrGroups)
            {
                foreach (var cpa in _aG.CategoryProductAttributes)
                {
                    CategoryAttributeModel cam = new CategoryAttributeModel();
                    cam.Values = new List <CategoryProductAttributeValueModel>();
                    cam.Values.AddRange(cpa.CategoryProductAttributeValues.OrderBy(x => x.DisplayOrder)
                                        .ThenBy(x => x.Name)
                                        .Select(x =>
                    {
                        var md = new CategoryProductAttributeValueModel();
                        if (x.CategoryProductAttribute.AttributeControlType != AttributeControlType.TextBox)
                        {
                            md.Name = x.GetLocalized(z => z.Name, _workContext.WorkingLanguage.Id, false);
                        }
                        else
                        {
                            md.Name = x.Name;
                        }
                        md.IsPreSelected = product.ProductAttributes.Where(p => p.Id == x.Id).Count() > 0;
                        md.CategoryProductAttributeId = x.CategoryProductAttributeId;
                        md.Id                         = x.Id;
                        md.DisplayOrder               = x.DisplayOrder;
                        md.ColorSquaresRgb            = x.ColorSquaresRgb;
                        md.CategoryProductAttributeId = x.CategoryProductAttributeId;
                        return(md);
                    })
                                        .ToList());
                    //cam.Values.ForEach(i =>
                    //{
                    //    i.Name = i.GetLocalized(xi => xi.Name, _workContext.WorkingLanguage.Id, true);
                    //});

                    cam.Name        = cpa.ProductAttribute.GetLocalized(n => n.Name, _workContext.WorkingLanguage.Id, false);
                    cam.ControlType = cpa.AttributeControlType;
                    //cam.Values.ForEach(x =>
                    //{
                    //    x.IsPreSelected = product.ProductAttributes.Where(i => i.Id == x.Id).Count() > 0;
                    //});
                    //foreach (var val in cam.Values)
                    //{
                    //    val.IsPreSelected = product.ProductAttributes.Where(p => p.Id == val.Id).Count() > 0;
                    //}
                    var attrValue = cam.Values.Where(i => i.IsPreSelected).FirstOrDefault();
                    cam.SelectedValue = attrValue;
                    cam.DisplayOrder  = cpa.DisplayOrder;
                    //cam.SelectedValue.Name = attrValue.GetLocalized(v => v.Name, _workContext.WorkingLanguage.Id, true);
                    //cam.Values.ForEach(i => { i.Name = i.GetLocalized(xi => xi.Name, _workContext.WorkingLanguage.Id, true); });
                    DisplayedAttributes.Add(cam);
                }
            }
            model.CategoryAttributes = DisplayedAttributes.OrderBy(x => x.DisplayOrder).ToList();

            //product tags
            foreach (var item in product.ProductTags)
            {
                model.ProductTags.Add(new ProductTagModel()
                {
                    Name         = item.Name,
                    ProductCount = item.ProductCount,
                    Id           = item.Id
                });
            }
            model.CompanyInformationModel               = new CompanyInformationModel();
            model.CompanyInformationModel.CompanyName   = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, _workContext.WorkingLanguage.Id, false);
            model.CompanyInformationModel.CompanySeName = product.Customer.CompanyInformation.GetSeName(_workContext.WorkingLanguage.Id);
            if (model.CompanyInformationModel.CompanyName == null)
            {
                var languages = _languageService.GetAllLanguages().ToList();
                model.CompanyInformationModel.CompanyName = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, languages.Where(l => l.LanguageCulture == "es-MX").FirstOrDefault().Id, false);
                model.CompanyInformationModel.CompanyName = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, languages.Where(l => l.LanguageCulture == "de-DE").FirstOrDefault().Id, false);
                model.CompanyInformationModel.CompanyName = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, languages.Where(l => l.LanguageCulture == "en-US").FirstOrDefault().Id, false);
                model.CompanyInformationModel.CompanyName = product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, languages.Where(l => l.LanguageCulture == "ru-RU").FirstOrDefault().Id, false);
            }

            var prices     = _productPriceService.GetAllProductPrices(model.Id);
            var currencies = _currencyService.GetAllCurrencies().Where(c => c.Published).ToList();

            model.ProductPrices = new List <ProductDetailsModel.ProductPriceModel>();
            var prices_to_delete = prices.Where(p => !currencies.Contains(p.Currency)).ToList();

            prices = prices.Where(p => currencies.Contains(p.Currency)).ToList();
            foreach (var p in prices_to_delete)
            {
                _productPriceService.DeleteProductPriceById(p.Id);
            }
            model.ProductPrices = new List <ProductDetailsModel.ProductPriceModel>();
            foreach (var price in prices)
            {
                model.ProductPrices.Add(new ProductDetailsModel.ProductPriceModel()
                {
                    CurrencyId     = price.CurrencyId,
                    Id             = price.Id,
                    Price          = price.Price,
                    PriceUpdatedOn = price.PriceUpdatedOn,
                    PriceValue     = price.Price.ToString("N2"),
                    ProductId      = price.ProductId,
                    Currency       = new Core.Domain.Directory.Currency()
                    {
                        CurrencyCode = price.Currency.CurrencyCode
                    }
                });
            }

            return(model);
        }
Ejemplo n.º 6
0
        public ActionResult CategoryProductAttributeValueEditPopup(string btnId, string formId, CategoryProductAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var pvav = _categoryProductAttributeService.GetCategoryProductAttributeValueById(model.Id);

            if (pvav == null)
            {
                //No attribute value found with the specified id
                return(RedirectToAction("List", "Product"));
            }


            if (ModelState.IsValid)
            {
                pvav.Name            = model.Name;
                pvav.ColorSquaresRgb = model.ColorSquaresRgb;
                //pvav.PriceAdjustment = model.PriceAdjustment;
                //pvav.WeightAdjustment = model.WeightAdjustment;
                pvav.IsPreSelected = model.IsPreSelected;
                pvav.DisplayOrder  = model.DisplayOrder;
                pvav.PopularValue  = model.Popularvalue;
                if (model.Realvalue.HasValue)
                {
                    pvav.RealValue = model.Realvalue;
                    if (String.IsNullOrEmpty(model.Name))
                    {
                        pvav.Name = ((int)model.Realvalue).ToString();
                    }
                }
                _categoryProductAttributeService.UpdateCategoryProductAttributeValue(pvav);
                UpdateAttributeValueLocales(pvav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 7
0
 protected void UpdateAttributeValueLocales(CategoryProductAttributeValue pvav, CategoryProductAttributeValueModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(pvav,
                                                    x => x.Name,
                                                    localized.Name,
                                                    localized.LanguageId);
     }
 }