#define ccFieldListLog 'facetExport.fieldList.txt' #define ccCRLF chr(13) + chr(10) local lcCaption as string, ; lcFacetExportCategory as string, ; lcFacetExportFile as string, ; lcFacetFields as string, ; lcFacetName as string, ; lcFacetValue as string, ; lcParent as string, ; liFKCategory as integer, ; llCloseCustom as Boolean, ; llErrorOccurred as Boolean, ; lnActive as number, ; lnTable as number, ; loApp as swStorePorter of swStorePorter.vcx, ; loCatLink as swwCatlinkCursorAdapter of swwData.vcx, ; loCustom as swwCustomFieldCursorAdapter of swwData.vcx, ; loException as exception, ; loFam as swwFamilyCursorAdapter of swwData.vcx, ; loProd as swwProductCursorAdapter of swwData.vcx, ; loProgress as swwProgress of swwProgress.vcx, ; loRecord as 'empty', ; loTable as object loApp = oApp lcCaption = 'Facet Export' * Get export file name lcFacetExportCategory = inputbox('Specify category PK or "ALL":', lcCaption) if empty(lcFacetExportCategory) return .f. endif empty(lcFacetExportCategory) liFKCategory = int(val(lcFacetExportCategory)) * Get export file name lcFacetExportFile = getfile('csv', 'Export to', 'Export', 0, 'Specify Facet Export csv file') if empty(lcFacetExportFile) return .f. endif empty(lcFacetExportFile) *llIncludeInactive = loApp.yesNo('Include inactive Products & Families?') lnActive = int(val(inputbox('Specify 1 for Active, 2 for Inactive, or 3 for both:', lcCaption))) if not between(lnActive, 1, 3) return .f. endif not between(lnActive, 1, 3) loProgress = oFactory.make('progress') loProgress.setCaption('Export Facets') loProgress.show(2) loProgress.setStatus('Building facet list...') * Get facet list if not used('customField') use swwebstore!customField in 0 llCloseCustom = .t. endif not used('customField') select distinct upper(name) as name from customField into cursor facetNames if llCloseCustom use in customField endif llCloseCustom * Build header record select facetNames lcFacetFields = '' scan lcFacetName = 'facet' + strtran(trim(facetNames.name), ' ', '_') lcFacetFields = lcFacetFields + lcFacetName + ' M,' endscan * strip comma lcFacetFields = left(lcFacetFields, len(lcFacetFields) - 1) strtofile(lcFacetFields, loApp.cXMLPath + ccFieldListLog) * Setup the export cursor try create cursor facetExport (parent c(7), pk i, sku c(80), name c(240), &lcFacetFields) catch to loException llErrorOccurred = .t. if loException.errorno = 1712 loApp.postMessage('Duplicate facet names. See ' + loApp.cXMLPath + ccFieldListLog + ' for details.') else loApp.postMessage( ; 'Error ' + transform(loException.errorno) + ; ' at line ' + transform(loException.lineno) + '.' + ccCRLF + ccCRLF + ; lcFacetFields) endif loException.errorno = 1712 endtry if llErrorOccurred return .f. endif llErrorOccurred loProd = oFactory.make('product') loFam = oFactory.make('family') loCustom = oFactory.make('customField') loCatLink = oFactory.make('catLink') for lnTable = 1 to 2 loProgress.reset() if lnTable = 1 loTable = loProd store 'PRODUCT' to lcParent, loCatLink.cParent loProgress.setStatus('Querying Products...') loProgress.setCaption('Exporting Product facets...') loCustom.cParent = 'PRODUCT' else loTable = loFam store 'FAMILY' to lcParent, loCatLink.cParent loProgress.setStatus('Querying Families...') loProgress.setCaption('Exporting Family facets...') loCustom.cParent = 'FAMILY' endif lnTable = 1 loTable.goTop() loProgress.setStatus() loProgress.setTotal(loTable.reccount()) do while not loTable.eof() * Ignore active flags that don't match the request do case case lnActive = 3 case lnActive = 1 and not loTable.getValue('active') loProgress.update() loTable.skip() loop case lnActive = 2 and loTable.getValue('active') loProgress.update() loTable.skip() loop endcase * See if it fits the category filter if liFKCategory > 0 && If "ALL" was supplied, don't check loCatLink.nParentPK = loTable.getPK() loCatLink.query() if not loCatLink.isLinked(liFKCategory, .f., .t.) loProgress.update() loTable.skip() loop endif not loCatLink.isLinked(liFKCategory, .f., .t.) endif liFKCategory > 0 * Get facets loCustom.nFKParent = loTable.getPK() loCustom.query() * Build record loRecord = createobject('empty') addproperty(loRecord, 'parent', lcParent) addproperty(loRecord, 'pk', loTable.getPK()) addproperty(loRecord, 'sku', loTable.getValue('sku')) addproperty(loRecord, 'name', loTable.getValue('name')) loCustom.goTop() do while not loCustom.eof() lcFacetName = 'facet' + strtran(trim(loCustom.getValue('name')), ' ', '_') lcFacetValue = trim(loCustom.getValue('text')) if pemstatus(loRecord, lcFacetName, 5) loRecord.&lcFacetName = loRecord.&lcFacetName + '|' + lcFacetValue else addproperty(loRecord, lcFacetName, lcFacetValue) endif pemstatus(loRecord, lcFacetName, 5) loCustom.skip() enddo && while not loCustom.eof() * Add record insert into facetExport from name loRecord * Next product loProgress.update() loTable.skip() enddo && while not loTable.eof() next lnTable select facetExport copymck('facetExport', lcFacetExportFile, .t.) && Include header record use in facetExport