Created
January 12, 2018 16:31
-
-
Save prinzdezibel/dfaccf50d3d33998713eecb8b4081063 to your computer and use it in GitHub Desktop.
This file contains 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
methods.importProductImages = function () { | |
Logger.info("Started loading product images"); | |
if (!checkForMedia()) { | |
const products = Products.find({ type: "simple" }).fetch(); | |
for (const product of products) { | |
const productId = product._id; | |
if (!Media.findOne({ "metadata.productId": productId })) { | |
const shopId = product.shopId; | |
const filepath = `plugins/reaction-swag-shop/images/${productId}.jpg`; | |
const binary = Assets.getBinary(filepath); | |
const fileObj = new FS.File(); | |
const fileName = `${productId}.jpg`; | |
fileObj.attachData(binary, { type: "image/jpeg", name: fileName }); | |
const topVariant = getTopVariant(productId); | |
fileObj.metadata = { | |
productId: productId, | |
variantId: topVariant._id, | |
toGrid: 1, | |
shopId: shopId, | |
priority: 0, | |
workflow: "published" | |
}; | |
Media.insert(fileObj); | |
} | |
} | |
Logger.info("loaded product images"); | |
} else { | |
Logger.info("Skipped loading product images"); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment