Magento 2.3.1 Change store view in controller_action_predispatch eventsales_order_save_commit_after event triggered twice?Magento2: Re-direct to custom URL from observerSet custom price of product when adding to cart code not workingMagento 1.9 - Order object passed to event observer is emptyRedirect to correct store view by customer browser languageCustomer save after event magento2controller_action_predispatch is not observing after logoutMagento 2 controller_action_predispatch observer not working as expectedCreate event and observer for customer sign up (Magento 2)Sign up (guest checkout) issue in Magento 2

Do Goblin tokens count as Goblins?

Why is there paternal, for fatherly, fraternal, for brotherly, but no similar word for sons?

How to find the version of extensions used on a Joomla website without access to the backend?

How to say "just a precision" properly in English?

When is one 'Ready' to make Original Contributions to Mathematics?

Why do people prefer metropolitan areas, considering monsters and villains?

White's last move?

Does the Milky Way orbit around anything?

What's the big deal about the Nazgûl losing their horses?

What is the highest level of accuracy in motion control a Victorian society could achieve?

What is the meaning of "prairie-dog" in this sentence?

Is there a minimum amount of electricity that can be fed back into the grid?

Howto display unicode character u2026 in terminal mode in emacs

Better random (unique) file name

Examples of fluid (including air) being used to transmit digital data?

Did Stalin kill all Soviet officers involved in the Winter War?

How to deal with a Murder Hobo Paladin?

Do grungs have a written language?

Was the 45.9°C temperature in France in June 2019 the highest ever recorded in France?

Why do we need a bootloader separate from our application program in microcontrollers?

What's the difference between a type and a kind?

How to get the speed of my spaceship?

How do I explain how I handle unrealistic expectations from superiors in an interview?

PhD: When to quit and move on?



Magento 2.3.1 Change store view in controller_action_predispatch event


sales_order_save_commit_after event triggered twice?Magento2: Re-direct to custom URL from observerSet custom price of product when adding to cart code not workingMagento 1.9 - Order object passed to event observer is emptyRedirect to correct store view by customer browser languageCustomer save after event magento2controller_action_predispatch is not observing after logoutMagento 2 controller_action_predispatch observer not working as expectedCreate event and observer for customer sign up (Magento 2)Sign up (guest checkout) issue in Magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















In my extension, the default storeview is English and I want to set Arabic storeview, only one time when the customer comes first time on my website. I'm using controller_action_predispatch event to check customer comes the first time or not, if not, customer can move to English storeview as well. Following is my piece of code:




NamespaceModulenameetcfrontendevents.xml




<event name="controller_action_predispatch">
<observer name="switch_store" instance="NamespaceModulenameObserverSwitchStore" shared="false" />
</event>



NamespaceModulenameObserverSwitchStore.php




protected $storeManager;

public function __construct(
MagentoStoreModelStoreManagerInterface $storeManager
)
$this->storeManager = $storeManager;


public function execute(MagentoFrameworkEventObserver $observer)
if ($this->firstVisit()) // Customer's first visit logic inside firstVisit() function
$storeId = $this->storeManager->getStore($target_store)->getId();
$this->storeManager->setCurrentStore($storeId);

return $this;



This code is working fine for the first time, but when the user tries to switch English storeview, he/she would be redirected to the same storeview, that is Arabic. I debugged so many times, but in logs, I'm getting perfect output and not reflecting the change on the frontend. I think this is a cache issue, but not sure. Please let me know if anyone has a solution for this.



Thanks in anticipate.










share|improve this question






























    1















    In my extension, the default storeview is English and I want to set Arabic storeview, only one time when the customer comes first time on my website. I'm using controller_action_predispatch event to check customer comes the first time or not, if not, customer can move to English storeview as well. Following is my piece of code:




    NamespaceModulenameetcfrontendevents.xml




    <event name="controller_action_predispatch">
    <observer name="switch_store" instance="NamespaceModulenameObserverSwitchStore" shared="false" />
    </event>



    NamespaceModulenameObserverSwitchStore.php




    protected $storeManager;

    public function __construct(
    MagentoStoreModelStoreManagerInterface $storeManager
    )
    $this->storeManager = $storeManager;


    public function execute(MagentoFrameworkEventObserver $observer)
    if ($this->firstVisit()) // Customer's first visit logic inside firstVisit() function
    $storeId = $this->storeManager->getStore($target_store)->getId();
    $this->storeManager->setCurrentStore($storeId);

    return $this;



    This code is working fine for the first time, but when the user tries to switch English storeview, he/she would be redirected to the same storeview, that is Arabic. I debugged so many times, but in logs, I'm getting perfect output and not reflecting the change on the frontend. I think this is a cache issue, but not sure. Please let me know if anyone has a solution for this.



    Thanks in anticipate.










    share|improve this question


























      1












      1








      1








      In my extension, the default storeview is English and I want to set Arabic storeview, only one time when the customer comes first time on my website. I'm using controller_action_predispatch event to check customer comes the first time or not, if not, customer can move to English storeview as well. Following is my piece of code:




      NamespaceModulenameetcfrontendevents.xml




      <event name="controller_action_predispatch">
      <observer name="switch_store" instance="NamespaceModulenameObserverSwitchStore" shared="false" />
      </event>



      NamespaceModulenameObserverSwitchStore.php




      protected $storeManager;

      public function __construct(
      MagentoStoreModelStoreManagerInterface $storeManager
      )
      $this->storeManager = $storeManager;


      public function execute(MagentoFrameworkEventObserver $observer)
      if ($this->firstVisit()) // Customer's first visit logic inside firstVisit() function
      $storeId = $this->storeManager->getStore($target_store)->getId();
      $this->storeManager->setCurrentStore($storeId);

      return $this;



      This code is working fine for the first time, but when the user tries to switch English storeview, he/she would be redirected to the same storeview, that is Arabic. I debugged so many times, but in logs, I'm getting perfect output and not reflecting the change on the frontend. I think this is a cache issue, but not sure. Please let me know if anyone has a solution for this.



      Thanks in anticipate.










      share|improve this question
















      In my extension, the default storeview is English and I want to set Arabic storeview, only one time when the customer comes first time on my website. I'm using controller_action_predispatch event to check customer comes the first time or not, if not, customer can move to English storeview as well. Following is my piece of code:




      NamespaceModulenameetcfrontendevents.xml




      <event name="controller_action_predispatch">
      <observer name="switch_store" instance="NamespaceModulenameObserverSwitchStore" shared="false" />
      </event>



      NamespaceModulenameObserverSwitchStore.php




      protected $storeManager;

      public function __construct(
      MagentoStoreModelStoreManagerInterface $storeManager
      )
      $this->storeManager = $storeManager;


      public function execute(MagentoFrameworkEventObserver $observer)
      if ($this->firstVisit()) // Customer's first visit logic inside firstVisit() function
      $storeId = $this->storeManager->getStore($target_store)->getId();
      $this->storeManager->setCurrentStore($storeId);

      return $this;



      This code is working fine for the first time, but when the user tries to switch English storeview, he/she would be redirected to the same storeview, that is Arabic. I debugged so many times, but in logs, I'm getting perfect output and not reflecting the change on the frontend. I think this is a cache issue, but not sure. Please let me know if anyone has a solution for this.



      Thanks in anticipate.







      event-observer cache store-view magento2.3.1 store-switcher






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 28 at 3:59









      poojan sharma

      8091 silver badge10 bronze badges




      8091 silver badge10 bronze badges










      asked Jun 27 at 13:13









      Dhara BhattiDhara Bhatti

      4731 silver badge12 bronze badges




      4731 silver badge12 bronze badges




















          0






          active

          oldest

          votes














          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%2f279931%2fmagento-2-3-1-change-store-view-in-controller-action-predispatch-event%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f279931%2fmagento-2-3-1-change-store-view-in-controller-action-predispatch-event%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

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?