0

Did you ever face 404 Error when the customer is logged in and switching the store switch with having folder structure is Base Url?

Something like, Base Url is http://examplemagento.com/b2c/

I have noted that while switching the store it redirects to this controller Magento\Store\Controller\Store\SwitchRequest.php

enter image description here

0

I just noted that, Magento\Store\Model\StoreSwitcher\HashGenerator.php model file is using $urlParts = parse_url($targetUrl); parse_url to get the base_url which will remove the folder from the actual base_url.

I just overrided Magento\Store\Model\StoreSwitcher\HashGenerator.php file and updated $urlParts = parse_url($targetUrl); line number 75.

  1. Created preference in the di.xml file.

<preference for="Magento\Store\Model\StoreSwitcher\HashGenerator" type="Custom\Module\Model\Rewrite\StoreSwitcher\HashGenerator" />

  1. Model overrided file as below.

    • Override Magento\Store\Model\StoreSwitcher\HashGenerator and just lines from line number 75 to 85 as below.

$urlParts = parse_url($targetUrl); //$host = $urlParts['host']; //$scheme = $urlParts['scheme']; $host = $targetStore->getBaseUrl(); $key = (string)$this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY); $timeStamp = time(); $fromStoreCode = $fromStore->getCode(); $data = implode(',', [$customerId, $timeStamp, $fromStoreCode]); $signature = hash_hmac('sha256', $data, $key); //$targetUrl = $scheme . "://" . $host . '/stores/store/switchrequest'; $targetUrl = $host . 'stores/store/switchrequest';

Hopefully, it will do it the required changes.

| improve this answer | |

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.