Adminhtml how to get current scope in ajax controllerHow to add date filed in admin & show on front in magento2Magento 2 :Display attribute option valuesMagento 2 get Current page Browser url in phtml?How to use Context object to get config valuesGet system config option inside source model of another optionGet Config Path value based on website scopeMagento 2 : Error on running magento commandMagento 2 | Add Admin Configuration Button ActionHow to get config field value for all available store views as an array?Magento2.2 How to get userContext into ScopeConfig

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Lay out the Carpet

Minimal reference content

Teaching indefinite integrals that require special-casing

Displaying the order of the columns of a table

How does residential electricity work?

Trouble understanding overseas colleagues

Can I Retrieve Email Addresses from BCC?

Generic lambda vs generic function give different behaviour

Valid Badminton Score?

Cynical novel that describes an America ruled by the media, arms manufacturers, and ethnic figureheads

Why is delta-v is the most useful quantity for planning space travel?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

voltage of sounds of mp3files

Is the destination of a commercial flight important for the pilot?

What's the purpose of "true" in bash "if sudo true; then"

Bash method for viewing beginning and end of file

Efficiently merge handle parallel feature branches in SFDX

What is the opposite of 'gravitas'?

What's a natural way to say that someone works somewhere (for a job)?

Failed to fetch jessie backports repository

Will it be accepted, if there is no ''Main Character" stereotype?



Adminhtml how to get current scope in ajax controller


How to add date filed in admin & show on front in magento2Magento 2 :Display attribute option valuesMagento 2 get Current page Browser url in phtml?How to use Context object to get config valuesGet system config option inside source model of another optionGet Config Path value based on website scopeMagento 2 : Error on running magento commandMagento 2 | Add Admin Configuration Button ActionHow to get config field value for all available store views as an array?Magento2.2 How to get userContext into ScopeConfig













0















I need following if in admin i click on button i need to write some system values based on the current scope.



/** @var MagentoConfigModelResourceModelConfig $resourceConfig */
$resourceConfig->saveConfig('path/to/field', $value, $scope, $scopeId);


so the question is how to get the scope?










share|improve this question


























    0















    I need following if in admin i click on button i need to write some system values based on the current scope.



    /** @var MagentoConfigModelResourceModelConfig $resourceConfig */
    $resourceConfig->saveConfig('path/to/field', $value, $scope, $scopeId);


    so the question is how to get the scope?










    share|improve this question
























      0












      0








      0








      I need following if in admin i click on button i need to write some system values based on the current scope.



      /** @var MagentoConfigModelResourceModelConfig $resourceConfig */
      $resourceConfig->saveConfig('path/to/field', $value, $scope, $scopeId);


      so the question is how to get the scope?










      share|improve this question














      I need following if in admin i click on button i need to write some system values based on the current scope.



      /** @var MagentoConfigModelResourceModelConfig $resourceConfig */
      $resourceConfig->saveConfig('path/to/field', $value, $scope, $scopeId);


      so the question is how to get the scope?







      magento2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Naberd ZendiNaberd Zendi

      312




      312




















          1 Answer
          1






          active

          oldest

          votes


















          0














          fixed issue by adding some parameters in to javascript call, basicaly we check if in admin url we have either store or website parameter and passing it to the script.



          var a = window.location.pathname.split('/');
          if(a.indexOf('website') !== -1)
          a.splice(0, a.indexOf('website'));
          params =
          'website': a[1]
          ;
          else
          if(a.indexOf('store') !== -1)
          a.splice(0, a.indexOf('store'));
          params =
          'store': a[1]
          ;
          else
          params =
          ;


          new Ajax.Request('<?php echo $block->getAjaxUrl() ?>',
          loaderArea: false,
          asynchronous: true,
          parameters: params,
          onSuccess: function(transport)
          var response = JSON.parse(transport.responseText);

          );


          also rewrited part of the save function, it seem the first method didn't save the config value directly but only after you click save manually.



          MagentoFrameworkAppRequestInterface $request,
          MagentoConfigModelConfigFactory $configFactory
          ...
          $this->_configFactory = $configFactory;
          $this->_request = $request;
          ...
          $configData = [
          'section' => 'path',
          'website' => ($this->_request->getParam('website', 0) ? $this->_request->getParam('website', 0):null),
          'store' => ($this->_request->getParam('store', 0) ? $this->_request->getParam('store', 0) : null),
          'groups' => [
          'to' => [
          'fields' => [
          'field' => [
          'value' => $value,
          ],
          ],
          ],
          ],
          ];
          /** @var MagentoConfigModelConfig $configModel */
          $configModel = $this->_configFactory->create(['data' => $configData]);
          $configModel->save();


          now this saves value based on website / store view






          share|improve this answer






















            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
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267273%2fadminhtml-how-to-get-current-scope-in-ajax-controller%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            fixed issue by adding some parameters in to javascript call, basicaly we check if in admin url we have either store or website parameter and passing it to the script.



            var a = window.location.pathname.split('/');
            if(a.indexOf('website') !== -1)
            a.splice(0, a.indexOf('website'));
            params =
            'website': a[1]
            ;
            else
            if(a.indexOf('store') !== -1)
            a.splice(0, a.indexOf('store'));
            params =
            'store': a[1]
            ;
            else
            params =
            ;


            new Ajax.Request('<?php echo $block->getAjaxUrl() ?>',
            loaderArea: false,
            asynchronous: true,
            parameters: params,
            onSuccess: function(transport)
            var response = JSON.parse(transport.responseText);

            );


            also rewrited part of the save function, it seem the first method didn't save the config value directly but only after you click save manually.



            MagentoFrameworkAppRequestInterface $request,
            MagentoConfigModelConfigFactory $configFactory
            ...
            $this->_configFactory = $configFactory;
            $this->_request = $request;
            ...
            $configData = [
            'section' => 'path',
            'website' => ($this->_request->getParam('website', 0) ? $this->_request->getParam('website', 0):null),
            'store' => ($this->_request->getParam('store', 0) ? $this->_request->getParam('store', 0) : null),
            'groups' => [
            'to' => [
            'fields' => [
            'field' => [
            'value' => $value,
            ],
            ],
            ],
            ],
            ];
            /** @var MagentoConfigModelConfig $configModel */
            $configModel = $this->_configFactory->create(['data' => $configData]);
            $configModel->save();


            now this saves value based on website / store view






            share|improve this answer



























              0














              fixed issue by adding some parameters in to javascript call, basicaly we check if in admin url we have either store or website parameter and passing it to the script.



              var a = window.location.pathname.split('/');
              if(a.indexOf('website') !== -1)
              a.splice(0, a.indexOf('website'));
              params =
              'website': a[1]
              ;
              else
              if(a.indexOf('store') !== -1)
              a.splice(0, a.indexOf('store'));
              params =
              'store': a[1]
              ;
              else
              params =
              ;


              new Ajax.Request('<?php echo $block->getAjaxUrl() ?>',
              loaderArea: false,
              asynchronous: true,
              parameters: params,
              onSuccess: function(transport)
              var response = JSON.parse(transport.responseText);

              );


              also rewrited part of the save function, it seem the first method didn't save the config value directly but only after you click save manually.



              MagentoFrameworkAppRequestInterface $request,
              MagentoConfigModelConfigFactory $configFactory
              ...
              $this->_configFactory = $configFactory;
              $this->_request = $request;
              ...
              $configData = [
              'section' => 'path',
              'website' => ($this->_request->getParam('website', 0) ? $this->_request->getParam('website', 0):null),
              'store' => ($this->_request->getParam('store', 0) ? $this->_request->getParam('store', 0) : null),
              'groups' => [
              'to' => [
              'fields' => [
              'field' => [
              'value' => $value,
              ],
              ],
              ],
              ],
              ];
              /** @var MagentoConfigModelConfig $configModel */
              $configModel = $this->_configFactory->create(['data' => $configData]);
              $configModel->save();


              now this saves value based on website / store view






              share|improve this answer

























                0












                0








                0







                fixed issue by adding some parameters in to javascript call, basicaly we check if in admin url we have either store or website parameter and passing it to the script.



                var a = window.location.pathname.split('/');
                if(a.indexOf('website') !== -1)
                a.splice(0, a.indexOf('website'));
                params =
                'website': a[1]
                ;
                else
                if(a.indexOf('store') !== -1)
                a.splice(0, a.indexOf('store'));
                params =
                'store': a[1]
                ;
                else
                params =
                ;


                new Ajax.Request('<?php echo $block->getAjaxUrl() ?>',
                loaderArea: false,
                asynchronous: true,
                parameters: params,
                onSuccess: function(transport)
                var response = JSON.parse(transport.responseText);

                );


                also rewrited part of the save function, it seem the first method didn't save the config value directly but only after you click save manually.



                MagentoFrameworkAppRequestInterface $request,
                MagentoConfigModelConfigFactory $configFactory
                ...
                $this->_configFactory = $configFactory;
                $this->_request = $request;
                ...
                $configData = [
                'section' => 'path',
                'website' => ($this->_request->getParam('website', 0) ? $this->_request->getParam('website', 0):null),
                'store' => ($this->_request->getParam('store', 0) ? $this->_request->getParam('store', 0) : null),
                'groups' => [
                'to' => [
                'fields' => [
                'field' => [
                'value' => $value,
                ],
                ],
                ],
                ],
                ];
                /** @var MagentoConfigModelConfig $configModel */
                $configModel = $this->_configFactory->create(['data' => $configData]);
                $configModel->save();


                now this saves value based on website / store view






                share|improve this answer













                fixed issue by adding some parameters in to javascript call, basicaly we check if in admin url we have either store or website parameter and passing it to the script.



                var a = window.location.pathname.split('/');
                if(a.indexOf('website') !== -1)
                a.splice(0, a.indexOf('website'));
                params =
                'website': a[1]
                ;
                else
                if(a.indexOf('store') !== -1)
                a.splice(0, a.indexOf('store'));
                params =
                'store': a[1]
                ;
                else
                params =
                ;


                new Ajax.Request('<?php echo $block->getAjaxUrl() ?>',
                loaderArea: false,
                asynchronous: true,
                parameters: params,
                onSuccess: function(transport)
                var response = JSON.parse(transport.responseText);

                );


                also rewrited part of the save function, it seem the first method didn't save the config value directly but only after you click save manually.



                MagentoFrameworkAppRequestInterface $request,
                MagentoConfigModelConfigFactory $configFactory
                ...
                $this->_configFactory = $configFactory;
                $this->_request = $request;
                ...
                $configData = [
                'section' => 'path',
                'website' => ($this->_request->getParam('website', 0) ? $this->_request->getParam('website', 0):null),
                'store' => ($this->_request->getParam('store', 0) ? $this->_request->getParam('store', 0) : null),
                'groups' => [
                'to' => [
                'fields' => [
                'field' => [
                'value' => $value,
                ],
                ],
                ],
                ],
                ];
                /** @var MagentoConfigModelConfig $configModel */
                $configModel = $this->_configFactory->create(['data' => $configData]);
                $configModel->save();


                now this saves value based on website / store view







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 17 hours ago









                Naberd ZendiNaberd Zendi

                312




                312



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267273%2fadminhtml-how-to-get-current-scope-in-ajax-controller%23new-answer', 'question_page');

                    );

                    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







                    Popular posts from this blog

                    Sum ergo cogito? 1 nng

                    三茅街道4182Guuntc Dn precexpngmageondP