Skip to content

Commit f8279ef

Browse files
committed
Refactored and removed CurrencySettings.PrimaryStoreCurrencyId
1 parent e85a366 commit f8279ef

36 files changed

Lines changed: 765 additions & 837 deletions

src/Libraries/SmartStore.Core/Domain/Directory/CurrencySettings.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-

2-
using SmartStore.Core.Configuration;
1+
using SmartStore.Core.Configuration;
32

43
namespace SmartStore.Core.Domain.Directory
54
{
65
public class CurrencySettings : ISettings
76
{
8-
public int PrimaryStoreCurrencyId { get; set; }
97
public int PrimaryExchangeRateCurrencyId { get; set; }
108
public string ActiveExchangeRateProviderSystemName { get; set; }
119
public bool AutoUpdateEnabled { get; set; }

src/Libraries/SmartStore.Core/Domain/Stores/Store.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public partial class Store : BaseEntity
6767
/// Gets or sets the primary store currency identifier
6868
/// </summary>
6969
[DataMember]
70-
public int? PrimaryStoreCurrencyId { get; set; }
70+
public int PrimaryStoreCurrencyId { get; set; }
7171

7272
/// <summary>
7373
/// Gets or sets the primary exchange rate currency identifier
7474
/// </summary>
7575
[DataMember]
76-
public int? PrimaryExchangeRateCurrencyId { get; set; }
76+
public int PrimaryExchangeRateCurrencyId { get; set; }
7777

7878
/// <summary>
7979
/// Gets or sets the primary store currency

src/Libraries/SmartStore.Data/Mapping/Stores/StoreMap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public StoreMap()
1515
this.Property(s => s.SecureUrl).HasMaxLength(400);
1616
this.Property(s => s.Hosts).HasMaxLength(1000);
1717

18-
this.HasOptional(s => s.PrimaryStoreCurrency)
18+
this.HasRequired(s => s.PrimaryStoreCurrency)
1919
.WithMany()
2020
.HasForeignKey(s => s.PrimaryStoreCurrencyId).WillCascadeOnDelete(false);
2121

22-
this.HasOptional(s => s.PrimaryExchangeRateCurrency)
22+
this.HasRequired(s => s.PrimaryExchangeRateCurrency)
2323
.WithMany()
2424
.HasForeignKey(s => s.PrimaryExchangeRateCurrencyId).WillCascadeOnDelete(false);
2525
}

src/Libraries/SmartStore.Data/Migrations/201506261028198_PrimaryStoreCurrencyMultiStore.resx

Lines changed: 0 additions & 126 deletions
This file was deleted.

src/Libraries/SmartStore.Data/Migrations/201506261028198_PrimaryStoreCurrencyMultiStore.Designer.cs renamed to src/Libraries/SmartStore.Data/Migrations/201506261756463_PrimaryStoreCurrencyMultiStore.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Libraries/SmartStore.Data/Migrations/201506261028198_PrimaryStoreCurrencyMultiStore.cs renamed to src/Libraries/SmartStore.Data/Migrations/201506261756463_PrimaryStoreCurrencyMultiStore.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
namespace SmartStore.Data.Migrations
22
{
3-
using System;
4-
using System.Linq;
53
using System.Data.Entity.Migrations;
4+
using System.Linq;
65
using SmartStore.Core.Domain.Configuration;
7-
using SmartStore.Data.Setup;
86
using SmartStore.Core.Domain.Stores;
7+
using SmartStore.Data.Setup;
98

109
public partial class PrimaryStoreCurrencyMultiStore : DbMigration, ILocaleResourcesProvider, IDataSeeder<SmartObjectContext>
1110
{
1211
public override void Up()
1312
{
14-
AddColumn("dbo.Store", "PrimaryStoreCurrencyId", c => c.Int());
15-
AddColumn("dbo.Store", "PrimaryExchangeRateCurrencyId", c => c.Int());
13+
AddColumn("dbo.Store", "PrimaryStoreCurrencyId", c => c.Int(nullable: false));
14+
AddColumn("dbo.Store", "PrimaryExchangeRateCurrencyId", c => c.Int(nullable: false));
1615
CreateIndex("dbo.Store", "PrimaryStoreCurrencyId");
1716
CreateIndex("dbo.Store", "PrimaryExchangeRateCurrencyId");
1817
AddForeignKey("dbo.Store", "PrimaryExchangeRateCurrencyId", "dbo.Currency", "Id");

src/Libraries/SmartStore.Data/Migrations/201506261756463_PrimaryStoreCurrencyMultiStore.resx

Lines changed: 126 additions & 0 deletions
Large diffs are not rendered by default.

src/Libraries/SmartStore.Data/Setup/SeedData/InvariantSeedData.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public IList<Store> Stores()
7373
var seName = GetSeName("company-logo");
7474
var imgCompanyLogo = _ctx.Set<Picture>().Where(x => x.SeoFilename == seName).FirstOrDefault();
7575

76+
var currency = _ctx.Set<Currency>().FirstOrDefault(x => x.CurrencyCode == "EUR");
77+
if (currency == null)
78+
currency = _ctx.Set<Currency>().First();
79+
7680
var entities = new List<Store>()
7781
{
7882
new Store()
@@ -82,7 +86,9 @@ public IList<Store> Stores()
8286
Hosts = "yourstore.com,www.yourstore.com",
8387
SslEnabled = false,
8488
DisplayOrder = 1,
85-
LogoPictureId = imgCompanyLogo.Id
89+
LogoPictureId = imgCompanyLogo.Id,
90+
PrimaryStoreCurrencyId = currency.Id,
91+
PrimaryExchangeRateCurrencyId = currency.Id
8692
}
8793
};
8894
this.Alter(entities);
@@ -4244,8 +4250,6 @@ public IList<ISettings> Settings()
42444250
},
42454251
new CurrencySettings()
42464252
{
4247-
PrimaryStoreCurrencyId = _ctx.Set<Currency>().First().Id,
4248-
PrimaryExchangeRateCurrencyId = _ctx.Set<Currency>().First().Id,
42494253
},
42504254
new MeasureSettings()
42514255
{

src/Libraries/SmartStore.Data/SmartStore.Data.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@
285285
<Compile Include="Migrations\201506261018157_Merge.Designer.cs">
286286
<DependentUpon>201506261018157_Merge.cs</DependentUpon>
287287
</Compile>
288-
<Compile Include="Migrations\201506261028198_PrimaryStoreCurrencyMultiStore.cs" />
289-
<Compile Include="Migrations\201506261028198_PrimaryStoreCurrencyMultiStore.Designer.cs">
290-
<DependentUpon>201506261028198_PrimaryStoreCurrencyMultiStore.cs</DependentUpon>
288+
<Compile Include="Migrations\201506261756463_PrimaryStoreCurrencyMultiStore.cs" />
289+
<Compile Include="Migrations\201506261756463_PrimaryStoreCurrencyMultiStore.Designer.cs">
290+
<DependentUpon>201506261756463_PrimaryStoreCurrencyMultiStore.cs</DependentUpon>
291291
</Compile>
292292
<Compile Include="Setup\Builder\SettingsBuilder.cs" />
293293
<Compile Include="Setup\Builder\SettingsMigrator.cs" />
@@ -555,8 +555,8 @@
555555
<EmbeddedResource Include="Migrations\201506261018157_Merge.resx">
556556
<DependentUpon>201506261018157_Merge.cs</DependentUpon>
557557
</EmbeddedResource>
558-
<EmbeddedResource Include="Migrations\201506261028198_PrimaryStoreCurrencyMultiStore.resx">
559-
<DependentUpon>201506261028198_PrimaryStoreCurrencyMultiStore.cs</DependentUpon>
558+
<EmbeddedResource Include="Migrations\201506261756463_PrimaryStoreCurrencyMultiStore.resx">
559+
<DependentUpon>201506261756463_PrimaryStoreCurrencyMultiStore.cs</DependentUpon>
560560
</EmbeddedResource>
561561
<EmbeddedResource Include="Sql\Indexes.sql" />
562562
<EmbeddedResource Include="Sql\StoredProcedures.sql" />

src/Libraries/SmartStore.Services/Directory/CurrencyService.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public partial class CurrencyService : ICurrencyService
3333
private readonly IPluginFinder _pluginFinder;
3434
private readonly IEventPublisher _eventPublisher;
3535
private readonly IProviderManager _providerManager;
36+
private readonly IStoreContext _storeContext;
3637

3738
#endregion
3839

@@ -53,7 +54,8 @@ public CurrencyService(ICacheManager cacheManager,
5354
CurrencySettings currencySettings,
5455
IPluginFinder pluginFinder,
5556
IEventPublisher eventPublisher,
56-
IProviderManager providerManager)
57+
IProviderManager providerManager,
58+
IStoreContext storeContext)
5759
{
5860
this._cacheManager = cacheManager;
5961
this._currencyRepository = currencyRepository;
@@ -62,6 +64,7 @@ public CurrencyService(ICacheManager cacheManager,
6264
this._pluginFinder = pluginFinder;
6365
this._eventPublisher = eventPublisher;
6466
this._providerManager = providerManager;
67+
this._storeContext = storeContext;
6568
}
6669

6770
#endregion
@@ -268,11 +271,13 @@ public virtual decimal ConvertFromPrimaryExchangeRateCurrency(decimal amount, Cu
268271
/// </summary>
269272
/// <param name="amount">Amount</param>
270273
/// <param name="sourceCurrencyCode">Source currency code</param>
274+
/// <param name="store">Store to get the primary store currency from</param>
271275
/// <returns>Converted value</returns>
272-
public virtual decimal ConvertToPrimaryStoreCurrency(decimal amount, Currency sourceCurrencyCode)
276+
public virtual decimal ConvertToPrimaryStoreCurrency(decimal amount, Currency sourceCurrencyCode, Store store = null)
273277
{
274278
decimal result = amount;
275-
var primaryStoreCurrency = GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId);
279+
var primaryStoreCurrency = (store == null ? _storeContext.CurrentStore.PrimaryStoreCurrency : store.PrimaryStoreCurrency);
280+
276281
if (result != decimal.Zero && sourceCurrencyCode.Id != primaryStoreCurrency.Id)
277282
{
278283
decimal exchangeRate = sourceCurrencyCode.Rate;
@@ -289,10 +294,10 @@ public virtual decimal ConvertToPrimaryStoreCurrency(decimal amount, Currency so
289294
/// <param name="amount">Amount</param>
290295
/// <param name="targetCurrencyCode">Target currency code</param>
291296
/// <returns>Converted value</returns>
292-
public virtual decimal ConvertFromPrimaryStoreCurrency(decimal amount, Currency targetCurrencyCode)
297+
public virtual decimal ConvertFromPrimaryStoreCurrency(decimal amount, Currency targetCurrencyCode, Store store = null)
293298
{
294299
decimal result = amount;
295-
var primaryStoreCurrency = GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId);
300+
var primaryStoreCurrency = (store == null ? _storeContext.CurrentStore.PrimaryStoreCurrency : store.PrimaryStoreCurrency);
296301
result = ConvertCurrency(amount, primaryStoreCurrency, targetCurrencyCode);
297302
return result;
298303
}

0 commit comments

Comments
 (0)