User Tools

Site Tools


Add Store Id

Summary

Below is an example demonstrating how you can add a StoreId to the database so that metadata that defines a product associated with that StoreId can be imported and ultimately show up within the database driven content views, via script.

API Areas of Interest

Example

DB_Add_Store_Id.dsa
// DAZ Studio version 3.3.0.11
 
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sStoreID, sURL, sToken, bVerbose ){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// Get the asset manager
	var oAssetMgr = App.getAssetMgr();
	// If the asset manager is not found
	if( !oAssetMgr ){
		// We are done...
		return;
	}
 
	// Get the list of known store identifiers
	var aStoreIDs = oAssetMgr.getStoresIDs();
 
	// Iterate over the store IDs
	for( var i = 0, numStores = aStoreIDs.length; i < numStores; i += 1 ){
		// Convert for case-insensitive comparisons
		aStoreIDs[ i ] = aStoreIDs[ i ].toLowerCase();
	}
 
	// Define a common string
	var sButton = text( "&OK" );
 
	// If the store is already in the list
	if( aStoreIDs.indexOf( sStoreID.toLowerCase() ) > -1 ){
		// If being verbose
		if( bVerbose ){
			// Inform the user
			MessageBox.warning(
				text( "StoreID:\t%1\nURL:\t%2\nToken:\t%3" )
					.arg( sStoreID )
					.arg( oAssetMgr.getStoreUrl( sStoreID ) )
					.arg( oAssetMgr.getStoreToken( sStoreID ) ),
				text( "Collision Error" ), sButton, "" );
		}
 
		// We are done...
		return;
	}
 
	// If the store is successfully added to the database
	if( oAssetMgr.createStore( sStoreID, sToken, sURL ) ){
		// If being verbose
		if( bVerbose ){
			// Inform the user
			MessageBox.information(
				text( "The \"%1\" store has been added.\nURL: %2\nToken: %3" )
					.arg( sStoreID )
					.arg( sURL )
					.arg( sToken ),
				text( "Information" ), sButton );
		}
	}
 
// Finalize the function and invoke
} )( "My Store", "http://www.mystore.com/products/@.html", "@", true );