Skip to content

Commit 2163474

Browse files
committed
GMC: Added a setting to export products only for those for which GMC data is specified
1 parent 507f8d9 commit 2163474

6 files changed

Lines changed: 77 additions & 20 deletions

File tree

src/Smartstore.Modules/Smartstore.Google.MerchantCenter/Components/GmcConfigurationViewComponent.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.AspNetCore.Mvc.Rendering;
3+
using Microsoft.EntityFrameworkCore;
4+
using Smartstore.Core;
5+
using Smartstore.Core.Data;
36
using Smartstore.Google.MerchantCenter.Models;
47
using Smartstore.Web.Components;
58

@@ -10,11 +13,31 @@ namespace Smartstore.Google.MerchantCenter.Components
1013
/// </summary>
1114
public class GmcConfigurationViewComponent : SmartViewComponent
1215
{
13-
public IViewComponentResult Invoke(object data)
16+
private readonly SmartDbContext _db;
17+
private readonly IWorkContext _workContext;
18+
19+
public GmcConfigurationViewComponent(SmartDbContext db, IWorkContext workContext)
20+
{
21+
_db = db;
22+
_workContext = workContext;
23+
}
24+
25+
public async Task<IViewComponentResult> InvokeAsync(object data)
1426
{
1527
var model = data as ProfileConfigurationModel;
1628

17-
ViewBag.LanguageSeoCode = Services.WorkContext.WorkingLanguage.UniqueSeoCode.EmptyNull().ToLower();
29+
var counts = await _db.Products
30+
.Select(_ => new
31+
{
32+
NumProducts = _db.Products.Where(x => !x.IsSystemProduct).Count(),
33+
NumGoogleProducts = _db.GoogleProducts().Count()
34+
})
35+
.FirstAsync();
36+
37+
ViewBag.DefaultValueSettingsNote = T("Plugins.Feed.Froogle.DefaultValueSettingsNote",
38+
counts.NumGoogleProducts.ToString("N0"), counts.NumProducts.ToString("N0"));
39+
40+
ViewBag.LanguageSeoCode = _workContext.WorkingLanguage.UniqueSeoCode.EmptyNull().ToLower();
1841
ViewBag.AvailableCategories = model.DefaultGoogleCategory.HasValue()
1942
? new List<SelectListItem> { new() { Text = model.DefaultGoogleCategory, Value = model.DefaultGoogleCategory, Selected = true } }
2043
: null;

src/Smartstore.Modules/Smartstore.Google.MerchantCenter/Localization/resources.de-de.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@
3737
<Value>Standardwerte</Value>
3838
</LocaleResource>
3939
<LocaleResource Name="DefaultValueSettingsNote">
40-
<Value>Standardwerte werden exportiert, wenn die entsprechende Information für das jeweilge Produkt nicht gepflegt wurde. Für einzelne Produkte können diese Werte sowohl in der Plugin-Konfiguration als auch direkt auf der Bearbeitungsseite des Produktes eingegeben werden.</Value>
40+
<Value>
41+
<![CDATA[Standardwerte werden exportiert, wenn die entsprechende Information für das jeweilge Produkt nicht gepflegt wurde. Für einzelne Produkte können diese Werte
42+
sowohl in der Plugin-Konfiguration als auch direkt auf der Bearbeitungsseite des Produktes eingegeben werden.
43+
Für <strong>{0}</strong> von <strong>{1}</strong> Produkten sind GMC-Daten festgelegt.]]>
44+
</Value>
45+
</LocaleResource>
46+
<LocaleResource Name="ExportAllProducts">
47+
<Value>Alle Produkte exportieren</Value>
48+
</LocaleResource>
49+
<LocaleResource Name="ExportAllProducts.Hint">
50+
<Value>Legt fest, ob alle Produkte exportiert werden (Standard). Falls deaktiviert, werden nur die Produkte exportiert, für die GMC-Daten festgelegt sind.</Value>
4151
</LocaleResource>
4252
<LocaleResource Name="MissingDefaultCategory">
4353
<Value>Standard-Google-Kategorie fehlt</Value>

src/Smartstore.Modules/Smartstore.Google.MerchantCenter/Localization/resources.en-us.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@
3636
<Value>Default values</Value>
3737
</LocaleResource>
3838
<LocaleResource Name="DefaultValueSettingsNote">
39-
<Value>Default values will be exported if the information does not exist or is not available for a particular product. For a particular product, these values can be edited in the plugin configuration and the product edit page.</Value>
39+
<Value>
40+
<![CDATA[Default values will be exported if the information does not exist or is not available for a particular product. For a particular product,
41+
these values can be edited in the plugin configuration and the product edit page. GMC data is set for <strong>{0}</strong> of <strong>{1}</strong> products.]]>
42+
</Value>
43+
</LocaleResource>
44+
<LocaleResource Name="ExportAllProducts">
45+
<Value>Export all products</Value>
46+
</LocaleResource>
47+
<LocaleResource Name="ExportAllProducts.Hint">
48+
<Value>Specifies whether all products are exported (default). If disabled, only products for which GMC data is specified are exported.</Value>
4049
</LocaleResource>
4150
<LocaleResource Name="MissingDefaultCategory">
4251
<Value>Default Google category is not set</Value>

src/Smartstore.Modules/Smartstore.Google.MerchantCenter/Models/ProfileConfigurationModel.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,54 @@
22
{
33
[CustomModelPart]
44
[Serializable]
5+
[LocalizedDisplay("Plugins.Feed.Froogle.")]
56
public class ProfileConfigurationModel
67
{
7-
[LocalizedDisplay("Plugins.Feed.Froogle.DefaultGoogleCategory")]
8+
[LocalizedDisplay("*DefaultGoogleCategory")]
89
public string DefaultGoogleCategory { get; set; }
910

10-
[LocalizedDisplay("Plugins.Feed.Froogle.AdditionalImages")]
11+
[LocalizedDisplay("*ExportAllProducts")]
12+
public bool ExportAllProducts { get; set; } = true;
13+
14+
[LocalizedDisplay("*AdditionalImages")]
1115
public bool AdditionalImages { get; set; } = true;
1216

13-
[LocalizedDisplay("Plugins.Feed.Froogle.Availability")]
17+
[LocalizedDisplay("*Availability")]
1418
public string Availability { get; set; }
1519

16-
[LocalizedDisplay("Plugins.Feed.Froogle.SpecialPrice")]
20+
[LocalizedDisplay("*SpecialPrice")]
1721
public bool SpecialPrice { get; set; } = true;
1822

1923
[UIHint("Gender")]
20-
[LocalizedDisplay("Plugins.Feed.Froogle.Gender")]
24+
[LocalizedDisplay("*Gender")]
2125
public string Gender { get; set; }
2226

2327
[UIHint("AgeGroup")]
24-
[LocalizedDisplay("Plugins.Feed.Froogle.AgeGroup")]
28+
[LocalizedDisplay("*AgeGroup")]
2529
public string AgeGroup { get; set; }
2630

27-
[LocalizedDisplay("Plugins.Feed.Froogle.Color")]
31+
[LocalizedDisplay("*Color")]
2832
public string Color { get; set; }
2933

30-
[LocalizedDisplay("Plugins.Feed.Froogle.Size")]
34+
[LocalizedDisplay("*Size")]
3135
public string Size { get; set; }
3236

33-
[LocalizedDisplay("Plugins.Feed.Froogle.Material")]
37+
[LocalizedDisplay("*Material")]
3438
public string Material { get; set; }
3539

36-
[LocalizedDisplay("Plugins.Feed.Froogle.Pattern")]
40+
[LocalizedDisplay("*Pattern")]
3741
public string Pattern { get; set; }
3842

39-
[LocalizedDisplay("Plugins.Feed.Froogle.ExpirationDays")]
43+
[LocalizedDisplay("*ExpirationDays")]
4044
public int ExpirationDays { get; set; }
4145

42-
[LocalizedDisplay("Plugins.Feed.Froogle.ExportShipping")]
46+
[LocalizedDisplay("*ExportShipping")]
4347
public bool ExportShipping { get; set; }
4448

45-
[LocalizedDisplay("Plugins.Feed.Froogle.ExportShippingTime")]
49+
[LocalizedDisplay("*ExportShippingTime")]
4650
public bool ExportShippingTime { get; set; }
4751

48-
[LocalizedDisplay("Plugins.Feed.Froogle.ExportBasePrice")]
52+
[LocalizedDisplay("*ExportBasePrice")]
4953
public bool ExportBasePrice { get; set; }
5054
}
5155

src/Smartstore.Modules/Smartstore.Google.MerchantCenter/Providers/GmcXmlExportProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ protected override async Task ExportAsync(ExportExecuteContext context, Cancella
115115

116116
Product entity = product.Entity;
117117
var googleProduct = googleProducts.Get(entity.Id);
118-
if (googleProduct != null && !googleProduct.Export)
118+
if ((googleProduct == null && !config.ExportAllProducts) || (googleProduct != null && !googleProduct.Export))
119+
{
119120
continue;
121+
}
120122

121123
writer.WriteStartElement("item");
122124

src/Smartstore.Modules/Smartstore.Google.MerchantCenter/Views/Shared/Components/GmcConfiguration/Default.cshtml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
<div class="head">@T("Plugins.Feed.Froogle.GeneralSettings")</div>
4848
</div>
4949
</div>
50+
<div class="adminRow">
51+
<div class="adminTitle">
52+
<smart-label asp-for="ExportAllProducts" />
53+
</div>
54+
<div class="adminData">
55+
<editor asp-for="ExportAllProducts"></editor>
56+
<span asp-validation-for="ExportAllProducts"></span>
57+
</div>
58+
</div>
5059
<div class="adminRow">
5160
<div class="adminTitle">
5261
<smart-label asp-for="ExportShipping" />
@@ -96,7 +105,7 @@
96105
<div class="admin-config-group">
97106
<div class="title">@T("Plugins.Feed.Froogle.DefaultValueSettings")</div>
98107
<div class="alert alert-info alert-dismissible">
99-
@T("Plugins.Feed.Froogle.DefaultValueSettingsNote")
108+
@Html.Raw(ViewBag.DefaultValueSettingsNote)
100109
<button type="button" class="btn-close" data-dismiss="alert"></button>
101110
</div>
102111
</div>

0 commit comments

Comments
 (0)