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

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form