//edit public ActionResult ProductAttributeValueEditPopup(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); var pav = _productAttributeService.GetProductAttributeValueById(id); if (pav == null) //No attribute value found with the specified id return RedirectToAction("List", "Product"); var product = _productService.GetProductById(pav.ProductAttributeMapping.ProductId); if (product == null) throw new ArgumentException("No product found with the specified id"); //a vendor should have access only to his products if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id) return RedirectToAction("List", "Product"); var associatedProduct = _productService.GetProductById(pav.AssociatedProductId); var model = new ProductModel.ProductAttributeValueModel { ProductAttributeMappingId = pav.ProductAttributeMappingId, AttributeValueTypeId = pav.AttributeValueTypeId, AttributeValueTypeName = pav.AttributeValueType.GetLocalizedEnum(_localizationService, _workContext), AssociatedProductId = pav.AssociatedProductId, AssociatedProductName = associatedProduct != null ? associatedProduct.Name : "", Name = pav.Name, ColorSquaresRgb = pav.ColorSquaresRgb, DisplayColorSquaresRgb = pav.ProductAttributeMapping.AttributeControlType == AttributeControlType.ColorSquares, PriceAdjustment = pav.PriceAdjustment, WeightAdjustment = pav.WeightAdjustment, Cost = pav.Cost, Quantity = pav.Quantity, IsPreSelected = pav.IsPreSelected, DisplayOrder = pav.DisplayOrder, PictureId = pav.PictureId }; if (model.DisplayColorSquaresRgb && String.IsNullOrEmpty(model.ColorSquaresRgb)) { model.ColorSquaresRgb = "#000000"; } //locales AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = pav.GetLocalized(x => x.Name, languageId, false, false); }); //pictures model.ProductPictureModels = _productService.GetProductPicturesByProductId(product.Id) .Select(x => new ProductModel.ProductPictureModel { Id = x.Id, ProductId = x.ProductId, PictureId = x.PictureId, PictureUrl = _pictureService.GetPictureUrl(x.PictureId), DisplayOrder = x.DisplayOrder }) .ToList(); return View(model); }
//create public ActionResult ProductAttributeValueCreatePopup(int productAttributeMappingId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); var productAttributeMapping = _productAttributeService.GetProductAttributeMappingById(productAttributeMappingId); if (productAttributeMapping == null) throw new ArgumentException("No product attribute mapping found with the specified id"); var product = _productService.GetProductById(productAttributeMapping.ProductId); if (product == null) throw new ArgumentException("No product found with the specified id"); //a vendor should have access only to his products if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id) return RedirectToAction("List", "Product"); var model = new ProductModel.ProductAttributeValueModel(); model.ProductAttributeMappingId = productAttributeMappingId; //color squares model.DisplayColorSquaresRgb = productAttributeMapping.AttributeControlType == AttributeControlType.ColorSquares; model.ColorSquaresRgb = "#000000"; //default qantity for associated product model.Quantity = 1; //locales AddLocales(_languageService, model.Locales); //pictures model.ProductPictureModels = _productService.GetProductPicturesByProductId(product.Id) .Select(x => new ProductModel.ProductPictureModel { Id = x.Id, ProductId = x.ProductId, PictureId = x.PictureId, PictureUrl = _pictureService.GetPictureUrl(x.PictureId), DisplayOrder = x.DisplayOrder }) .ToList(); return View(model); }