Skip to content

Instantly share code, notes, and snippets.

@JumboLove
Created June 7, 2013 14:04
Show Gist options
  • Select an option

  • Save JumboLove/5729480 to your computer and use it in GitHub Desktop.

Select an option

Save JumboLove/5729480 to your computer and use it in GitHub Desktop.
Boilerplate Product Feed
/**
* Demandware Script File
* Export only the Product IDs to Netrada FTP to match the ProductFeed Export sent to Bazaarvoice
* Exports Product IDs to a text file with pipe delimiters.
* Created by David Witt 05 June 2013
*
*/
importPackage( dw.system );
importPackage( dw.util );
importPackage( dw.catalog );
importPackage( dw.object );
importPackage( dw.io );
function execute( args : PipelineDictionary ) : Number {
var folderPath : String = "/src/Netrada/";
var includeFinalSaleInFeed : Boolean = Site.getCurrent().getCustomPreferenceValue("includeFinalSaleInFeed");
//Set the time to be used in the header and filename
var currentDate : Calendar = new dw.util.Calendar();
currentDate.timeZone = "GMT";
var timeStamp : String = dw.util.StringUtils.formatCalendar(currentDate, "yyyy-MM-dd/HH:mm:ss");
var dateStamp : String = dw.util.StringUtils.formatCalendar(currentDate, "yyyyMMdd");
// Create text file and directories
var tempFolder = dw.io.File.IMPEX + folderPath;
(new dw.io.File(tempFolder)).mkdirs();
var fileName : String = "bvexportproductids_" + dateStamp + ".txt";
var file : File = new dw.io.File(tempFolder + fileName);
var writer : FileWriter = new FileWriter(file);
// Here we will iterate through every online variation product and create a single line with several attributes
var products : SeekableIterator = ProductMgr.queryAllSiteProducts();
while (products.hasNext()){
var product : Product = products.next();
try {
if(product.online && product.searchable && product.isVariant()) {
writer.writeLine(product.ID);
}
} catch (e) {
// Error handling
Logger.error("An error occured while exporting product {0}. Error: {1}.", product.ID, e);
return PIPELET_ERROR;
}
}
// Close the writer and products iterator to cleanup resources
writer.close();
products.close();
return PIPELET_NEXT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment