Magento2 : Retrieve Multiselect Values in system.xml
I have created a system.xml file with a multiselect type field somewhere in my admin system config. I just want to know on how to retrieve the selected values in that field?
magento2 module custom system.xml
add a comment |
I have created a system.xml file with a multiselect type field somewhere in my admin system config. I just want to know on how to retrieve the selected values in that field?
magento2 module custom system.xml
I found the solution by using Mage::getStoreConfig(section_group_field path)
– Eubie Aluad
Oct 24 '17 at 9:41
bit.ly/2w7H6y2 using link got all the multiselect attribute.
– Rakesh Jesadiya
Aug 23 '18 at 17:41
add a comment |
I have created a system.xml file with a multiselect type field somewhere in my admin system config. I just want to know on how to retrieve the selected values in that field?
magento2 module custom system.xml
I have created a system.xml file with a multiselect type field somewhere in my admin system config. I just want to know on how to retrieve the selected values in that field?
magento2 module custom system.xml
magento2 module custom system.xml
edited Oct 24 '17 at 10:20
Sarfaraj
378318
378318
asked Oct 24 '17 at 9:19
Eubie AluadEubie Aluad
6311
6311
I found the solution by using Mage::getStoreConfig(section_group_field path)
– Eubie Aluad
Oct 24 '17 at 9:41
bit.ly/2w7H6y2 using link got all the multiselect attribute.
– Rakesh Jesadiya
Aug 23 '18 at 17:41
add a comment |
I found the solution by using Mage::getStoreConfig(section_group_field path)
– Eubie Aluad
Oct 24 '17 at 9:41
bit.ly/2w7H6y2 using link got all the multiselect attribute.
– Rakesh Jesadiya
Aug 23 '18 at 17:41
I found the solution by using Mage::getStoreConfig(section_group_field path)
– Eubie Aluad
Oct 24 '17 at 9:41
I found the solution by using Mage::getStoreConfig(section_group_field path)
– Eubie Aluad
Oct 24 '17 at 9:41
bit.ly/2w7H6y2 using link got all the multiselect attribute.
– Rakesh Jesadiya
Aug 23 '18 at 17:41
bit.ly/2w7H6y2 using link got all the multiselect attribute.
– Rakesh Jesadiya
Aug 23 '18 at 17:41
add a comment |
2 Answers
2
active
oldest
votes
Define source model in system.xml
<field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<Module>Module Position</Module>
<source_model>VendorModuleModelConfigSourceConfigOption</source_model>
</field>
Now create ConfigOption.php at
<?php
namespace VendorModuleModelConfigSource;
class ConfigOption implements MagentoFrameworkOptionArrayInterface
{
public function toOptionArray()
{
return [
['value' => '1', 'label' => __('Top Right')],
['value' => '2', 'label' => __('Top Left')],
['value' => '3', 'label' => __('Middle Right')],
['value' => '4', 'label' => __('Middle')],
['value' => '5', 'label' => __('Middle Left')],
['value' => '6', 'label' => __('Bottom Right')],
['value' => '7', 'label' => __('Bottom Left')]
];
}
}
You will get multiselect value in string with value1,value2,value3
format.
You can use explode() function to convert it into array like this
$value = explode(',', $multiSelectValue);
For more info about how you can get system.xml config value refer this question
Magento2 -How to get data from system configuration
I will note this sire!
– Eubie Aluad
Oct 24 '17 at 9:43
add a comment |
Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like
$miltiselectValues = explode(',', $configValue);
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f198348%2fmagento2-retrieve-multiselect-values-in-system-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Define source model in system.xml
<field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<Module>Module Position</Module>
<source_model>VendorModuleModelConfigSourceConfigOption</source_model>
</field>
Now create ConfigOption.php at
<?php
namespace VendorModuleModelConfigSource;
class ConfigOption implements MagentoFrameworkOptionArrayInterface
{
public function toOptionArray()
{
return [
['value' => '1', 'label' => __('Top Right')],
['value' => '2', 'label' => __('Top Left')],
['value' => '3', 'label' => __('Middle Right')],
['value' => '4', 'label' => __('Middle')],
['value' => '5', 'label' => __('Middle Left')],
['value' => '6', 'label' => __('Bottom Right')],
['value' => '7', 'label' => __('Bottom Left')]
];
}
}
You will get multiselect value in string with value1,value2,value3
format.
You can use explode() function to convert it into array like this
$value = explode(',', $multiSelectValue);
For more info about how you can get system.xml config value refer this question
Magento2 -How to get data from system configuration
I will note this sire!
– Eubie Aluad
Oct 24 '17 at 9:43
add a comment |
Define source model in system.xml
<field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<Module>Module Position</Module>
<source_model>VendorModuleModelConfigSourceConfigOption</source_model>
</field>
Now create ConfigOption.php at
<?php
namespace VendorModuleModelConfigSource;
class ConfigOption implements MagentoFrameworkOptionArrayInterface
{
public function toOptionArray()
{
return [
['value' => '1', 'label' => __('Top Right')],
['value' => '2', 'label' => __('Top Left')],
['value' => '3', 'label' => __('Middle Right')],
['value' => '4', 'label' => __('Middle')],
['value' => '5', 'label' => __('Middle Left')],
['value' => '6', 'label' => __('Bottom Right')],
['value' => '7', 'label' => __('Bottom Left')]
];
}
}
You will get multiselect value in string with value1,value2,value3
format.
You can use explode() function to convert it into array like this
$value = explode(',', $multiSelectValue);
For more info about how you can get system.xml config value refer this question
Magento2 -How to get data from system configuration
I will note this sire!
– Eubie Aluad
Oct 24 '17 at 9:43
add a comment |
Define source model in system.xml
<field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<Module>Module Position</Module>
<source_model>VendorModuleModelConfigSourceConfigOption</source_model>
</field>
Now create ConfigOption.php at
<?php
namespace VendorModuleModelConfigSource;
class ConfigOption implements MagentoFrameworkOptionArrayInterface
{
public function toOptionArray()
{
return [
['value' => '1', 'label' => __('Top Right')],
['value' => '2', 'label' => __('Top Left')],
['value' => '3', 'label' => __('Middle Right')],
['value' => '4', 'label' => __('Middle')],
['value' => '5', 'label' => __('Middle Left')],
['value' => '6', 'label' => __('Bottom Right')],
['value' => '7', 'label' => __('Bottom Left')]
];
}
}
You will get multiselect value in string with value1,value2,value3
format.
You can use explode() function to convert it into array like this
$value = explode(',', $multiSelectValue);
For more info about how you can get system.xml config value refer this question
Magento2 -How to get data from system configuration
Define source model in system.xml
<field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<Module>Module Position</Module>
<source_model>VendorModuleModelConfigSourceConfigOption</source_model>
</field>
Now create ConfigOption.php at
<?php
namespace VendorModuleModelConfigSource;
class ConfigOption implements MagentoFrameworkOptionArrayInterface
{
public function toOptionArray()
{
return [
['value' => '1', 'label' => __('Top Right')],
['value' => '2', 'label' => __('Top Left')],
['value' => '3', 'label' => __('Middle Right')],
['value' => '4', 'label' => __('Middle')],
['value' => '5', 'label' => __('Middle Left')],
['value' => '6', 'label' => __('Bottom Right')],
['value' => '7', 'label' => __('Bottom Left')]
];
}
}
You will get multiselect value in string with value1,value2,value3
format.
You can use explode() function to convert it into array like this
$value = explode(',', $multiSelectValue);
For more info about how you can get system.xml config value refer this question
Magento2 -How to get data from system configuration
edited 3 mins ago
Marko Durasic
31
31
answered Oct 24 '17 at 9:28
Prince PatelPrince Patel
13.3k54676
13.3k54676
I will note this sire!
– Eubie Aluad
Oct 24 '17 at 9:43
add a comment |
I will note this sire!
– Eubie Aluad
Oct 24 '17 at 9:43
I will note this sire!
– Eubie Aluad
Oct 24 '17 at 9:43
I will note this sire!
– Eubie Aluad
Oct 24 '17 at 9:43
add a comment |
Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like
$miltiselectValues = explode(',', $configValue);
add a comment |
Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like
$miltiselectValues = explode(',', $configValue);
add a comment |
Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like
$miltiselectValues = explode(',', $configValue);
Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like
$miltiselectValues = explode(',', $configValue);
answered Oct 24 '17 at 9:29
NikolasNikolas
1,442412
1,442412
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f198348%2fmagento2-retrieve-multiselect-values-in-system-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I found the solution by using Mage::getStoreConfig(section_group_field path)
– Eubie Aluad
Oct 24 '17 at 9:41
bit.ly/2w7H6y2 using link got all the multiselect attribute.
– Rakesh Jesadiya
Aug 23 '18 at 17:41