This documentation is for developers only. If you're not a developer, please send this information to your developer, as they can follow the documentation.
We always recommend using our "Market Selector" app embeds. This article is only for synchronizing your native theme country selector.
If you have more than one store synced with Orbe, please don't follow this article. Your selector should be the one created by the Orbe app. If you need any customization for this selector, please get in touch with our Support team via app chat or email at support@orbe.app. We are always happy to help with specific customizations for the Orbe Plus plan in the Market selector.
In our app Orbe, we have an app embed called "Market Selector" that allows any Shopify merchant to add and customize a country and language selector in the footer of any Shopify Theme. These selectors use the Orbe technology.
However, some merchants would like to use their native Shopify theme country and language selector with Orbe because they want its style and UX in their theme. They can work with a developer to synchronize this theme selector with Orbe for that case.
Step-by-Step Guide
Step 1: Get the domain of the store in a JS variable. You can do that with orbito.getCountryDomain
let shopDomain =orbito.getCountryDomain();
Step 2: Find the function that runs before submitting the localization form. This method is called when a user clicks on one of the country names in the selector and sets the value of the input element to the value of the country code where they want to buy.
Here you can see the complete JavaScript code synchronized with Orbe based on the example provided in the official Shopify documentation:
// function to get the domain of the current shopfunctiongetShopDomain() {let shopDomain =document.domain;return shopDomain;}// custom element for the localization formclassLocalizationFormextendsHTMLElement {constructor() {super();// initialize the elements for the formthis.elements = { input:this.querySelector('input[name="language_code"], input[name="country_code"]'), button:this.querySelector('button'), panel:this.querySelector('ul'), };// add event listeners for opening and closing the selectorthis.elements.button.addEventListener('click',this.openSelector.bind(this));this.elements.button.addEventListener('focusout',this.closeSelector.bind(this));this.addEventListener('keyup',this.onContainerKeyUp.bind(this));// add event listeners for selecting a countrythis.querySelectorAll('a').forEach(item =>item.addEventListener('click',this.onItemClick.bind(this))); }// function to hide the country selector panelhidePanel() {this.elements.button.setAttribute('aria-expanded','false');this.elements.panel.setAttribute('hidden',true); }// function to handle keyup events on the form containeronContainerKeyUp(event) {if (event.code.toUpperCase() !=='ESCAPE') return;this.hidePanel();this.elements.button.focus(); }// function to handle clicking on a countryonItemClick(event) {event.preventDefault();constform=this.querySelector('form');constreturnToInput=form.querySelector("input[name='return_to']");let countryCode =event.currentTarget.dataset.value;let urlCountryRedirect ='';if (returnToInput.value.includes('?')) { urlCountryRedirect ='&mdApp_countryCodeDomain='+ countryCode; } else { urlCountryRedirect ='?mdApp_countryCodeDomain='+ countryCode; }returnToInput.value =returnToInput.value + urlCountryRedirect; document.cookie = `mdApp_countryCodeDomain=${countryCode}; domain=${getShopDomain()}; path=/; max-age=${60 * 60 * 24 * 60};`;
this.elements.input.value = countryCode;if (form) form.submit(); }// function to open the country selector panelopenSelector() {this.elements.button.focus();this.elements.panel.toggleAttribute('hidden'); this.elements.button.setAttribute('aria-expanded', (this.elements.button.getAttribute('aria-expanded') === 'false').toString());
}// function to close the country selector panelcloseSelector(event) {constshouldClose=event.relatedTarget &&event.relatedTarget.nodeName ==='BUTTON';if (event.relatedTarget ===null|| shouldClose) {this.hidePanel(); } }}// define the custom elementcustomElements.define('localization-form', LocalizationForm);