SwitchAction.php 813 B

12345678910111213141516171819202122232425
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Directory\Controller\Currency;
  8. class SwitchAction extends \Magento\Framework\App\Action\Action
  9. {
  10. /**
  11. * @return void
  12. */
  13. public function execute()
  14. {
  15. /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
  16. $storeManager = $this->_objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
  17. $currency = (string)$this->getRequest()->getParam('currency');
  18. if ($currency) {
  19. $storeManager->getStore()->setCurrentCurrencyCode($currency);
  20. }
  21. $storeUrl = $storeManager->getStore()->getBaseUrl();
  22. $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($storeUrl));
  23. }
  24. }