Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mariannk committed Sep 5, 2017
2 parents a7563dc + aca617a commit 478b324
Show file tree
Hide file tree
Showing 35 changed files with 365 additions and 98 deletions.
14 changes: 0 additions & 14 deletions src/Libraries/Nop.Core/Caching/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,5 @@ public static void RemoveByPattern(this ICacheManager cacheManager, string patte
//remove matching values
matchesKeys.ForEach(key => cacheManager.Remove(key));
}

/// <summary>
/// Get original (base) entity. Throw an exception if it cannot be loaded
/// </summary>
/// <param name="entity">Entity</param>
/// <returns>Type</returns>
public static Type GetOriginalEntityType(this IEntityForCaching entity)
{
var type = entity.GetType()?.BaseType;
if (type == null)
throw new Exception("Original entity type cannot be loaded");

return type;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public ExternalAuthenticationSettings()
/// </summary>
public bool RequireEmailValidation { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the user is allowed to remove external authentication associations
/// </summary>
public bool AllowCustomersToRemoveAssociations { get; set; }

/// <summary>
/// Gets or sets system names of active payment methods
/// </summary>
Expand Down
28 changes: 28 additions & 0 deletions src/Libraries/Nop.Core/Domain/Directory/Currency.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using Nop.Core.Caching;
using Nop.Core.Domain.Localization;
using Nop.Core.Domain.Stores;

Expand Down Expand Up @@ -80,4 +82,30 @@ public RoundingType RoundingType
}
}

[Serializable]
//Entity Framework will assume that any class that inherits from a POCO class that is mapped to a table on the database requires a Discriminator column
//That's why we have to add [NotMapped] as an attribute of the derived class.
[NotMapped]
public class CurrencyForCaching : Currency, IEntityForCaching
{
public CurrencyForCaching()
{

}
public CurrencyForCaching(Currency c)
{
Id = c.Id;
Name = c.Name;
CurrencyCode = c.CurrencyCode;
Rate = c.Rate;
DisplayLocale = c.DisplayLocale;
CustomFormatting = c.CustomFormatting;
LimitedToStores = c.LimitedToStores;
Published = c.Published;
DisplayOrder = c.DisplayOrder;
CreatedOnUtc = c.CreatedOnUtc;
UpdatedOnUtc = c.UpdatedOnUtc;
RoundingTypeId = c.RoundingTypeId;
}
}
}
29 changes: 28 additions & 1 deletion src/Libraries/Nop.Core/Domain/Localization/Language.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using Nop.Core.Caching;
using Nop.Core.Domain.Stores;

namespace Nop.Core.Domain.Localization
Expand Down Expand Up @@ -53,4 +55,29 @@ public partial class Language : BaseEntity, IStoreMappingSupported
/// </summary>
public int DisplayOrder { get; set; }
}

[Serializable]
//Entity Framework will assume that any class that inherits from a POCO class that is mapped to a table on the database requires a Discriminator column
//That's why we have to add [NotMapped] as an attribute of the derived class.
[NotMapped]
public class LanguageForCaching : Language, IEntityForCaching
{
public LanguageForCaching()
{

}
public LanguageForCaching(Language l)
{
Id = l.Id;
Name = l.Name;
LanguageCulture = l.LanguageCulture;
UniqueSeoCode = l.UniqueSeoCode;
FlagImageFileName = l.FlagImageFileName;
Rtl = l.Rtl;
LimitedToStores = l.LimitedToStores;
DefaultCurrencyId = l.DefaultCurrencyId;
Published = l.Published;
DisplayOrder = l.DisplayOrder;
}
}
}
20 changes: 20 additions & 0 deletions src/Libraries/Nop.Core/Domain/Seo/SeoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,82 @@ public class SeoSettings : ISettings
/// Page title separator
/// </summary>
public string PageTitleSeparator { get; set; }

/// <summary>
/// Page itle SEO adjustment
/// </summary>
public PageTitleSeoAdjustment PageTitleSeoAdjustment { get; set; }

/// <summary>
/// Default title
/// </summary>
public string DefaultTitle { get; set; }

/// <summary>
/// Default META keywords
/// </summary>
public string DefaultMetaKeywords { get; set; }

/// <summary>
/// Default META description
/// </summary>
public string DefaultMetaDescription { get; set; }

/// <summary>
/// A value indicating whether product META descriptions will be generated automatically (if not entered)
/// </summary>
public bool GenerateProductMetaDescription { get; set; }

/// <summary>
/// A value indicating whether we should conver non-wetern chars to western ones
/// </summary>
public bool ConvertNonWesternChars { get; set; }

/// <summary>
/// A value indicating whether unicode chars are allowed
/// </summary>
public bool AllowUnicodeCharsInUrls { get; set; }

/// <summary>
/// A value indicating whether canonical URL tags should be used
/// </summary>
public bool CanonicalUrlsEnabled { get; set; }

/// <summary>
/// A value indicating whether to use canonical URLs with query string parameters
/// </summary>
public bool QueryStringInCanonicalUrlsEnabled { get; set; }

/// <summary>
/// WWW requires (with or without WWW)
/// </summary>
public WwwRequirement WwwRequirement { get; set; }

/// <summary>
/// A value indicating whether JS file bundling and minification is enabled
/// </summary>
public bool EnableJsBundling { get; set; }

/// <summary>
/// A value indicating whether CSS file bundling and minification is enabled
/// </summary>
public bool EnableCssBundling { get; set; }

/// <summary>
/// A value indicating whether Twitter META tags should be generated
/// </summary>
public bool TwitterMetaTags { get; set; }

/// <summary>
/// A value indicating whether Open Graph META tags should be generated
/// </summary>
public bool OpenGraphMetaTags { get; set; }

/// <summary>
/// Slugs (sename) reserved for some other needs
/// </summary>
public List<string> ReservedUrlRecordSlugs { get; set; }

/// <summary>
/// Custom tags in the <![CDATA[<head></head>]]> section
/// </summary>
Expand Down
76 changes: 63 additions & 13 deletions src/Libraries/Nop.Services/Directory/CurrencyService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Nop.Core;
Expand Down Expand Up @@ -44,7 +45,7 @@ public partial class CurrencyService : ICurrencyService

private readonly IRepository<Currency> _currencyRepository;
private readonly IStoreMappingService _storeMappingService;
private readonly ICacheManager _cacheManager;
private readonly IStaticCacheManager _cacheManager;
private readonly CurrencySettings _currencySettings;
private readonly IPluginFinder _pluginFinder;
private readonly IEventPublisher _eventPublisher;
Expand All @@ -62,7 +63,7 @@ public partial class CurrencyService : ICurrencyService
/// <param name="currencySettings">Currency settings</param>
/// <param name="pluginFinder">Plugin finder</param>
/// <param name="eventPublisher">Event published</param>
public CurrencyService(ICacheManager cacheManager,
public CurrencyService(IStaticCacheManager cacheManager,
IRepository<Currency> currencyRepository,
IStoreMappingService storeMappingService,
CurrencySettings currencySettings,
Expand Down Expand Up @@ -106,7 +107,10 @@ public virtual void DeleteCurrency(Currency currency)
{
if (currency == null)
throw new ArgumentNullException(nameof(currency));


if (currency is IEntityForCaching)
throw new ArgumentException("Cacheable entities are not supported by Entity Framework");

_currencyRepository.Delete(currency);

_cacheManager.RemoveByPattern(CURRENCIES_PATTERN_KEY);
Expand All @@ -119,45 +123,85 @@ public virtual void DeleteCurrency(Currency currency)
/// Gets a currency
/// </summary>
/// <param name="currencyId">Currency identifier</param>
/// <param name="loadCacheableCopy">A value indicating whether to load a copy that could be cached (workaround until Entity Framework supports 2-level caching)</param>
/// <returns>Currency</returns>
public virtual Currency GetCurrencyById(int currencyId)
public virtual Currency GetCurrencyById(int currencyId, bool loadCacheableCopy = true)
{
if (currencyId == 0)
return null;

string key = string.Format(CURRENCIES_BY_ID_KEY, currencyId);
return _cacheManager.Get(key, () => _currencyRepository.GetById(currencyId));

Func<Currency> loadCurrencyFunc = () =>
{
return _currencyRepository.GetById(currencyId);
};

if (loadCacheableCopy)
{
//cacheable copy
string key = string.Format(CURRENCIES_BY_ID_KEY, currencyId);
return _cacheManager.Get(key, () =>
{
var currency = loadCurrencyFunc();
if (currency == null)
return null;
return new CurrencyForCaching(currency);
});
}
else
{
return loadCurrencyFunc();
}
}

/// <summary>
/// Gets a currency by code
/// </summary>
/// <param name="currencyCode">Currency code</param>
/// <param name="loadCacheableCopy">A value indicating whether to load a copy that could be cached (workaround until Entity Framework supports 2-level caching)</param>
/// <returns>Currency</returns>
public virtual Currency GetCurrencyByCode(string currencyCode)
public virtual Currency GetCurrencyByCode(string currencyCode, bool loadCacheableCopy = true)
{
if (String.IsNullOrEmpty(currencyCode))
return null;
return GetAllCurrencies(true).FirstOrDefault(c => c.CurrencyCode.ToLower() == currencyCode.ToLower());
return GetAllCurrencies(true, loadCacheableCopy: loadCacheableCopy)
.FirstOrDefault(c => c.CurrencyCode.ToLower() == currencyCode.ToLower());
}

/// <summary>
/// Gets all currencies
/// </summary>
/// <param name="showHidden">A value indicating whether to show hidden records</param>
/// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param>
/// <param name="loadCacheableCopy">A value indicating whether to load a copy that could be cached (workaround until Entity Framework supports 2-level caching)</param>
/// <returns>Currencies</returns>
public virtual IList<Currency> GetAllCurrencies(bool showHidden = false, int storeId = 0)
public virtual IList<Currency> GetAllCurrencies(bool showHidden = false, int storeId = 0, bool loadCacheableCopy = true)
{
string key = string.Format(CURRENCIES_ALL_KEY, showHidden);
var currencies = _cacheManager.Get(key, () =>
Func<IList<Currency>> loadCurrenciesFunc = () =>
{
var query = _currencyRepository.Table;
if (!showHidden)
query = query.Where(c => c.Published);
query = query.OrderBy(c => c.DisplayOrder).ThenBy(c => c.Id);
return query.ToList();
});
};

IList<Currency> currencies;
if (loadCacheableCopy)
{
//cacheable copy
string key = string.Format(CURRENCIES_ALL_KEY, showHidden);
currencies = _cacheManager.Get(key, () =>
{
var result = new List<Currency>();
foreach (var currency in loadCurrenciesFunc())
result.Add(new CurrencyForCaching(currency));
return result;
});
}
else
{
currencies = loadCurrenciesFunc();
}

//store mapping
if (storeId > 0)
Expand All @@ -178,6 +222,9 @@ public virtual void InsertCurrency(Currency currency)
if (currency == null)
throw new ArgumentNullException(nameof(currency));

if (currency is IEntityForCaching)
throw new ArgumentException("Cacheable entities are not supported by Entity Framework");

_currencyRepository.Insert(currency);

_cacheManager.RemoveByPattern(CURRENCIES_PATTERN_KEY);
Expand All @@ -195,6 +242,9 @@ public virtual void UpdateCurrency(Currency currency)
if (currency == null)
throw new ArgumentNullException(nameof(currency));

if (currency is IEntityForCaching)
throw new ArgumentException("Cacheable entities are not supported by Entity Framework");

_currencyRepository.Update(currency);

_cacheManager.RemoveByPattern(CURRENCIES_PATTERN_KEY);
Expand Down
9 changes: 6 additions & 3 deletions src/Libraries/Nop.Services/Directory/ICurrencyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,26 @@ public partial interface ICurrencyService
/// Gets a currency
/// </summary>
/// <param name="currencyId">Currency identifier</param>
/// <param name="loadCacheableCopy">A value indicating whether to load a copy that could be cached (workaround until Entity Framework supports 2-level caching)</param>
/// <returns>Currency</returns>
Currency GetCurrencyById(int currencyId);
Currency GetCurrencyById(int currencyId, bool loadCacheableCopy = true);

/// <summary>
/// Gets a currency by code
/// </summary>
/// <param name="currencyCode">Currency code</param>
/// <param name="loadCacheableCopy">A value indicating whether to load a copy that could be cached (workaround until Entity Framework supports 2-level caching)</param>
/// <returns>Currency</returns>
Currency GetCurrencyByCode(string currencyCode);
Currency GetCurrencyByCode(string currencyCode, bool loadCacheableCopy = true);

/// <summary>
/// Gets all currencies
/// </summary>
/// <param name="showHidden">A value indicating whether to show hidden records</param>
/// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param>
/// <param name="loadCacheableCopy">A value indicating whether to load a copy that could be cached (workaround until Entity Framework supports 2-level caching)</param>
/// <returns>Currencies</returns>
IList<Currency> GetAllCurrencies(bool showHidden = false, int storeId = 0);
IList<Currency> GetAllCurrencies(bool showHidden = false, int storeId = 0, bool loadCacheableCopy = true);

/// <summary>
/// Inserts a currency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Execute()

foreach (var exchageRate in exchangeRates)
{
var currency = _currencyService.GetCurrencyByCode(exchageRate.CurrencyCode);
var currency = _currencyService.GetCurrencyByCode(exchageRate.CurrencyCode, false);
if (currency != null)
{
currency.Rate = exchageRate.Rate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5900,6 +5900,7 @@ protected virtual void InstallSettings(bool installSampleData)
ConvertNonWesternChars = false,
AllowUnicodeCharsInUrls = true,
CanonicalUrlsEnabled = false,
QueryStringInCanonicalUrlsEnabled = false,
WwwRequirement = WwwRequirement.NoMatter,
//we disable bundling out of the box because it requires a lot of server resources
EnableJsBundling = false,
Expand Down Expand Up @@ -6180,7 +6181,8 @@ protected virtual void InstallSettings(bool installSampleData)

settingService.SaveSetting(new ExternalAuthenticationSettings
{
RequireEmailValidation = false
RequireEmailValidation = false,
AllowCustomersToRemoveAssociations = true
});

settingService.SaveSetting(new RewardPointsSettings
Expand Down
Loading

0 comments on commit 478b324

Please sign in to comment.