Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tobymarsden/d0a74c0d4d97c2fe9e01ce05a5565522 to your computer and use it in GitHub Desktop.
Save tobymarsden/d0a74c0d4d97c2fe9e01ce05a5565522 to your computer and use it in GitHub Desktop.
// first copy the uploaders and insert them into the table without their existing id, and with the new shop_id
oldshopify = new Shopify({
shopName: oldshop.get('myshopify_name'),
accessToken: oldshop.get('shopify_token'),
autoLimit: true
})
shopify = new Shopify({
shopName: newshop.get('myshopify_name'),
accessToken: newshop.get('shopify_token'),
autoLimit: true
})
uploader.where({shop_id: newshop.get('id')}).fetchAll().then(res => uploaders=res)
function setId(productObject) {
console.log('finding', productObject.object_id)
if(productObject.id == "4771523264561") { console.log('***** 4771523264561')}
oldshopify.product.get(productObject.object_id).then(product => {
shopify.product.list({title: product.title}).then(function(res) {
if(res[0]) {
console.log('setting ', productObject.title, ' to ', res[0].id)
productObject.object_id = '' + res[0].id
}
console.log('*')
}).catch(e => console.log('ERROR:', e))
}).catch(() => console.log('no'))
}
for(var uploader of uploaders.toArray()) {
for(var condition of uploader.get('conditions')) {
for(var productObject of condition.products) {
setId(productObject)
}
}
}
//...
for(var uploader of uploaders.toArray()) { uploader.save() }
//...
newshop.syncConfigToShopify()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment