Is the order of the bundles/apps/plugins inside the generated file var/plugins.json in Shopware 6 important? - shopware

When developing store bundles/apps/plugins in Shopware 6, the file var/plugins.json often has to be generated since it is needed for the build scripts, for example bin/build-administration.sh in the Shopware 6 production template.
Depending on the branch that is being worked on, different bundles/apps/plugins are active. The file var/plugins.json is of course different in each branch, but the order of contents is constantly changing since the bundle:dump command has no integrated sorting which leads to repeated merge conflicts similarly to the composer.lock file, since the order of items changes most of the time.
A possible solution is to ksort the array of bundles/apps/plugins before it gets written into var/plugins.json. However, I'm wondering if this could lead to problems, for example should one plugin be dependent on another. So my question is: Is the order of the bundles inside the generated file var/plugins.json in Shopware 6 important?

The plugins are sorted ascending by the date stored in plugin.installed_at. This affects the order of template inheritance within plugins for example, so generally speaking it matters. Within the plugins.json however I'm not exactly sure if it does though, since it seems to be used by the webpack.config.js for injecting a possible custom webpack config of a plugin, which I think should not come in conflict with each other no matter what the order is.

Related

Shopware 6 - bug with Email template variables

Did someone has a problem with email templates?
In my case when I use email template in Flow builder for trigger "checkout.order.payment_method.changed" email template with type "order confirmation" doesn't work properly. Problem with variables: currency and addresses are null but other variables works properly.
Interesting when I use the same template in Flow builder for trigger "checkout.order.placed" all vars working properly.
p.s. I've updated all extensions and my Shopware version is v6.4.9.0 Stable Version
Maybe it's a Shopware bug or conflict between plugins?
There are some inconsistencies regarding the data available between different Flow-Builder Events. I noticed something similar and created an issue for it here.
Maybe you can add your case there as this sounds related.
Without knowing the exact content of your order confirmation template, eg if it is the default content or if you made changes, it is hard to tell why this wouldn't work. I tested this on the latest release as of today 6.4.13.0 and the combination of said trigger and template seems to work fine. Looking at the history of the OrderStateChangeEventListener, the criteria for the order should've included currency and addresses associations for a while already, including your version. As #newgennerd already said there could potentially be differences between the criteria used for fetching order for state change events and those used for order placed events, as the latter would be the common use case for the order confirmation. So you should keep that in mind.

Override twig template from plugin

I would like to override a block from a twig template from a plugin in my own plugin.
I have overridden native shopware templates in the past, but I have troubles with plugin templates.
The plugin I am trying to adjust is FroshProductCompare and I am also using FroshDevelopmentHelper to easily retrieve the template I am trying to adjust.
Via the development helper, I found out that the template is located at
vendor/store.shopware.com/froshproductcompare/src/Resources/views/storefront/component/compare/section/overview.html.twig
So I created the file at
custom/plugins/ExamplePlugin/Resources/views/storefront/component/compare/section/overview.html.twig
and added
{% sw_extends "#FroshProductCompare/storefront/component/compare/section/overview.html.twig" %}
to the first line of the file.
I have also tried
{% sw_extends "#Storefront/storefront/component/compare/section/overview.html.twig" %}
I have built the storefront and cleared the cache multiple times and I have also reinstalled the plugins in different orders without success.
I found similar questions, which are not the same.
E.G. How to do a template multiple inheritance in Shopware 6?
But the difference here is, that the block is not native to shopware and is created by the plugin.
Any ideas?
The issue is most likely due to plugin load order.
tl;dr: Older plugins (based on installation date) take precedence over newer plugins. But if you want to make sure your plugins take precedence defined the load order in your theme.
It starts with finding the right template in \Shopware\Core\Framework\Adapter\Twig\TemplateFinder::find you can see a queue is build based \Shopware\Core\Framework\Adapter\Twig\TemplateFinder::getNamespaceHierarchy which in turn gets it from \Shopware\Core\Framework\Adapter\Twig\NamespaceHierarchy\NamespaceHierarchyBuilder. The method return the first found template to the order is the key.
The NamespaceHierarchyBuilder is tagged with shopware.twig.hierarchy_builder which is used to inject the following builders:
Shopware\Core\Framework\Adapter\Twig\NamespaceHierarchy\BundleHierarchyBuilder with priority 1000
Shopware\Storefront\Theme\Twig\ThemeNamespaceHierarchyBuilder with priority 500
Since you want to overwrite a template from a plugin with a plugin BundleHierarchyBuilder is the interesting one (all plugins are simply symfony bundles).
BundleHierarchyBuilder is getting the bundles from the kernel (\Shopware\Core\Kernel). The kernel registers the bundles in \Shopware\Core\Kernel::registerBundles and uses an instance of \Shopware\Core\Framework\Plugin\KernelPluginLoader\KernelPluginLoader to load the plugins. The used instance is \Shopware\Core\Framework\Plugin\KernelPluginLoader\DbalKernelPluginLoader as you can see in \Shopware\Core\HttpKernel::createPluginLoader.
As described in this answer DbalKernelPluginLoader loads the plugins based on the installation date. So plugins with an older installation date will be higher up in the list in the TemplateFinder and their template will be returned.
I would actually recommend you this solution: Define the load order in your own theme.

Liferay 6.2 Hook deployment strange behaviour

I have deployed a document library hook which includes many jsp files under custom_jsps.
Recently, I wanted to change folder_action.jsp, so I changed it and deployed it normally in document library portlet.
As it was expected, a folder_action.portal.jsp was created containing the original file.
However, I've noticed something strange. After stopping Tomcat both folder_action.jsp and folder_action.portal.jsp are deleted(this is not happening for the other files that come from the hook), and when it is up again a really strange thing happens. The folder_action.portal.jsp contains the changed file and the folder_action.jsp is the original file.
Has anyone met something similar ever? Any help would be appreciated.
You might run into a very nasty issue: You must only override a particular jsp from exactly one hook. If you override the same jsp from two different hooks, the scenario that you describe might happen (on undeploy). Worse: Order is not maintained, you might have some "wrong" files left over.
Find the two hooks that override the same jsp and determine which you like better (or merge the two). Find some more horror in this answer to a similar question

Multiple custom filters in 1 plugin?

I'm writing a few custom CIFilters for a program. Based on the fact that CIKernel's kernelsWithString: will take multiple kernels from the same file (and a few similar clues I can't recall right now), it seems like I could provide them all in 1 plugin. Am I barking up the wrong tree, or is this doable?
I made an admittedly flawed attempt at this, and the 2 filters do show up. However, one was flawed, and using [[CIFilter filterWithName:filterName] attributes] on it produces null for the parameter list.
I believe I've fixed it now, but [CIPlugIn loadAllPlugIns] "loads newly added image units, but image units (and the filters they contain) that are already loaded are not removed." Either my fix is being ignored, or I haven't actually fixed it. Unless somebody knows a method that unloads a filter (which the Core Image Programming Guide implies is possible), I can't be sure without rebooting.
Apparently I had a misunderstanding of how the CIPlugin system works: it is not global. That is, each program's loaded plugins are independent of other programs'. So to update a plugin, simply close all programs that are using it, and replace the plugin.
To answer the main issue, yes, it's fairly easy to put multiple filters in 1 plugin.
Each filter needs it's own XxxPlugInLoader : NSObject <CIPlugInRegistration> class and Xxx : CIFilter class. (The filters' bundleForClass appear to all load from the same bundle.)
The kernels can be in the same *.cikernel file or not, but if together avoid loading the *.cikernel for each filter (it won't hurt, but it's inefficient).
Set up 1 Description.plist and 1 Description.strings, with the info for all the filters. In the plist, each filter's CIFilterClass entry must match the CIFilter class defined above. Each filters CIAttributeDescription entry is a key into the strings file.

ExpressionEngine file manager - default to thumbnail view

At the moment when you go to select an image inside an entry using the EE default file manager, the default view is 'show files as a list'.
Is there a way to show the thumbnail view as the default?
At this point I would be happy with a core hack.
I don't usually use the file manager for sites (much prefer Assets) but this client had a tight budget
I've wondered about doing this in the past as well - turns out it's pretty simple. Open up ee_filebrowser.js and search for the first instance of a("#dir_choice").val(). Immediately after that add this:
; a("#view_type").val('thumb').change();
Make sure you include the leading ;.
I've only tested this in Safari but I can't see why it wouldn't work everywhere. Incidentally, JS beautifier makes this sort of thing infinitely easier.
I don't recommend hacking core for any reason and I suggest it should be avoided at all cost.
With that said, I will provide what I've found out just the same.
Looks like the following files, in EE 2.5.3, are what you'd want to edit:
/themes/javascript/compressed/jquery/plugins/ee_filebrowser.js
/system/expressionengine/libraries/File_field.php
I found these doing a file search in my text editor for view_type which was from the id of that dropdown. The javascript is minified so you'd probably want to un-minify it and then rewrite the part which handles the switch. I'm not the best JS/jQuery person out there, and un-minified js makes it a bit harder too so, I won't offer any more than what I've found so far.
Consider pulling out the parts parts from the two files if you aren't great with js and maybe start a new post tagged accordingly.
Also note: there might be more to this than just those two files so consider this answer a start and nothing more.

Resources