Skip to content

Dynamic Context

danneg edited this page Feb 9, 2022 · 10 revisions

dependency: tag >= 1.3.0 check the composer.json requirements for the versions used

Before you continue, make sure the required integration steps have been completed.

The content of the response depends 100% on your design and layout blocks desired.

Before you start, the layout blocks & narrative layout must be defined in Boxalino Intelligence admin.

The Layout Blocks JSON & Narratives JSON from this page can be used as base.

If there is no narrative assigned to the choice/widget requested, the response will be empty.

Integration Description

The dynamic context is about generating dynamic routes with dynamic content. For example:

  • brand pages: /brand/brand-name, where brand-name value is sent as a request context parameter used for content-mapping (filter) at the TPO level
  • landing pages: /campaign/campaign-name, where campaign-name value is mapped to an existing Boxalino campaign that defines the product rules and to a narrative to represent the layout

The Dynamic Context Strategy

This strategy implies:

  1. adding a custom route
  2. creating a controller (which will also set the SEO properties for the page)
  3. adding a layout.xml (2columns-left, 1column, etc)
  4. (part of the controller) sending context parameters, based on which the content of the page is filtered

The usual the process is :

  • implement your narrative (layout & templates) with static narratives
  • we dynamize the narratives for you

Layout Elements

Boxalino Narrative API returns dynamic layout content to be displayed in your e-shop. This means that you will receive directly the layout which should be implemented for the specific situation you are in.

The narrative layout must include all the Layout Blocks required for the view. More WPOs can be combined with the use of "accessor":

  • title of the page
  • product sliders (ex: popular items from a different WPO)
  • campaign sliders (ex: active campaigns from a different WPO)
  • product listing & facets
  • sub-content (ex: links to other pages, from facets or other properties)

Prerequisites

Before the (code) integration, please make sure:

  1. the layout requirements are provided by the client (elements, design)
  2. the layout has been divided/isolated into Layout Blocks (check the Integration Guide
  3. the layout blocks are created in Boxalino Intelligence Admin with the required JSON schema for the use-case
  4. the narrative layout is built and linked to a WPO (main request)
  5. define static content in the narrative layout (for campaigns, banners, titles, names, etc). the migration to a dynamic-context is done by Boxalino once the layout narrative is final and the integration works with static content.

Steps

Steps 1-2 are generic (but custom) for an API integration. Steps 3-6 are Magento default.

  1. Create the DynamicContext model In this samples, the base filters (category, visibility, status) have been removed. This is only to be done if the filters are defined in the TPO or your context indeed requires no product filters.

  2. Create the Dynamic API block Similar to a CMS integration, the block will read the properties from the layout.xml and set them to the ApiContext. Further, the ApiLoader will make the API call and load the content in an ApiResponsePage element.

The DynamicContext & Dynamic block can be used for more than one layout/narrative because the properties are set in the layout

  1. Declare the route for the integration repository This property is required in order to manage the breadcrumbs and to match the route.

  2. Define and create the custom route In this sample, the router matches a request path like /campaign/ An AbstractRouter is provided in the rtux-magento2 library which can be used as base.

Integration aspects (custom)

  • the request context parameters (used for content-mapping to make the narrative dynamic) (ex: brand name, camapaign name, facet values, etc)
  1. Create the controller The controller will also handle the SEO properties on the page (title, keywords, description, breadcrumbs) The SEO content is set in the Narrative view >> SEO Content tab; the Page Title is set in the General tab

  2. Create the .xml This is a Magento2 definition. For this sample, there is a 2columns-left layout used, with content in left, top and main. Please make sure the arguments for the Dynamic context are valid (return fields, widget, etc)

Layout Blocks

These are a series of HELPER layout blocks, that might help you structure/group the elements into individual "position" wrappers.

Position Wrapper

[{"id":2096,"uniqueKey":"rtux_wrapper_position","parametersJsonScheme":"{\n \"title\": \"Content wrapper\",\n \"type\": \"object\",\n \"properties\": {\n\"position\": {\n \"type\": \"string\",\n \"description\": \"The value set will create an individual node in the API response\"\n },\n \"accessor\": {\n \"type\": \"string\",\n \"description\": \"hits accessor (typically leave empty)\"\n }\n }\n}","format":null,"widgets":[],"parameters":[{"name":"content-resource","values":["c-r=t"]},{"name":"name","values":["rtux_wrapper_position"]},{"name":"type","values":["Boxalino\\RealTimeUserExperience\\Block\\Api\\Block"]},{"name":"template","values":["Boxalino_RealTimeUserExperience::api/block.phtml"]}],"subRenderings":[],"route":"visual-elements","reqParams":null,"$fromServer":true,"parentResource":null,"restangularCollection":false,"contentResource":false,"isSelected":true}]

Content Block & Items (generic)

[{"id":1981,"uniqueKey":"rtux_content_item","parametersJsonScheme":"","format":null,"widgets":[],"parameters":[{"name":"content-resource","values":["c-r=t"]},{"name":"bx-hit","values":["accessor"]},{"name":"name","values":["rtux_content_item"]},{"name":"template","values":["BoxalinoClientProject_BoxalinoIntegration::api/element/content/item.phtml"]},{"name":"type","values":["Boxalino\\RealTimeUserExperience\\Block\\Api\\Item"]}],"subRenderings":[],"route":"visual-elements","reqParams":null,"$fromServer":true,"parentResource":null,"restangularCollection":false,"isSelected":true},{"id":1982,"uniqueKey":"rtux_content_list","parametersJsonScheme":"{\n \"title\": \"Content List(blog, product, etc)\",\n \"type\": \"object\",\n \"properties\": {\n \"content\": {\n \"type\": \"string\",\n \"description\": \"Content type\"\n },\n \"accessor\": {\n \"type\": \"string\",\n \"description\": \"accessor (for connection to other widgets)\"\n }\n }\n}","format":null,"widgets":[],"parameters":[{"name":"bx-hits","values":["accessor"]},{"name":"name","values":["rtux_content_list"]},{"name":"template","values":["BoxalinoClientProject_BoxalinoIntegration::api/element/content/list.phtml"]},{"name":"type","values":["Boxalino\\RealTimeUserExperience\\Block\\Api\\ListApi"]}],"subRenderings":[],"route":"visual-elements","reqParams":null,"$fromServer":true,"parentResource":null,"restangularCollection":false,"isSelected":true},{"id":1986,"uniqueKey":"rtux_content_block","parametersJsonScheme":"{\n \"title\": \"Content (blog, product, etc)\",\n \"type\": \"object\",\n \"properties\": {\n \"link\": {\n \"type\": \"object\",\n \"title\": \"Content URL\",\n \"properties\": {\n \"de\": {\n \"type\": \"string\",\n \"description\": \"Set Content View URL in German.\"\n },\n \"fr\": {\n \"type\": \"string\",\n \"description\": \"Set Content View URL in French.\"\n },\n \"it\": {\n \"type\": \"string\",\n \"description\": \"Set Content View URL in Italian.\"\n },\n \"en\": {\n \"type\": \"string\",\n \"description\": \"Set Content View URL in English.\"\n }\n }\n },\n \"image\": {\n \"type\": \"object\",\n \"title\": \"Image\",\n \"properties\": {\n \"de\": {\n \"type\": \"string\",\n \"description\": \"Set Image Source in German.\"\n },\n \"fr\": {\n \"type\": \"string\",\n \"description\": \"Set Image Source in French.\"\n },\n \"it\": {\n \"type\": \"string\",\n \"description\": \"Set Image Source in Italian.\"\n },\n \"en\": {\n \"type\": \"string\",\n \"description\": \"Set Image Source in English.\"\n }\n }\n },\n \"title\": {\n \"type\": \"object\",\n \"title\": \"Name\",\n \"properties\": {\n \"de\": {\n \"type\": \"string\",\n \"description\": \"Set Content title in German.\"\n },\n \"fr\": {\n \"type\": \"string\",\n \"description\": \"Set Content title in French.\"\n },\n \"it\": {\n \"type\": \"string\",\n \"description\": \"Set Content title in Italian.\"\n },\n \"en\": {\n \"type\": \"string\",\n \"description\": \"Set Content title in English.\"\n }\n }\n },\n \"description\": {\n \"type\": \"object\",\n \"title\": \"Content Description\",\n \"properties\": {\n \"de\": {\n \"type\": \"string\",\n \"description\": \"Set Content details in German.\"\n },\n \"fr\": {\n \"type\": \"string\",\n \"description\": \"Set Content details in French.\"\n },\n \"it\": {\n \"type\": \"string\",\n \"description\": \"Set Content details in Italian.\"\n },\n \"en\": {\n \"type\": \"string\",\n \"description\": \"Set Content details in English.\"\n }\n }\n }\n }\n}","format":null,"widgets":[],"parameters":[{"name":"content-resource","values":["c-r=t"]},{"name":"bx-hit","values":["accessor"]},{"name":"name","values":["rtux_content_item"]},{"name":"template","values":["BoxalinoClientProject_BoxalinoIntegration::api/element/content/block.phtml"]}],"subRenderings":[],"route":"visual-elements","reqParams":null,"$fromServer":true,"parentResource":null,"restangularCollection":false,"isSelected":true}]

WPO logic

[{"id":0,"useCaseModelSource":"library","useCaseModelId":14,"useCaseModelVersion":1,"useCaseModelSubVersion":1,"name":"filter on the brand","order":"2","orGroup":null,"fromIndex":-1,"toIndex":-1,"maxWeight":null,"variant":"","scope":"local","overwriteLevel":1,"overwriteLabel":[null],"globalTargetTags":[null],"active":true,"parameters":[{"name":"field","value":{"format":"FieldParameterValue","value":"brand"},"scope":"global"},{"name":"operator","value":{"format":"StringParameterValue","value":"matches exactly"},"scope":"global"},{"name":"requestContextParameter","value":{"format":"StringParameterValue","value":"brand"},"scope":"global","startval":{},"schema":""},{"name":"required","value":{"format":"BooleanParameterValue","value":false},"scope":"global"},{"name":"queryPathParameter","value":{"format":"StringParameterValue","value":""},"scope":"global","startval":{},"schema":""},{"name":"orCondition","value":{"format":"BooleanParameterValue","value":false},"scope":"global"},{"name":"boostFilter","value":{"format":"BooleanParameterValue","value":false},"scope":"global"},{"name":"boostWeight","value":{"format":"StringParameterValue","value":"500"},"scope":"global","startval":{},"schema":""}],"segmentationIds":null,"segmentationUniqueKeys":[],"CPOInitiativeId":null,"notes":null,"options":{"status":null,"includeWidgets":null,"excludeWidgets":null,"allWidgets":null,"conditionalSegments":null,"conditionalProductSelections":null,"ordering":null,"parameters":[{"name":"system","values":["false"]}],"allLinkedAccounts":null,"accounts":null},"icons":{"strategy":{"value":"cpo_sales.png","tooltip":"SALES OPTIMIZATION"},"level":{"value":"L1","tooltip":"LEVEL 1 - ONLINE CONVERSIONS"},"initiative":{"value":"fa-folder","tooltip":"EFFECTIVE CONTEXT"},"character":{"value":"","tooltip":""},"mode":{"label":"","value":"","tooltip":""}},"sections":[{"id":"main","label":"Values","active":true},{"id":"advanced","label":"Advanced","active":false}],"status":true,"isSelected":true}]