Created
August 31, 2016 14:15
-
-
Save lasergoat/7c801467aab7e7848507dccb85598241 to your computer and use it in GitHub Desktop.
Shopify's BOLD Product Options SCRIPT SETUP (hack)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the goal of this script is to save you time when using BOLD product options | |
// for your shopify store. it currently only works for drop down options. | |
// run it in your browser's console on the "create option" page in the bold app. | |
// fill out the values for these three variables: | |
// 1. internalName | |
// 2. publicName | |
// 3. options | |
// the names will be formatted like: "Internal Options" -> "internal-options" | |
// the options object expects: <option-name> : <extra price or null> | |
// this ONLY works for drop downs, but if you want a different type than drop down, | |
// change the value in option_data.new_option_type to whatever your value should be | |
// from Bold's option type drop down. | |
// to use, copy all the code and paste into your console on the new option page. | |
// ##IMPORTANT! | |
// also, the "create options" page uses an iFrame, so you need to use console's inspector | |
// to inspect something within the iFrame to change the run context to the iFrame | |
// before you run the code in your browser's console | |
var internalName = 'Internal Options'; | |
var publicName = 'options'; | |
var options = { | |
'Option 1' : null, | |
'Option 2' : 30, | |
'Option 3' : 60, | |
'Option 4' : 90, | |
'Super Option' : null, | |
}; | |
function titleCase(str) { | |
return str | |
.toLowerCase() | |
.split(' ') | |
.map(i => i[0].toUpperCase() + i.substring(1)) | |
.join(' '); | |
} | |
function labels() { | |
var tmp = []; | |
for(var o in options) { | |
var label = titleCase(o); | |
if (options[o]) { | |
label += ' +' + options[o]; | |
} | |
tmp.push(label); | |
} | |
return tmp; | |
} | |
function priceChanges() { | |
var tmp = []; | |
for(var o in options) { | |
tmp.push(""+(!!options[o]^0)); | |
} | |
return tmp; | |
} | |
function optionVariants() { | |
var tmp = []; | |
for(var o in options) { | |
tmp.push(""); | |
} | |
return tmp; | |
} | |
function optionPrices() { | |
var tmp = []; | |
for(var o in options) { | |
tmp.push(options[o] ? ""+options[o] : ""); | |
} | |
return tmp; | |
} | |
var option_data = { | |
new_internal_name: internalName.replace(' ', '-'), | |
new_public_name: titleCase(publicName), | |
new_option_type: "1", | |
option_name: "", | |
edit_option_name: labels(), | |
change_price: "1", | |
edit_val_change_price: priceChanges(), | |
filter_col: "", | |
edit_option_variant: optionVariants(), | |
edit_option_variant_visible: "", | |
edit_new_option_price: optionPrices(), | |
textarea_data: "", | |
val_change_price: "0", | |
check_option_name: "checked", | |
check_change_price: "0", | |
check_option_variant: "", | |
check_option_price: "" | |
}; | |
// @@@ look, the code isn't pretty but it works | |
// open the options drop down | |
$('select#new_option_type').val(1).change(); | |
$('#option_data').val(JSON.stringify(option_data)); | |
$('#JSON_form').submit(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment