Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CartJS & Shopify multiple languages store ? #198

Open
msev opened this issue Feb 15, 2021 · 1 comment
Open

CartJS & Shopify multiple languages store ? #198

msev opened this issue Feb 15, 2021 · 1 comment

Comments

@msev
Copy link

msev commented Feb 15, 2021

Hi,

With the native translation API from Shopify, we can now have this kind of URL : site.com and site.com/fr or site.com/de

But the response from CartJS is always using this structure :

  • site.com/cart.js,
  • site.com/cart/add.js
  • site.com/cart/change.js
  • site.com/cart/update.js
  • site.com/cart/clear.js

It would be great to add the current language in the structure : site.com/fr/cart.js (or site.com/de/cart.js)

Currently, when we are using CartJS.addItem, whichever language is being used in the front-office, the response from CartJS is awlays to /cart.js instead of /fr/cart.js (as an example)

Thanks in advance.

@nemoeric
Copy link

Hey @msev

Just realized this was also affecting some of our stores.
We use CartJS with Rivets.
And whenever a line item is updated, the front actually shows a cart in the root locale !

Here is my fix, works like a charm.

  1. Declare routes in theme.liquid in a script markup
window.kercambreRoutes = {
      root_url : "{{ routes.root_url }}",
      add_url: "{{ routes.cart_add_url }}",
      cart_change_url : "{{ routes.cart_change_url }}",
      cart_clear_url: "{{ routes.cart_clear_url }}",
      cart_update_url: "{{ routes.cart_update_url }}"
    }
  1. In Cart.min.js, find the functions declarations and simply use the variable above to ping the correct url.
    For instance :
getCart: function (a) {
    console.log("get CART");
    return null == a && (a = {}), (a.type = "GET"), (a.updateCart = !0), c.Queue.add( "/cart.js", { v: new Date().getTime() }, a);
            },

and change it to :

getCart: function (a) {
      console.log("get CART");
      return null == a && (a = {}), (a.type = "GET"), (a.updateCart = !0), c.Queue.add( window.kercambreRoutes.cart_url + ".js", { v: new Date().getTime() }, a);
            },

That worked for me :)
The best of course should be to start the CartJS.init() function with the sufficient variables. Might try to do a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants