Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Shopify routing to work with Markets (CLA signed) #174

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/theme-cart/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ function fetchJSON(url, config) {
});
}

function getRoute() {
if(window.Shopify.routes.root) {
return window.Shopify.routes.root;
}
return '/';
}

export function cart() {
return fetchJSON('/cart.js', getDefaultRequestConfig());
return fetchJSON(getRoute() + 'cart.js', getDefaultRequestConfig());
}

export function cartAdd(id, quantity, properties) {
Expand All @@ -33,7 +40,7 @@ export function cartAdd(id, quantity, properties) {
properties: properties
});

return fetchJSON('/cart/add.js', config);
return fetchJSON(getRoute() + 'cart/add.js', config);
}

export function cartAddFromForm(formData) {
Expand All @@ -43,7 +50,7 @@ export function cartAddFromForm(formData) {
config.method = 'POST';
config.body = formData;

return fetchJSON('/cart/add.js', config);
return fetchJSON(getRoute() + 'cart/add.js', config);
}

export function cartChange(line, options) {
Expand All @@ -58,14 +65,14 @@ export function cartChange(line, options) {
properties: options.properties
});

return fetchJSON('/cart/change.js', config);
return fetchJSON(getRoute() + 'cart/change.js', config);
}

export function cartClear() {
var config = getDefaultRequestConfig();
config.method = 'POST';

return fetchJSON('/cart/clear.js', config);
return fetchJSON(getRoute() + 'cart/clear.js', config);
}

export function cartUpdate(body) {
Expand All @@ -74,9 +81,9 @@ export function cartUpdate(body) {
config.method = 'POST';
config.body = JSON.stringify(body);

return fetchJSON('/cart/update.js', config);
return fetchJSON(getRoute() + 'cart/update.js', config);
}

export function cartShippingRates() {
return fetchJSON('/cart/shipping_rates.json', getDefaultRequestConfig());
return fetchJSON(getRoute() + 'cart/shipping_rates.json', getDefaultRequestConfig());
}