0

I have a small problem and don't know how to implement redirect based on selected language (as a multiple store views there are few languages: en, lt,lv). The file located in app/design/frontend/MyProject/Project/Magento_Checkout/web/template/minicart/content.html and the code that need to be changed

<ifnot args="getCartParam('summary_count')">
    <div class="empty-bag-img"></div>
            <strong class=""
                    translate="'You have no items in your shopping cart.'"></strong>
            <div class="actions">
                <div class="secondary">
                    <a class="action viewcart" href="/">
                        <span translate="'Go to the store'"></span>
                    </a>
                </div>
            </div>
</ifnot>

For know it hardcoded and redirect to home without saving language. Could you help with several steps what I should do to make redirect like home.com/en or home.com/lv

0

4 Answers 4

1

I resolve this problem.simply add this code with baseUrl into minicart.js.

return Component.extend({
        shoppingCartUrl: window.checkout.shoppingCartUrl,
        baseUrl: window.checkout.baseUrl,

app/design/frontend/MyProject/Project/Magento_Checkout/web/template/minicart/content.html

 <div class="actions">
            <div class="secondary">
                <a class="action viewcart" data-bind="attr: { href: baseUrl }">
                    <span translate="'Go to the store'"></span>
                </a>
            </div>
  </div>
0

please try the below code.

<a class="action viewcart" data-bind="attr: { href: getBaseUrl() }">
  <span><!-- ko i18n: 'Home page' --><!-- /ko --></span>
</a>
0
0

Another way you can use it is to check the below code and try to implement it.

/var/www/html/project/app/code/Vendor/Module/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">
<type name="Magento\Checkout\Model\CompositeConfigProvider">
    <arguments>
        <argument name="configProviders" xsi:type="array">
            <item name="additional_provider_class" xsi:type="object">Vendor\Module\Model\AdditionalConfig</item>
        </argument>
    </arguments>
</type>

/var/www/html/walletmetamask/app/code/Vendor/Module/Model/AdditionalConfig.php

<?php
  namespace Vendor\Module\Model;

  use Magento\Checkout\Model\ConfigProviderInterface;
  use Magento\Checkout\Model\Session as CheckoutSession;
  use Magento\Checkout\Model\Cart as CustomerCart;



class AdditionalConfig implements ConfigProviderInterface
 {

protected $checkoutSession;

protected $cart;

protected $storeManager;


/**
 *
 * @param \Magento\Framework\View\Element\Template\Context $context
 * @param \Web30india\Faq\Helper\Data $helper
 * @param array $data
 */
public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    CustomerCart $cart,
    CheckoutSession $checkoutSession
   
   
) {
    $this->checkoutSession = $checkoutSession;
    $this->storeManager = $storeManager;
    $this->cart = $cart;
}

public function getConfig()
{
    $validationConfig = [
         "baseUrl" => $this->getBaseUrl()
    ];

    return $validationConfig;
}

public function getBaseUrl(){
     return $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);
}

}

In the HTML file add the below code

/var/www/html/project/app/code/Vendor/Module/view/frontend/web/template/payment/web3wallet.html

<a data-bind="attr: {'href': checkoutConfig.baseUrl}" target="_blank">Link</a>

you can use more information.

checkout.baseUrl => {www.example.com}/

checkout.checkoutUrl => {www.example.com}/checkout/

checkout.customerLoginUrl => {www.example.com}/customer/account/login/

checkout.removeItemUrl => {www.example.com}/checkout/sidebar/removeItem/

checkout.shoppingCartUrl => {www.example.com}/checkout/cart/

checkout.updateItemQtyUrl => {www.example.com}/checkout/sidebar/updateItemQty/

checkoutConfig.cartUrl => {www.example.com}/checkout/cart/

checkoutConfig.checkoutUrl => {www.example.com}/checkout/

checkoutConfig.defaultSuccessPageUrl => {www.example.com}/checkout/onepage/success/

checkoutConfig.forgotPasswordUrl => {www.example.com}/customer/account/forgotpassword/

checkoutConfig.pageNotFoundUrl => {www.example.com}/checkout/noroute/

checkoutConfig.registerUrl => {www.example.com}/customer/account/create/

checkoutConfig.staticBaseUrl => {www.example.com}/pub/static/
0
<a class="action viewcart" href="/"> => <a class="action viewcart" href="#" id="goToStoreLink">

<script type="text/javascript">
require([
'jquery',
'mage/translate',
'mage/url'
], function ($, $t, urlBuilder) {
var currentLanguage = window.navigator.userLanguage || window.navigator.language;
var goToStoreLink = $('#goToStoreLink');
var languageCode = currentLanguage.substr(0, 2);
var storeUrlMap = {
'en': '/en/',
'de': '/de/',
'fr': '/fr/'
};
goToStoreLink.attr('href', urlBuilder.build(storeUrlMap[languageCode]));
});
</script>
</ifnot>

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.