public static TPropType GetArticleAttribute <TPropType>(this IArticleAttributeService genericAttributeService, string entityName, int entityId, string key, int siteId = 0)
        {
            Guard.ArgumentNotNull(() => genericAttributeService);
            Guard.ArgumentNotEmpty(() => entityName);

            var props = genericAttributeService.GetAttributesForEntity(entityId, entityName);

            // little hack here (only for unit testing). we should write expect-return rules in unit tests for such cases
            if (props == null)
            {
                return(default(TPropType));
            }

            //if (!props.Any(x => x.SiteId == siteId))
            //{
            //    return default(TPropType);
            //}

            var prop = props.FirstOrDefault(ga => ga.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)); //should be culture invariant

            if (prop == null || prop.Value.IsEmpty())
            {
                return(default(TPropType));
            }

            return(prop.Value.Convert <TPropType>());
        }
        /// <summary>
        /// Get an attribute of an entity
        /// </summary>
        /// <typeparam name="TPropType">Property type</typeparam>
        /// <param name="entity">Entity</param>
        /// <param name="key">Key</param>
        /// <param name="genericAttributeService">ArticleAttributeService</param>
        /// <param name="siteId">Load a value specific for a certain store; pass 0 to load a value shared for all stores</param>
        /// <returns>Attribute</returns>
        public static TPropType GetArticleAttribute <TPropType>(this BaseEntity entity,
                                                                string key, IArticleAttributeService genericAttributeService, int siteId = 0)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            if (genericAttributeService == null)
            {
                genericAttributeService = EngineContext.Current.Resolve <IArticleAttributeService>();
            }

            string keyGroup = entity.GetUnproxiedEntityType().Name;

            return(genericAttributeService.GetArticleAttribute <TPropType>(keyGroup, entity.Id, key, siteId));

            #region Old
            //var props = genericAttributeService.GetAttributesForEntity(entity.Id, keyGroup);
            ////little hack here (only for unit testing). we should write expect-return rules in unit tests for such cases
            //if (props == null)
            //    return default(TPropType);
            //props = props.Where(x => x.SiteId == siteId).ToList();
            //if (props.Count == 0)
            //    return default(TPropType);

            //var prop = props.FirstOrDefault(ga =>
            //    ga.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)); //should be culture invariant

            //if (prop == null || string.IsNullOrEmpty(prop.Value))
            //    return default(TPropType);

            //return CommonHelper.To<TPropType>(prop.Value);
            #endregion
        }
Exemplo n.º 3
0
 public CopyArticleService(IArticleService articleService,
                           IArticleAttributeService articleAttributeService,
                           ILanguageService languageService,
                           ILocalizedEntityService localizedEntityService,
                           ILocalizationService localizationService,
                           IPictureService pictureService,
                           ICategoryService categoryService,
                           IPublisherService publisherService,
                           ISpecificationAttributeService specificationAttributeService,
                           IDownloadService downloadService,
                           IArticleAttributeParser articleAttributeParser,
                           IUrlRecordService urlRecordService,
                           IStoreMappingService storeMappingService)
 {
     this._articleService                = articleService;
     this._articleAttributeService       = articleAttributeService;
     this._languageService               = languageService;
     this._localizedEntityService        = localizedEntityService;
     this._localizationService           = localizationService;
     this._pictureService                = pictureService;
     this._categoryService               = categoryService;
     this._publisherService              = publisherService;
     this._specificationAttributeService = specificationAttributeService;
     this._downloadService               = downloadService;
     this._articleAttributeParser        = articleAttributeParser;
     this._urlRecordService              = urlRecordService;
     this._storeMappingService           = storeMappingService;
 }
 public ArticleAttributeController(IArticleService articleService,
                                   IArticleAttributeService articleAttributeService,
                                   ILanguageService languageService,
                                   ILocalizedEntityService localizedEntityService,
                                   ILocalizationService localizationService,
                                   ICustomerActivityService customerActivityService,
                                   IPermissionService permissionService)
 {
     this._articleService          = articleService;
     this._articleAttributeService = articleAttributeService;
     this._languageService         = languageService;
     this._localizedEntityService  = localizedEntityService;
     this._localizationService     = localizationService;
     this._customerActivityService = customerActivityService;
     this._permissionService       = permissionService;
 }
Exemplo n.º 5
0
 public ArticleAttributeFormatter(IWorkContext workContext,
                                  IArticleAttributeService articleAttributeService,
                                  IArticleAttributeParser articleAttributeParser,
                                  ICurrencyService currencyService,
                                  ILocalizationService localizationService,
                                  ITaxService taxService,
                                  IPriceFormatter priceFormatter,
                                  IDownloadService downloadService,
                                  IWebHelper webHelper,
                                  IPriceCalculationService priceCalculationService,
                                  ShoppingCartSettings shoppingCartSettings)
 {
     this._workContext             = workContext;
     this._articleAttributeService = articleAttributeService;
     this._articleAttributeParser  = articleAttributeParser;
     this._currencyService         = currencyService;
     this._localizationService     = localizationService;
     this._taxService              = taxService;
     this._priceFormatter          = priceFormatter;
     this._downloadService         = downloadService;
     this._webHelper               = webHelper;
     this._priceCalculationService = priceCalculationService;
     this._shoppingCartSettings    = shoppingCartSettings;
 }
Exemplo n.º 6
0
 public ArticleAttributeParser(IDbContext context,
                               IArticleAttributeService articleAttributeService)
 {
     this._context = context;
     this._articleAttributeService = articleAttributeService;
 }