Skip to content

Instantly share code, notes, and snippets.

@leobossmann
Created July 23, 2013 20:36
Show Gist options
  • Save leobossmann/6065938 to your computer and use it in GitHub Desktop.
Save leobossmann/6065938 to your computer and use it in GitHub Desktop.
Bulk create/delete shipping rates in the Shopify backend. Go to Settings/Shipping and paste it into Javascript console. WARNING: This is a proof of concept, use with extreme caution and only if you know what you're doing, you will have to customize this to fit your needs. Again, just a proof of concept, worked for me, might not work for you. Ong…
function make_shipping_rates(id, low, mid, high) {
$.post('/admin/price_based_shipping_rates.json', {
price_based_shipping_rate: {
country_id: id,
min_order_subtotal: "0",
max_order_subtotal: "500",
name: "DHL Premiumversand",
offsets: [],
price: low
}
});
$.post('/admin/price_based_shipping_rates.json', {
price_based_shipping_rate: {
country_id: id,
min_order_subtotal: "500",
max_order_subtotal: "2500",
name: "DHL Premiumversand",
offsets: [],
price: mid
}
});
$.post('/admin/price_based_shipping_rates.json', {
price_based_shipping_rate: {
country_id: id,
min_order_subtotal: "2500",
max_order_subtotal: "25000",
name: "DHL Premiumversand",
offsets: [],
price: high
}
});
}
function remove_weight_based_shipping_rates(country) {
$.each(country.weight_based_shipping_rates, function(j,item) {
$.ajax({
url: '/admin/weight_based_shipping_rates/' + item.id + '.json',
type: 'DELETE',
success: function(){
console.log(item.name + ' deleted!');
}
});
});
}
function remove_price_based_shipping_rates(country) {
$.each(country.price_based_shipping_rates, function(j,item) {
$.ajax({
url: '/admin/price_based_shipping_rates/' + item.id + '.json',
type: 'DELETE',
success: function(){
console.log(item.name + ' deleted!');
}
});
});
}
$.get('/admin/countries.json', function(countries){
$.each(countries.countries, function(i, country) {
// remove_weight_based_shipping_rates(country);
// remove_price_based_shipping_rates(country);
var north_america = ['US', 'CA', 'MX'];
if( $.inArray(country.code, north_america) != -1 ) {
make_shipping_rates(country.id, 40, 50, 90);
} else if (country.code == 'DE') {
make_shipping_rates(country.id, 7, 10, 20);
} else if (country.code == '*') {
make_shipping_rates(country.id, 40, 50, 90);
} else {
make_shipping_rates(country.id, 15, 25, 65);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment