0

I am trying to get the value of system.xml from a plugin I am developing.

 <field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Seleccionar tienda</label>
                    <source_model>Mageplaza\Simpleshipping\Model\Config\Source\ConfigOption</source_model>
</field>

From the following function I am initially trying to return a test value to show it inside an alert

 public function getSelectStore()
    {
        return "probando";
    }

I am trying to display the return of this variable within a .phtml file using Jquery.

 alert('<?php echo $block->getSelectStore(); ?>'); 
2
  • Can you please elaborate more about config and system. Do you have multiple store?
    – Ankit
    Mar 2 at 2:52
  • No, I need to retrieve the selected value of the field that is selected in a .phtml file Mar 2 at 15:35

2 Answers 2

2

Try this

<?php

namespace Vendor\Module\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

class Data extends AbstractHelper
{
    const XML_PATH_MODULE_CONFIG = 'section_id/group_id/field_id';

    public $_storeManager;
    public function __construct(
        StoreManagerInterface $storeManager,
        ScopeConfigInterface $scopeConfig
    ) {
        $this->_storeManager = $storeManager;
        $this->scopeConfig = $scopeConfig;
    }

    public function getConfigValue($field, $storeId = null)
    {
        return $this->scopeConfig->getValue(
            $field,
            ScopeInterface::SCOPE_STORE,
            $storeId
        );
    }

    public function getConfig($storeId = null)
    {
        return $this->getConfigValue(self::XML_PATH_MODULE_CONFIG, $storeId);
    }
}
2
0

Please find answer below as I assume you did not frame your question correctly.

$(document).ready(function(){ $('select[name="slider_details[slider_location]"]').change(function(){ alert( this.value ); }); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.