I am trying to achieve website switch for my site but i am getting error , i followed some code but getting error
here is my module structure
app/code/Rgswitch/switcher/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoStoreViewModelSwitcherUrlProvider" type="RgswitchswitcherViewModelStoreSwitchModel" />
</config>
/app/code/Rgswitch/switcher/ViewModel/StoreSwitchModel.php
<?php
namespace RgswitchswitcherViewModel;
use MagentoFrameworkAppConfigScopeConfigInterface;
use MagentoFrameworkLocaleTranslatedLists;
use MagentoFrameworkUrlEncoderInterface;
use MagentoFrameworkUrlInterface;
use MagentoStoreApiDataStoreInterface;
use MagentoStoreModelResourceModelWebsiteCollection as WebsiteCollection;
use MagentoStoreModelResourceModelWebsiteCollectionFactory as WebsiteCollectionFactory;
use MagentoStoreModelScopeInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoStoreViewModelSwitcherUrlProvider;
class StoreSwitchModel extends SwitcherUrlProvider
{
const LOCALE_CONFIG_PATH = 'general/locale/code';
const DEFAULT_COUNTRY_CONFIG_PATH = 'general/country/default';
private $websiteCollectionFactory;
private $scopeConfig;
private $translatedLists;
private $storeManager;
public function __construct(
EncoderInterface $encoder,
StoreManagerInterface $storeManager,
UrlInterface $urlBuilder,
WebsiteCollectionFactory $websiteCollectionFactory,
ScopeConfigInterface $scopeConfig,
TranslatedLists $translatedLists
) {
parent::__construct($encoder, $storeManager, $urlBuilder);
$this->websiteCollectionFactory = $websiteCollectionFactory;
$this->scopeConfig = $scopeConfig;
$this->translatedLists = $translatedLists;
$this->storeManager = $storeManager;
}
public function getWebsite()
{
return $this->storeManager->getWebsite();
}
public function getWebsites(): WebsiteCollection
{
return $this->websiteCollectionFactory->create();
}
public function getStoreLocale(StoreInterface $store): string
{
$locale = $this->scopeConfig->getValue(self::LOCALE_CONFIG_PATH, ScopeInterface::SCOPE_STORE, $store->getId());
return $locale;
}
public function getStoreCountryCode(StoreInterface $store): string
{
return $this->scopeConfig->getValue(
self::DEFAULT_COUNTRY_CONFIG_PATH,
ScopeInterface::SCOPE_STORE,
$store->getId()
);
}
}
here is the language switcher
app/design/frontend/vendor/theme/Magento_Store/templates/switch/languages.phtml
<?php
/** @var MagentoStoreBlockSwitcher $block */
$viewModel = $block->getData('view_model');
$websites = $viewModel->getWebsites();
$websiteid = $viewModel->getWebsite()->getWebsiteId();
?>
<div class="switcher store switcher-store" id="switcher-store">
<strong class="label switcher-label"><span><?php echo __('Select Store') ?></span></strong>
<div class="actions dropdown options switcher-options">
<?php foreach ($websites as $website): ?>
<?php if ($websiteid == $website->getId()): ?>
<div class="action toggle switcher-trigger"
role="button"
tabindex="0"
data-mage-init='{"dropdown":{}}'
data-toggle="dropdown"
data-trigger-keypress-button="true"
id="switcher-store-trigger">
<strong>
<span><?php echo $block->escapeHtml($website->getName()) ?></span>
</strong>
</div>
<?php endif; ?>
<?php endforeach; ?>
<ul class="dropdown switcher-dropdown" data-target="dropdown">
<?php foreach ($websites as $website): ?>
<?php if (!($websiteid == $website->getId())): ?>
<li class="switcher-option view">
<a href='<?php echo $viewModel->getTargetStoreRedirectUrl($website->getDefaultStore()) ?>'>
<?php echo $block->escapeHtml($website->getName()) ?>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
</div>
I am getting error as main.CRITICAL: Error: Call to undefined method MagentoStoreViewModelSwitcherUrlProvider::getWebsites() in /Magento_Store/templates/switch/languages.phtml:4
what am i missing