demandware - 在内容 Assets 中创建 session 重定向链接

标签 demandware salesforce-commerce-cloud

我们公司有多个品牌,每个品牌都有自己的主机名,但它们都是同一网站的一部分。我们可以让客户在使用 URLUtils.sessionRedirect 通过重定向链接在品牌之间切换时共享购物篮和其他 session 信息。

但是 URLUtils 在内容 Assets 中不可用。是否可以在保留所有 session 信息的内容 Assets 中形成 session 重定向链接?

提前致谢。

最佳答案

您可以使用 $include('Controller-Name', 'name1', 'value1', 'name2', 'value2', ...)$ 在内容 Assets 中包含动态内容句法。请参阅MarkupText Class Documentation有关该语法的更多信息。 'name1' 和 'value1' 参数映射为查询字符串属性,例如:Controller-Name?name1=value1&name2=value2

创建一个输出所需 session 重定向链接的 Controller ,并通过以下语法调用它:$include(Util-RenderSessionLink, 'siteID', 'foo')$

Controller 需要使用 text/plain 或类似内容的响应 Content-Type header ,以便不会将任何内容注入(inject)到响应中。 (例如:店面工具包或跟踪标签)例如:

response.setContentType('text/plain');

或者,您可以处理内容 Assets 以获取对其执行查找和替换操作的某些类型的键。例如,以下代码对内容 Assets 的正文内容执行查找和替换键:“%%SessionLink%%”。

var ContentMgr = require('dw/content/ContentMgr');
var URLUtils = require('dw/web/URLUtils');

if (!empty(content) {
  var content = ContentMgr.getContent('my-content-id');
  var contentOut = "";
  var viewData = {};
  
  contentOut = content.custom.body.getMarkup()
     .replace('%%SessionLink%%', URLUtils.sessionRedirect(...));
  
  viewData.content = contentOut;
  // then output your `pdict.content` key within a template with the appropriate encoding
}

关于demandware - 在内容 Assets 中创建 session 重定向链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65512377/

相关文章:

demandware - 如何在 Demandware 中编辑网站托管的源代码?

javascript - Salesforce Commerce Cloud 使用哪个版本的 Rhino JavaScript?

demandware - 我们如何从 SFCC(需求软件)获取最后访问的管道。

demandware - 我想开始学习 Demandware

regex - APO 和 FPO 的正则表达式导致问题 当城市是 APOAPKO 时,因为城市名称以 APO 开头

javascript - 如何使用es6的动态导入从静态导入模块?

salesforce - SFCC - 帮助将所有产品从 Salesforce Commerce Cloud(Demandware)导出到 XML 或 CSV

Demandware/SFCC 先决条件

Salesforce Commerce Cloud/Demandware - OCAPI 按日期范围查询订单