diff --git a/resources/fileTemplates/code/Magento Module DI Xml Plugin.xml.ft b/resources/fileTemplates/code/Magento Module DI Xml Plugin.xml.ft
index 062b13b67..5dde452f4 100644
--- a/resources/fileTemplates/code/Magento Module DI Xml Plugin.xml.ft
+++ b/resources/fileTemplates/code/Magento Module DI Xml Plugin.xml.ft
@@ -2,7 +2,12 @@
#end
+#if (${SORT_ORDER})
+ type="${PLUGIN_TYPE}"
+ sortOrder="${SORT_ORDER}" />
+#else
+ type="${PLUGIN_TYPE}" />
+#end
#if (${TYPE})
#end
\ No newline at end of file
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form
index 4434c7a9b..405f17927 100644
--- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form
+++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form
@@ -131,7 +131,6 @@
-
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java
index 8ae752ad8..b6b551adb 100644
--- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java
+++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java
@@ -82,8 +82,6 @@ public class CreateAPluginDialog extends AbstractDialog {
message = {DirectoryRule.MESSAGE, DIRECTORY})
private JTextField pluginDirectory;
- @FieldValidation(rule = RuleRegistry.NOT_EMPTY,
- message = {NotEmptyRule.MESSAGE, SORT_ORDER})
@FieldValidation(rule = RuleRegistry.NUMERIC,
message = {NumericRule.MESSAGE, SORT_ORDER})
private JTextField pluginSortOrder;
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGenerator.java
index e4e10d39c..70338c250 100644
--- a/src/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGenerator.java
+++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGenerator.java
@@ -161,6 +161,9 @@ protected void fillAttributes(final Properties attributes) {
attributes.setProperty("NAME", pluginFileData.getPluginName());
attributes.setProperty("PLUGIN_TYPE", pluginFileData.getPluginFqn());
attributes.setProperty("PLUGIN_NAME", pluginFileData.getPluginName());
- attributes.setProperty("SORT_ORDER", pluginFileData.getSortOrder());
+ final String sortOrder = pluginFileData.getSortOrder();
+ if (!sortOrder.isEmpty()) {
+ attributes.setProperty("SORT_ORDER", sortOrder);
+ }
}
}
diff --git a/testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneDiXml/di.xml b/testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneDiXml/di.xml
index a8d0b89ab..6a1235ecb 100644
--- a/testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneDiXml/di.xml
+++ b/testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneDiXml/di.xml
@@ -3,10 +3,12 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
+ type="Foo\Bar\Plugin\TestOnePlugin"
+ sortOrder="10"/>
+ type="Foo\Bar\Plugin\TestTwoPlugin"
+ sortOrder="20"/>
diff --git a/testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneTargetClass/di.xml b/testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneTargetClass/di.xml
index 5f4aa8fa2..4e7a51e74 100644
--- a/testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneTargetClass/di.xml
+++ b/testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneTargetClass/di.xml
@@ -3,8 +3,10 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
+ type="Foo\Bar\Plugin\TestOnePlugin"
+ sortOrder="10"/>
+ type="Foo\Bar\Plugin\TestTwoPlugin"
+ sortOrder="20"/>
diff --git a/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForAdminhtmlArea/di.xml b/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForAdminhtmlArea/di.xml
index 68c5acc74..290ad7910 100644
--- a/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForAdminhtmlArea/di.xml
+++ b/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForAdminhtmlArea/di.xml
@@ -3,6 +3,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
+ type="Foo\Bar\Plugin\TestTwoPlugin"
+ sortOrder="20"/>
diff --git a/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForBaseArea/di.xml b/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForBaseArea/di.xml
index 9e6b3baf7..66938302a 100644
--- a/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForBaseArea/di.xml
+++ b/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForBaseArea/di.xml
@@ -3,6 +3,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
+ type="Foo\Bar\Plugin\TestOnePlugin"
+ sortOrder="10"/>
diff --git a/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileWithoutSortOrder/di.xml b/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileWithoutSortOrder/di.xml
new file mode 100644
index 000000000..83161f7e6
--- /dev/null
+++ b/testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileWithoutSortOrder/di.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGeneratorTest.java
index c3f2ea3d7..9358295c6 100644
--- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGeneratorTest.java
+++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/PluginDiXmlGeneratorTest.java
@@ -24,6 +24,31 @@ public class PluginDiXmlGeneratorTest extends BaseGeneratorTestCase {
private static final String PLUGIN_CLASS_TWO_FNQ = "Foo\\Bar\\Plugin\\TestTwoPlugin";
private static final String MODULE = "Foo_Bar";
private static final String MODULE_DIR = "src/app/code/Foo/Bar/";
+ private static final String TEST_PLUGIN_NAME = "test_plugin_name_1";
+
+ /**
+ * Test checks whether di.xml is generated correctly for the base area
+ */
+ public void testGeneratePluginDiXmlFileWithoutSortOrder() {
+ final PsiFile expectedFile = myFixture.configureByFile(
+ this.getFixturePath(ModuleDiXml.FILE_NAME)
+ );
+ final String area = Areas.base.toString();
+
+ final PsiFile diXml = addPluginDiXml(
+ PLUGIN_TARGET_CLASS_ONE_FNQ,
+ area,
+ "",
+ TEST_PLUGIN_NAME,
+ PLUGIN_CLASS_ONE_FNQ
+ );
+
+ assertGeneratedFileIsCorrect(
+ expectedFile,
+ getExpectedDirectory(area),
+ diXml
+ );
+ }
/**
* Test checks whether di.xml is generated correctly for the base area
@@ -37,7 +62,7 @@ public void testGeneratePluginDiXmlFileForBaseArea() {
PLUGIN_TARGET_CLASS_ONE_FNQ,
area,
"10",
- "test_plugin_name_1",
+ TEST_PLUGIN_NAME,
PLUGIN_CLASS_ONE_FNQ
);
@@ -82,7 +107,7 @@ public void testAddTwoPluginsToOneDiXml() {
PLUGIN_TARGET_CLASS_ONE_FNQ,
area,
"10",
- "test_plugin_name_1",
+ TEST_PLUGIN_NAME,
PLUGIN_CLASS_ONE_FNQ
);
final PsiFile diXml = addPluginDiXml(
@@ -111,7 +136,7 @@ public void testAddTwoPluginsToOneTargetClass() {
PLUGIN_TARGET_CLASS_ONE_FNQ,
area,
"10",
- "test_plugin_name_1",
+ TEST_PLUGIN_NAME,
PLUGIN_CLASS_ONE_FNQ
);
final PsiFile diXml = addPluginDiXml(