0

I have created 2 store views in magento latest 2.2

I have enabled add store view to url in settings.

But on home page it throws error store id not found.

If I add en/ at the end of url or ar/ at end it works fine.

Even the language switcher is working fine.

Only issue with home page.

How can I set the default storeview for home page ?

0

I tried with updating the default switcher model found in /vendor/magento/module-store/Model/StoreManager.php. So I created a new module and in di.xml i wrote

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <preference for="Magento\Store\Model\StoreManager" type="Vendor\Custom\Model\StoreManager" />


</config>

and Then in my new Storemanager code I added the below code.

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Vendor\Custom\Model;

/**
 * Service contract, which manage scopes
 *
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class StoreManager extends \Magento\Store\Model\StoreManager
{
    /**
     * {@inheritdoc}
     */
    public function getStore($storeId = null)
    {
//        echo $storeId;
//        die('000');
        if (!isset($storeId) || '' === $storeId || $storeId === true) {
            if (null === $this->currentStoreId) {
                \Magento\Framework\Profiler::start('store.resolve');
                $this->currentStoreId = $this->storeResolver->getCurrentStoreId();
                \Magento\Framework\Profiler::stop('store.resolve');
            }
            $storeId = $this->currentStoreId;
        }
        if ($storeId instanceof \Magento\Store\Api\Data\StoreInterface) {
            return $storeId;
        }
        if (!$storeId) {
            if (isset($_COOKIE['store']) && $_COOKIE['store'] !== '') {
                $storeId = $_COOKIE['store'];
            } else {
                $storeId = $this->getDefaultStoreView()->getCode();
            }
        }
        $store = is_numeric($storeId)
            ? $this->storeRepository->getById($storeId)
            : $this->storeRepository->get($storeId);

        return $store;
    }
}

This is a bug already reported.

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.