0

I'm trying to use an extension to manage our hreflang tags, but when it generates the tags, it adds the default store code to the URL. As the default store code was removed from the URL, it creates an error (the french version is pointing to an inexistent page, with the store code).

Is there a way to correct this problem, without modifying the extension itself?

I need to remove the "ca_en" part

Thank you.

1 Answer 1

0

Try it like this and see if it works its not tested yet please give it a try etc/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">
    <type name="Magento\Store\Model\Store">
        <plugin name="vendor_hide_default_store_code" type="\Vendor\HideDefaultStoreCode\Plugin\Model\HideDefaultStoreCode" sortOrder="0" />
    </type>
</config>

HideDefaultStoreCode

<?php

namespace Vendor\HideDefaultStoreCode\Plugin\Model;

class HideDefaultStoreCode
{
    /**
     *
     * @var \Vendor\HideDefaultStoreCode\Helper\Data 
     */
    protected $helper;

    /**
     *
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $storeManager;

    /**
     * 
     * @param \Vendor\HideDefaultStoreCode\Helper\Data $helper
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     */
    public function __construct(
        \Vendor\HideDefaultStoreCode\Helper\Data $helper,
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ){
        $this->helper = $helper;
        $this->storeManager = $storeManager;
    }

    /**
     * 
     * @param \Magento\Store\Model\Store $subject
     * @param string $url
     * @return string
     */
    public function afterGetBaseUrl(\Magento\Store\Model\Store $subject, $url)
    {
        
            $url = str_replace('/'.$this->storeManager->getDefaultStoreView()->getCode().'/','/', $url);
       
        return $url;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.