Sub categories shopware5 - shopware

I am using a custom theme in Shopware, the parent theme is "Bare" theme, when I need to use some data or alter existing data, still I do not understand how I can do this using controllr, plugin or widgets.
Example:- I need to display "sub categories" on my home page main menu.
When I use "{debug}" on my index.tpl I can see all the main categories but the sub categories are not available even though I have created and activated sub categories on my back end.
I checked the configurations settings to make sure if anything is blocking it from showing on front end.
What kind of approach I should use to get this thing done.
What is the solution?
Update index controller?
Any CMS option to enable /disable?
install a plugin?
create a widget?
FYI: This is what I can see on my debug screen on home page (index.tpl)
$sCategory
flag => false
subcategories => Array (0)
childrenCount => 2
7 => Array (23)
id => 7
name => "IVORY & WHITE"
metaKeywords => null

There is a plugin called AdvancedMenu which has to be activated via the Plugin Manager. In the plugin's config you are able to define the nesting level of how deep the category should be shown. This setting set to 2 by default, I guess. After activating the plugin there should be a new variable $sAdvancedMenu available in the Smarty template.
Please have a look: http://en.community.shopware.com/_detail_1602.html?_ga=1.192119343.464766896.1445350898
Another way (without the AdvancedMenu plugin) would be as follows:
There is a Shopware Core class available via Shopware()->Modules()->Categories() that contains a method called sGetWholeCategoryTree($current). This method returns the whole category subtree for any given root category. But in that case you need to create a plugin that is listening to the Enlight_Controller_Front_PostDispatch event or any similar. After assigning the tree to the view you will have access to a hierarchical multidimensional array of categories with their related children.

Related

Alternate shape for EditorTemplate of Field is not being recognized

I need an alternate for the EditorTemplate of an Enumerator Field that's used when the Field has a particular name (PublishingMethod).
Based on the docs, I created a view with the pattern [ShapeType__FieldName] in the same folder as the original shape:
This is not working and still uses the original. I've thought of changing the Editor method in the Driver, but I think that defeats the purpose of alternates, which is that Orchard automatically detects the correct shape as I understand from the docs:
The Orchard framework automatically creates many alternates that you can use in your application. However, you can create templates for these alternate shapes.
Note: I can't use the Shape Tracing module, it never worked even with a clean Orchard install.
The editors in Orchard work different to how Display works. I guess it is so you get a MVC-style experience. Basically, the actual shape returned is of type EditorTemplate, which then binds your model and prefix then renders a partial view with the template name you gave it. What this means is alternates wont work as expected, or as the docs state. The alternates for your field name are actually added to the EditorTemplate shape. So what you can do is add a view called EditorTemplate-PublishingMethod.cshtml with contents like:
#{
var m = (Orchard.Fields.Fields.EnumerationField)Model.Model;
}
#Html.Partial("PublishingMethodEditor", m, new ViewDataDictionary {
TemplateInfo = new TemplateInfo { HtmlFieldPrefix = Model.Prefix }
})
Then add another view called PublishingMethodEditor.cshtml with the overrides you want for your editor. All these views should go in the root of your Views folder.
Another approach would be to implement the IShapeTableProvider interface and adjust the TemplateName property on a certain condition but, meh, that requires code...
Edit 1
If you have that field name on other content types that you don't want to override you can use the override EditorTemplate-ContentTypeName-PublishingMethod.cshtml

Kentico 9: Auto Add Binding in Custom Module

I have created a custom module (actually I have created a handful in recent years, and this same obstacle frustrates me every time) following the Kentico documentation:
https://docs.kentico.com/display/K9/Creating+custom+modules
The problem I end up with every time, is in developing the User Interface for Parent/Child classes. I create a Vertical Tab node, and beneath it I add an edit tab and a Binding tab for the child class. This all works, and I can add and remove bindings at will, but what I can't do is ADD a new child class and bind it.
Using the Standard Edit Binding template, I am able to bind EXISTING Job Titles to the selected Category, but I cannot CREATE a new one from that page:
To solve this, I created a custom Edit Binding template, and added a New Child Class Header Action that points to a New / Edit Object child:
Which gives me a button that I can use to add a new child class (Job Title):
This approach works per se, in that I can click the New Job Title button and create a new item on the subsequent page:
But no binding is created to link the child object (Job Title) to the selected parent object (Category), An even bigger problem is that once I click Save, I am presented with the following:
The new object DOES SAVE, but the post-save navigation is somehow failing. The event log offers little in the way of diagnostics:
So I thought to create a completely custom interface to accomplish my needs here, according to the Kentico documentation:
https://docs.kentico.com/display/K9/Manually+creating+the+interface+for+custom+modules
So I change the Element Content of the New Job Title page to a custom page that I created to post a DataForm for the new object:
Taking care to assign the proper Object Types on the Properties Tab:
The intent was to programmatically create the binding upon save and also handle the correct navigation to avoid the ambiguous parameter error above, but when this page loads, the UIContext.ObjectID and UIContext.ParentObjectID are both 0:
So I cannot create the binding programmatically. I was able however to solve the error that I received by manually assigning the redirect. The experience is still lacking even with this hack, since it returns to the listing page, but the user still has to click "Add Items" to assign the binding after successfully creating it with the custom page I built.
This cannot be the proper way to do this, so any help with getting me on the right track would be greatly appreciated.
In order for the EditedObject to have a value you have to either decorate the page with the EditedObjectAtribute e.g. like this:
[EditedObject("<custom.objecttype>", "<objectid>", ...)]
or set the object yourself:
int objectId = QueryHelper.GetInteger("objectid", 0);
EditedObject = SomeInfoProvider.GetSomeInfo(objectId);
In your case, I'd recommend exploring what query parameters are available on the page and using them to fetch appropriate object(s). Also, make sure "JobCategoryId" is passed to the "New Job Title" dialog so that you can create the binding.
Btw - kudos for well asked question!

OrchardCMS: How to access Content Menu Item boolean field in cshtml view

In orchard, I've added a boolean field called "IsDone" to the built in Content Menu Item content part via that Admin interface. I've then picked an item in Navigation and set the option to "yes" for the corresponding field i added.
In my custom theme, I've copied over MenuItem.cshtml.
How would I get the value of my custom "IsDone" field here?
I've tried something like
dynamic item = Model.ContentItem;
var myValue = item.MenuItem.IsDone.Value;
but I'm pretty sure my syntax is incorrect (because i get null binding errors at runtime).
thanks in advance!
First i suggest you use the shape alternate MenuItemLink-ContentMenuItem.cshtml instead of MenuItem.cshtml to target the content menu item directly.
Secondly, the field is attached to the ContentPart of the menu item. The following code retrieves the boolean field from this content part:
#using Orchard.ContentManagement;
#using System.Linq;
#{
Orchard.ContentManagement.ContentItem lContentItem = Model.Content.ContentItem;
var lBooleanField = lContentItem
.Parts
.Where(p => p.PartDefinition.Name == "ContentMenuItem") // *1
.SelectMany(p => p.Fields.Where(f => f.Name == "IsDone"))
.FirstOrDefault() as Orchard.Fields.Fields.BooleanField;
if (lBooleanField != null)
{
bool? v = lBooleanField.Value;
if (v.HasValue)
{
if (v.Value)
{
#("done")
}
else
{
#("not done")
}
}
else
{
#("not done")
}
}
}
*1
Sadly you cannot simply write lContentItem.As<Orchard.ContentManagement.ContentPart>() here as the first part in the part list is derived from this type, thus you would receive the wrong part.
While #ViRuSTriNiTy's answer is probably correct, it doesn't take advantage of the power of the dynamic objects that Orchard provides.
This is working for me but is a much shorter version:
#Model.Text
#{
bool? IsDone = Model.Content.ContentMenuItem.IsDone.Value;
var IsItDoneThough = (IsDone.HasValue ? IsDone.Value : false);
}
<p>Is it done? #IsItDoneThough</p>
You can see that in the first line I pull in the IsDone field using the dynamic nature of the Model.
For some reason (I'm sure there is a good one somewhere) the BooleanField uses a bool? as its backing value. This means that if you create the new menu item and just leave the checkbox blank it will be null when you query it. After you have saved it as checked it will be true and then if you go back and uncheck it then it will have the value false.
The second line that I've provided IsItDoneThough checks if it has a value yet. If it does then it uses that, otherwise it assumes it to be false.
Shape Alternate
#ViRuSTriNiTy's other advice, to change it to use the MenuItemLink-ContentMenuItem.cshtml instead of MenuItem.cshtml is also important.
The field doesn't exist on other menu items so it will crash if you try to access it. Just rename the .cshtml file to fix this.
Dynamic Model
Just to wrap this up with a little bit of insight as to how I got there (I'm still learning this as well) the way I figured it out is as follows:
.Content is a way of casting the current content item to dynamic, so you can use the dynamic advantages with the rest of line;
When you add the field in the admin panel it looks like it should be right there on the ContentItem, however it actually creates an invisible ContentPart to contain them and calls it whatever the ContentItem's type is.
So if you had added this field to a Page content type you would have used Model.Content.Page.IsDone.Value. If you had made a new content type called banana it would be Model.Content.Banana.IsDone.Value, etc.
Once you are inside the "invisible" part which holds the fields you can finally get at IsDone. This won't give you the actual value yet though. Each Field has its own properties which you can look up in the source code. the IsDone is actually a BooleanField and it exposes its data via the Value property.
Try doing a solution-wide search for : ContentField to see the classes for each of the fields you have available.
Hopefully this will have explained things clearly but I have actually written about using fields in a blog post and as part of my getting started with modules course over on the official docs (its way down in part 3 if you're curious).
Using built-in features instead of IsDone
This seems like a strange approach to do it this way. If you have a Content Item like a Page then you can just use the "Show on a menu" setting on the page.
Go to admin > content > open the page > down near the bottom you will find "Show on a menu":
This will automatically put it into your navigation and then you can move it around to where you want:
After it "IsDone" you can just go back and untick the "Show on a menu" option.
Setting up the alternative .cshtml
To clarify your comments about how to use the alternative, you need to
Copy the file you have at Orchard.Core/Shapes/Views/MenuItem.cshtml over to your theme's view folder so its /Views/MenuItem.cshtml
Rename the copy in your theme to MenuItem-ContentMenuItem.cshtml
Delete probably everything in it and paste in my sample at the start of this post. You don't want most of the original MenuItem.cshtml code in there as it is doing some special tricks to change itself into a different shape which isn't what you want.
Reset your original Orchard.Core/Shapes/Views/MenuItem.cshtml back to the factory default, grab it from the official Orchard repository
Understanding the view names
From your comments you asked about creating more specific views (known as alternates). You can use something call the Shape Tracer to view these. The name of them follows a certain pattern which makes them more and more specific.
You can learn about the alternates on the official docs site:
Accessing and Rendering Shapes
Alternates
To figure out what shape is being used and what alternates are available you can use the shape tracing module which is documented here:
Getting Started with Shape Tracing

extLib / appllicationLayout: how can I define link node to open a page in a new tab?

using extLib's applicationLayout control I'd like to place a link to a different application inside the bannerApplicationLinks node. This basically works fine using a basicLeafNode if it wasn't for the fact that the other application opens in the same browser tab. There apprently isn't any way to set the target for any kind of linking node control.
Before I go ahead and rebuild layout and navigator from scratch so that I can use standard link controls: does probably someone know some kind of well-kept secret how I could accomplish this task the simple way?
This limitation btw. applies to all types of link node elements available from extLib...
It doesn't look like this is easy to add. Unlike normal links, the basicLeafNode does not seem to have a target attribute. If it did, a theme would allow you to set the default value of the target to "_new".
If you want to try extending the basicLeafNode, the code for the component is in com.ibm.xsp.extlib.controls plugin, com.ibm.xsp.extlib.tree.complex.ComplexLeafTreeNode. You would need to add a target property and also expose it in the configuration files in com.ibm.xsp.extlib.config package (extlib-outline_en.properties, extlib-outline.xsp-config and raw-extlib-outline.xsp-config.
The link is written in the renderEntryItemContent method in com.ibm.xsp.extlib.renderkit.html_extended.outline.tree.HtmlTagsRenderer (bear in mind that this covers other link classes, not all of which will have a target attribute).
The best option you have is to use CSS (for targeting) and CSJS in the onLoad event to add the target attribute to the links. In the onLoad you select all links with a specific class (or all links inside a named element) and add the target "_blank" attribute.

Custom theming Drupal 6 Menus

Is there a hook or preprocess function that I can access to write my own theming function for a drupal menu (in this case, primary links)?
I have a rather complex menu structure that requires a little extra markup than I'm currently getting by just rendering the menu items in a block (involving sub-menus with a little custom markup) and really need to get access to build the menu's content variable myself, ideally from an array that has all the primary links and their children in scope.
While it may not be the best solution, it is one that worked quite quickly and painlessly:
Drupal keeps a cached version of all your menus in the cache_menu table, I ran a this query to retreive a serialized string containing all the contents of the menu:
SELECT data FROM menu_cache WHERE serialized = 1 AND cid LIKE 'links:primary_links:%';
Substitute primary_links for whatever the name of your menu is and call unserialize on $row->data to get a structured array of everything you should need to build a custom menu.
I call a function in hook_preprocess_block that swaps the content of the menu block with my own and everything seems to be working fine.

Resources