Skip to content

Commit 0f8f6bd

Browse files
Added Tabs tutorial, Widget tutorial Menu tutorial, Block tutorial, Block tutorial (advanced), Export tutorial, Domain tutorial
1 parent 2ed2f83 commit 0f8f6bd

File tree

173 files changed

+4537
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+4537
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using FluentValidation;
2+
using Smartstore.Core.Content.Blocks;
3+
using Smartstore.Web.Modelling;
4+
5+
namespace MyOrg.BlockTutorial.Blocks
6+
{
7+
[Block("blocktutorial", Icon = "fa fa-eye", FriendlyName = "Block Tutorial")]
8+
public class BlockTutorialBlockHandler : BlockHandlerBase<BlockTutorialBlock>
9+
{
10+
//Doing nothing means standard behaviour.
11+
}
12+
public class BlockTutorialBlock : IBlock
13+
{
14+
[LocalizedDisplay("Plugins.MyOrg.BlockTutorial.Name")]
15+
public string Name { get; set; }
16+
}
17+
public partial class BlockTutorialBlockValidator : AbstractValidator<BlockTutorialBlock>
18+
{
19+
public BlockTutorialBlockValidator()
20+
{
21+
RuleFor(x => x.Name).NotEmpty();
22+
}
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
using Smartstore.Core.OutputCache;
3+
4+
namespace MyOrg.BlockTutorial
5+
{
6+
internal sealed class CacheableRoutes : ICacheableRouteProvider
7+
{
8+
public int Order => 0;
9+
10+
public IEnumerable<string> GetCacheableRoutes()
11+
{
12+
return new string[]
13+
{
14+
"vc:MyOrg.BlockTutorial/BlockTutorialViewComponent"
15+
};
16+
}
17+
}
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Mvc;
3+
using MyOrg.BlockTutorial.Models;
4+
using Smartstore;
5+
using Smartstore.Core.Data;
6+
using Smartstore.Web.Components;
7+
using Smartstore.Web.Models.Catalog;
8+
9+
namespace MyOrg.BlockTutorial.Components
10+
{
11+
public class BlockTutorialViewComponent : SmartViewComponent
12+
{
13+
private readonly SmartDbContext _db;
14+
15+
public BlockTutorialViewComponent(SmartDbContext db)
16+
{
17+
_db = db;
18+
}
19+
20+
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object model)
21+
{
22+
if (widgetZone != "productdetails_pictures_top")
23+
{
24+
return Empty();
25+
}
26+
27+
if (model.GetType() != typeof(ProductDetailsModel))
28+
{
29+
return Empty();
30+
}
31+
32+
var productModel = (ProductDetailsModel)model;
33+
var product = await _db.Products.FindByIdAsync(productModel.Id);
34+
var attrValue = product.GenericAttributes.Get<string>("BlockTutorialMyTabValue");
35+
36+
var viewComponentModel = new ViewComponentModel
37+
{
38+
MyTabValue = attrValue
39+
};
40+
41+
return View(viewComponentModel);
42+
}
43+
}
44+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Smartstore.Core.Configuration;
2+
3+
namespace MyOrg.BlockTutorial.Settings
4+
{
5+
public class BlockTutorialSettings : ISettings
6+
{
7+
public string Name { get; set; } = "John Smith";
8+
}
9+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Mvc;
3+
using MyOrg.BlockTutorial.Models;
4+
using MyOrg.BlockTutorial.Settings;
5+
using Smartstore;
6+
using Smartstore.ComponentModel;
7+
using Smartstore.Core.Data;
8+
using Smartstore.Web.Controllers;
9+
using Smartstore.Web.Modelling.Settings;
10+
11+
namespace MyOrg.BlockTutorial.Controllers
12+
{
13+
public class BlockTutorialAdminController : AdminController
14+
{
15+
private readonly SmartDbContext _db;
16+
17+
public BlockTutorialAdminController(SmartDbContext db)
18+
{
19+
_db = db;
20+
}
21+
22+
[LoadSetting]
23+
public IActionResult Configure(BlockTutorialSettings settings)
24+
{
25+
var model = MiniMapper.Map<BlockTutorialSettings, ConfigurationModel>(settings);
26+
return View(model);
27+
}
28+
29+
[HttpPost, SaveSetting]
30+
public IActionResult Configure(ConfigurationModel model, BlockTutorialSettings settings)
31+
{
32+
if (!ModelState.IsValid)
33+
{
34+
return Configure(settings);
35+
}
36+
37+
ModelState.Clear();
38+
MiniMapper.Map(model, settings);
39+
40+
return RedirectToAction(nameof(Configure));
41+
}
42+
43+
public async Task<IActionResult> AdminEditTab(int entityId)
44+
{
45+
var product = await _db.Products.FindByIdAsync(entityId, false);
46+
47+
var model = new AdminEditTabModel
48+
{
49+
EntityId = entityId,
50+
MyTabValue = product.GenericAttributes.Get<string>("BlockTutorialMyTabValue")
51+
};
52+
53+
ViewData.TemplateInfo.HtmlFieldPrefix = "CustomProperties[MyTab]";
54+
return View(model);
55+
}
56+
}
57+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using MyOrg.BlockTutorial.Models;
3+
using MyOrg.BlockTutorial.Settings;
4+
using Smartstore.ComponentModel;
5+
using Smartstore.Web.Controllers;
6+
using Smartstore.Web.Modelling.Settings;
7+
8+
namespace MyOrg.BlockTutorial.Controllers
9+
{
10+
public class BlockTutorialController : PublicController
11+
{
12+
[LoadSetting]
13+
public IActionResult PublicInfo(BlockTutorialSettings settings)
14+
{
15+
var model = MiniMapper.Map<BlockTutorialSettings, PublicInfoModel>(settings);
16+
17+
return View(model);
18+
}
19+
}
20+
}

src/MyOrg.BlockTutorial/Events.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Threading.Tasks;
2+
using MyOrg.BlockTutorial.Models;
3+
using Smartstore;
4+
using Smartstore.Core.Data;
5+
using Smartstore.Events;
6+
using Smartstore.Web.Modelling;
7+
using Smartstore.Web.Rendering.Events;
8+
9+
namespace MyOrg.BlockTutorial
10+
{
11+
public class Events : IConsumer
12+
{
13+
private readonly SmartDbContext _db;
14+
15+
public Events(SmartDbContext db)
16+
{
17+
_db = db;
18+
}
19+
20+
public async Task HandleEventAsync(TabStripCreated eventMessage)
21+
{
22+
var tabStripName = eventMessage.TabStripName;
23+
24+
if (tabStripName == "product-edit")
25+
{
26+
var entityId = ((TabbableModel)eventMessage.Model).Id;
27+
// Add in a custom tab
28+
await eventMessage.TabFactory.AppendAsync(builder => builder
29+
.Text("My Tab")
30+
.Name("tab-MyTab")
31+
.Icon("star", "bi")
32+
.LinkHtmlAttributes(new { data_tab_name = "MyTab" })
33+
.Action("AdminEditTab", "BlockTutorialAdmin", new { entityId })
34+
.Ajax());
35+
}
36+
}
37+
38+
public async Task HandleEventAsync(ModelBoundEvent message)
39+
{
40+
if (!message.BoundModel.CustomProperties.ContainsKey("MyTab"))
41+
return;
42+
43+
if (message.BoundModel.CustomProperties["MyTab"] is not AdminEditTabModel model)
44+
return;
45+
46+
var product = await _db.Products.FindByIdAsync(model.EntityId);
47+
product.GenericAttributes.Set("BlockTutorialMyTabValue", model.MyTabValue);
48+
49+
await _db.SaveChangesAsync();
50+
}
51+
}
52+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Language Name="Deutsch" IsDefault="true" IsRightToLeft="false">
2+
<LocaleResource Name="Plugins.FriendlyName.MyOrg.BlockTutorial" AppendRootKey="false">
3+
<Value>Block Tutorial</Value>
4+
</LocaleResource>
5+
<LocaleResource Name="Plugins.Description.MyOrg.BlockTutorial" AppendRootKey="false">
6+
<Value>Dieses Modul fügt einen Block ein.</Value>
7+
</LocaleResource>
8+
9+
<LocaleResource Name="Plugins.MyOrg.BlockTutorial" AppendRootKey="false">
10+
<Children>
11+
<LocaleResource Name="Name">
12+
<Value>Text zum Speichern</Value>
13+
</LocaleResource>
14+
<LocaleResource Name="Name.Hint">
15+
<Value>Geben Sie hier den Text an, der in der Setting gespeichert werden soll.</Value>
16+
</LocaleResource>
17+
<LocaleResource Name="MyTabValue">
18+
<Value>Text zum Speichern</Value>
19+
</LocaleResource>
20+
<LocaleResource Name="MyTabValue.Hint">
21+
<Value>Geben Sie hier den Text an, der für dieses Produkt gespeichert werden soll.</Value>
22+
</LocaleResource>
23+
</Children>
24+
</LocaleResource>
25+
</Language>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Language Name="English" IsDefault="false" IsRightToLeft="false">
2+
<LocaleResource Name="Plugins.FriendlyName.MyOrg.BlockTutorial" AppendRootKey="false">
3+
<Value>Block Tutorial</Value>
4+
</LocaleResource>
5+
<LocaleResource Name="Plugins.Description.MyOrg.BlockTutorial" AppendRootKey="false">
6+
<Value>This module adds a block.</Value>
7+
</LocaleResource>
8+
9+
<LocaleResource Name="Plugins.MyOrg.BlockTutorial" AppendRootKey="false">
10+
<Children>
11+
<LocaleResource Name="Name">
12+
<Value>Text to save</Value>
13+
</LocaleResource>
14+
<LocaleResource Name="Name.Hint">
15+
<Value>Enter the text to be saved in the setting.</Value>
16+
</LocaleResource>
17+
<LocaleResource Name="MyTabValue">
18+
<Value>Text to save</Value>
19+
</LocaleResource>
20+
<LocaleResource Name="MyTabValue.Hint">
21+
<Value>Enter the text to be saved for this product.</Value>
22+
</LocaleResource>
23+
</Children>
24+
</LocaleResource>
25+
</Language>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Smartstore.Web.Modelling;
2+
3+
namespace MyOrg.BlockTutorial.Models
4+
{
5+
[CustomModelPart]
6+
public class AdminEditTabModel : ModelBase
7+
{
8+
public int EntityId { get; set; }
9+
10+
[LocalizedDisplay("Plugins.MyOrg.BlockTutorial.MyTabValue")]
11+
public string MyTabValue { get; set; }
12+
}
13+
}

0 commit comments

Comments
 (0)