Created
April 4, 2019 18:47
-
-
Save hartviglarsen/29cf46d95c9f0cf4e5ca8169d02d94a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using Umbraco.Core; | |
| using Umbraco.Core.Composing; | |
| using Umbraco.Web.Editors; | |
| using Umbraco.Web.PublishedModels; | |
| namespace MvcCourse.Core.Components | |
| { | |
| public class ProductsComponent : IComponent | |
| { | |
| public void Initialize() | |
| { | |
| EditorModelEventManager.SendingContentModel += EditorModelEventManager_SendingContentModel; | |
| } | |
| private void EditorModelEventManager_SendingContentModel(System.Web.Http.Filters.HttpActionExecutedContext sender, EditorModelEventArgs<Umbraco.Web.Models.ContentEditing.ContentItemDisplay> e) | |
| { | |
| if (e.Model.ContentTypeAlias != Products.ModelTypeAlias) | |
| { | |
| return; | |
| } | |
| foreach (var variant in e.Model.Variants) | |
| { | |
| var tab = variant.Tabs.FirstOrDefault(t => t.Label.InvariantContains("shop")); | |
| if (tab != null) | |
| { | |
| tab.Properties = tab.Properties | |
| .Where(p => p.Alias != Products.GetModelPropertyType(x => x.DefaultCurrency).Alias); | |
| } | |
| } | |
| } | |
| public void Terminate() { } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using MvcCourse.Core.Components; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using Umbraco.Core; | |
| using Umbraco.Core.Composing; | |
| namespace MvcCourse.Core.Composers | |
| { | |
| public class ProductsComposer : IUserComposer | |
| { | |
| public void Compose(Composition composition) | |
| { | |
| composition.Components().Append<ProductsComponent>(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment