I want custom to choose store view = option select, when clicking to store, it will redirect to store. But I can't do it, I tried to like this but it not working, please help me

<?php $blockObj= $block->getLayout()->createBlock('Magento\Store\Block\Switcher'); ?>
<?php if (count($blockObj->getStores())>1): ?>
    <?php $id = $blockObj->getIdModifier() ? '-' . $blockObj->getIdModifier() : ''?>
    <select style="width:66px;" id="switcher-language-s">
        <option selected>Store</option>
        <?php foreach ($blockObj->getStores() as $_lang): ?>
            <option data-post='<?php /* @escapeNotVerified */ echo $blockObj->getTargetStorePostData($_lang); ?>'><?php echo $blockObj->escapeHtml($_lang->getCode()) ?></option>
        <?php endforeach; ?>
<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.