From 4d2f60a78c004ddecba060620fcfa944a95cab61 Mon Sep 17 00:00:00 2001 From: ssachtleben Date: Wed, 26 Jul 2017 09:07:02 +0200 Subject: [PATCH] release 17.1.0 --- {int_styla => cartridges/int_styla}/.project | 0 .../int_styla}/.tern-project | 0 .../cartridge/controllers/StylaMagazine.js | 181 +++++++++++ .../example/pipelines/RedirectURL.xml | 183 +++++++++++ .../int_styla}/cartridge/int_styla.properties | 0 .../int_styla}/cartridge/js/styla/cart.js | 4 +- .../cartridge/pipelines/StylaMagazine.xml | 73 +++++ .../int_styla/cartridge/scripts/StylaMain.js | 245 +++++--------- .../scripts/init/StylaServiceInit.js | 0 .../scripts/pipelets/GetAliasPipeline.js | 51 +++ .../default/rendering/catlanding.isml | 0 .../default/rendering/pt_catlanding.isml | 0 .../templates/default/styla/bodycontent.isml | 18 +- .../templates/default/styla/bodyinclude.isml | 16 + .../templates/default/styla/empty.isml | 0 .../default/styla/headercontent.isml | 2 +- .../default/styla/headerinclude.isml | 7 + cartridges/int_styla/package.json | 7 + documentation/Integration Guide.html | 303 ++++++++++++------ .../images/{ => intguide}/cartridge_path.png | Bin .../images/{ => intguide}/catchall.png | Bin .../flow_add_product_to_cart.png | Bin .../flow_add_product_to_story.png | Bin .../flow_magazine_page_generation.png | Bin .../flow_show_product_details.png | Bin .../images/{ => intguide}/pipeline_alias.png | Bin .../intguide/redirect_pipeline_1_orig.png | Bin 0 -> 9478 bytes .../redirect_pipeline_2_error_templ.png | Bin 0 -> 24221 bytes .../redirect_pipeline_3_error_call.png | Bin 0 -> 8717 bytes .../redirect_pipeline_4_check_pref.png | Bin 0 -> 17153 bytes .../images/intguide/search_pipeline_1.png | Bin 0 -> 35073 bytes .../versionservice_credentials.png | Bin .../{ => intguide}/versionservice_profile.png | Bin .../{ => intguide}/versionservice_service.png | Bin .../{ => intguide}/webservice_credentials.png | Bin .../{ => intguide}/webservice_profile.png | Bin .../{ => intguide}/webservice_service.png | Bin documentation/markdown.css | 56 +++- .../templates/default/styla/bodyinclude.isml | 14 - .../default/styla/headerinclude.isml | 7 - int_styla/package.json | 7 - metadata/styla_magazine_metadata.xml | 19 +- ...rvices.xml => styla_magazine_services.xml} | 6 +- metadata/styla_magazine_services/version.txt | 5 - 44 files changed, 873 insertions(+), 331 deletions(-) rename {int_styla => cartridges/int_styla}/.project (100%) rename {int_styla => cartridges/int_styla}/.tern-project (100%) create mode 100755 cartridges/int_styla/cartridge/controllers/StylaMagazine.js create mode 100755 cartridges/int_styla/cartridge/example/pipelines/RedirectURL.xml rename {int_styla => cartridges/int_styla}/cartridge/int_styla.properties (100%) rename {int_styla => cartridges/int_styla}/cartridge/js/styla/cart.js (80%) create mode 100755 cartridges/int_styla/cartridge/pipelines/StylaMagazine.xml rename int_styla/cartridge/controllers/StylaMagazine.js => cartridges/int_styla/cartridge/scripts/StylaMain.js (59%) rename int_styla/cartridge/scripts/init/StylaServiceInit.ds => cartridges/int_styla/cartridge/scripts/init/StylaServiceInit.js (100%) create mode 100755 cartridges/int_styla/cartridge/scripts/pipelets/GetAliasPipeline.js rename {int_styla => cartridges/int_styla}/cartridge/templates/default/rendering/catlanding.isml (100%) rename {int_styla => cartridges/int_styla}/cartridge/templates/default/rendering/pt_catlanding.isml (100%) rename {int_styla => cartridges/int_styla}/cartridge/templates/default/styla/bodycontent.isml (57%) create mode 100755 cartridges/int_styla/cartridge/templates/default/styla/bodyinclude.isml rename {int_styla => cartridges/int_styla}/cartridge/templates/default/styla/empty.isml (100%) rename {int_styla => cartridges/int_styla}/cartridge/templates/default/styla/headercontent.isml (89%) create mode 100755 cartridges/int_styla/cartridge/templates/default/styla/headerinclude.isml create mode 100755 cartridges/int_styla/package.json rename documentation/images/{ => intguide}/cartridge_path.png (100%) rename documentation/images/{ => intguide}/catchall.png (100%) rename documentation/images/{ => intguide}/flow_add_product_to_cart.png (100%) rename documentation/images/{ => intguide}/flow_add_product_to_story.png (100%) rename documentation/images/{ => intguide}/flow_magazine_page_generation.png (100%) rename documentation/images/{ => intguide}/flow_show_product_details.png (100%) rename documentation/images/{ => intguide}/pipeline_alias.png (100%) create mode 100755 documentation/images/intguide/redirect_pipeline_1_orig.png create mode 100755 documentation/images/intguide/redirect_pipeline_2_error_templ.png create mode 100755 documentation/images/intguide/redirect_pipeline_3_error_call.png create mode 100755 documentation/images/intguide/redirect_pipeline_4_check_pref.png create mode 100755 documentation/images/intguide/search_pipeline_1.png rename documentation/images/{ => intguide}/versionservice_credentials.png (100%) rename documentation/images/{ => intguide}/versionservice_profile.png (100%) rename documentation/images/{ => intguide}/versionservice_service.png (100%) rename documentation/images/{ => intguide}/webservice_credentials.png (100%) rename documentation/images/{ => intguide}/webservice_profile.png (100%) rename documentation/images/{ => intguide}/webservice_service.png (100%) delete mode 100755 int_styla/cartridge/templates/default/styla/bodyinclude.isml delete mode 100755 int_styla/cartridge/templates/default/styla/headerinclude.isml delete mode 100755 int_styla/package.json rename metadata/{styla_magazine_services/services.xml => styla_magazine_services.xml} (93%) delete mode 100755 metadata/styla_magazine_services/version.txt diff --git a/int_styla/.project b/cartridges/int_styla/.project similarity index 100% rename from int_styla/.project rename to cartridges/int_styla/.project diff --git a/int_styla/.tern-project b/cartridges/int_styla/.tern-project similarity index 100% rename from int_styla/.tern-project rename to cartridges/int_styla/.tern-project diff --git a/cartridges/int_styla/cartridge/controllers/StylaMagazine.js b/cartridges/int_styla/cartridge/controllers/StylaMagazine.js new file mode 100755 index 0000000..f91dce8 --- /dev/null +++ b/cartridges/int_styla/cartridge/controllers/StylaMagazine.js @@ -0,0 +1,181 @@ +'use strict'; + +/** + * Controller exposes methods for injecting Styla JavaScript and SEO content. + * + * @module controllers/StylaMagazine + * + * + * Do not reference the storefront controller cartridge here (e.g to re-use 'app' or 'guard'): + * This montroller module is also called via remote include even when the storefront uses pipelines. + * IOW: the storefront controller cartridge may or may not exist when this controller executes. + * + */ + +var Logger = require('dw/system/Logger').getLogger('styla', 'StylaMagazine'); +var ISML = require('dw/template/ISML'); + +var StylaMain = require('/int_styla/cartridge/scripts/StylaMain'); + + +const CONFIG_CO_TYPE = 'StylaMagazineConfiguration'; // custom object type for storing magazine configurations +const CONFIG_CO_KEY_ATTR = 'Key_and_Sort_Order'; // name of the custom object's key attribute +const CONFIG_CO_SORT_ORRDER = 'custom.' + CONFIG_CO_KEY_ATTR + ' asc'; // sort order of custom objects + + + +function renderContent(template) { + var pdict = StylaMain.GetRenderContent(); + if (pdict) { + ISML.renderTemplate(template, pdict); + } + else { + ISML.renderTemplate('styla/empty'); + } +} + + +/** + * Inject Styla JavaScript library and SEO content into page header. Use as remote include. + */ +function headerContent() { + renderContent('styla/headercontent'); +} + + +/** + * Inject Styla JavaScript library and SEO content into page body. Use as remote include. + */ +function bodyContent() { + renderContent('styla/bodycontent'); +} + + +/** + * Render the Styla cartridge version. + */ +function cartridgeVersion() { + + var versionInfo = { + version: require('~/package.json').cartridgeVersion + }, + str; + + if (request.httpParameterMap.isParameterSubmitted('username')) { + var StylaMain = require('/int_styla/cartridge/scripts/StylaMain'); + var userName = request.httpParameterMap.get('username').stringValue; + versionInfo.seoContent = StylaMain.GetContentVersion({username: userName}); + } + + str = JSON.stringify(versionInfo, null, '\t'); + + response.setContentType('application/json'); + response.setExpires(5 * 60 * 1000); // 5 minutes + response.writer.print(str); +} + + +/** + * If the current URL is part of a magazine, then jump to the corresponding + * controller method so that the original URL is preserved in the browser. + * + * This is called from RedirectURL.start() if no matching redirect rule was found. + * + * E.g. assume we have an alias 'magazine' assigned to a pipeline which renders a Styla magazine. + * When interacting with the magazine the Styla JavaScript will modify the URL in the + * customer's browser to e.g. 'magazine/stories/5'. + * Because RedirectUrl.start() doesn't find a matching rule for 'magazine/stories/5' + * it calls this function. + * + * @param path Original URL before redirect. + * @returns True, if a matching magazine configuration was found and the configured + * controller method was called successfully. + */ +function alias(path) { + var result = false, + magazineConfig = StylaMain.GetConfigForAlias(path), + parts; + + if (magazineConfig) { + // read controller method method from configuration + parts = magazineConfig.pipeline.split('-'); + if (parts.length === 3) { + var controllerCartridge = parts[0], + controllerName = parts[1], + controllerMethod = parts[2], + controllerPath = controllerCartridge + '/cartridge/controllers/' + controllerName, + controller; + controller = require(controllerPath); + if (typeof controller[controllerMethod] === 'function') { + // store category ID in case the controller method is Search.show(), + // and header template uses this to set HTTP status + request.custom.MagazineConfiguration = magazineConfig; + // call controller method + controller[controllerMethod](); + result = true; + } + else { + Logger.error('alias: method not found or not a function: ' + magazineConfig.pipeline); + } + } + else { + var pip = magazineConfig.pipeline; + if (typeof magazineConfig.pipeline === 'undefined') { + pip = '(undefined)'; + } + else if (magazineConfig.pipeline === null) { + pip = '(null)'; + } + Logger.error('alias: invalid controller method specified: "{0}"', pip); + } + } + else { + Logger.debug('no matching config found for path: ' + path); + } + + + return result; +} + + + + +/* + * Module exports + */ + + +/* + * Web exposed methods - only used via 'remote include' + */ + +/** Renders Styla header fragment. + * @see module:controllers/StylaMagazine~headerContent */ +exports.HeaderContent = headerContent; +exports.HeaderContent.public = true; + +/** Renders Styla body fragment. + * @see module:controllers/StylaMagazine~bodyContent */ +exports.BodyContent = bodyContent; +exports.BodyContent.public = true; + + +/* + * Web exposed methods + */ + +/** Renders Styla cartridge version. + * @see module:controllers/StylaMagazine~cartridgeVersion */ +exports.CartridgeVersion = cartridgeVersion; +exports.CartridgeVersion.public = true; + + +/* + * Local methods + */ + +/** Redirect logic. Called from storefront controller RedirectURL.js. + * @see module:controllers/StylaMagazine~alias */ +exports.Alias = alias; + + diff --git a/cartridges/int_styla/cartridge/example/pipelines/RedirectURL.xml b/cartridges/int_styla/cartridge/example/pipelines/RedirectURL.xml new file mode 100755 index 0000000..b205912 --- /dev/null +++ b/cartridges/int_styla/cartridge/example/pipelines/RedirectURL.xml @@ -0,0 +1,183 @@ + + + + + + + + + Pipeline is called by the system to handle URL mappings (static mappings and mapping rules). The mappings are configured in Business Manager. This Pipeline is highly performance cricitcal, because it is frequently called in case of explot scans. Please follow these rules: +- no or only few database calls +- simple (static) template response +- caching the result page is a must + +In: +OriginalURL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +