adobe / aem-core-cif-components

A set of configurations and components to get you started with AEM Commerce development
Apache License 2.0
102 stars 80 forks source link

EventCollectorContextProvider missing context values when setting storefront instance #1003

Open MichaelHeinzman opened 7 months ago

MichaelHeinzman commented 7 months ago

Expected Behaviour

  1. StorefrontInstanceContext requires the following fields in the snowplow schema for iglu:com.adobe.magento.entity/storefront-instance/jsonschema/3-0-1

    "environmentId", "environment", "storeUrl", "websiteId", "storeId", "storeViewId", "websiteName", "storeName", "storeViewName", "baseCurrencyCode", "storeViewCurrencyCode"

  2. Expected behavior is the EventCollectorContextProvider has these fields in the context when applying mse.context.setStorefrontInstance(context).

  3. Expected add-to-cart event storefront instance to include these fields but only saw baseCurrencyCode and storeViewCurrencyCode.

Actual Behaviour

  1. It only has baseCurrencyCode and storeViewCurrencyCode in the context.

Reproduce Scenario (including but not limited to)

  1. Implement EventCollectorContextProvider and try to send an add-to-cart event.
  2. Check the snowplow schema and storefront instance will only have two fields in data when schema expects more listed above.

Fix for the issue

  1. Created custom ExperiencePlatformConnector from the source code and added fields to the graphql query and when setting the storefront instance context.

Changes made to graphql query

import { gql } from '@apollo/client'; export default gql` query DataServicesStorefrontInstanceContext { dataServicesStorefrontInstanceContext { catalog_extension_version environment environment_id store_code store_id store_name store_url store_view_code store_view_id store_view_name website_code website_id website_name } storeConfig { base_currency_code store_code } }

Changes made to Storefront Instance context

storeConfigQuery().then(({ data }) => { const { environment, environment_id, website_id, website_code, website_name, store_url, store_id, store_code, store_name, store_view_id, store_view_code, store_view_name, catalog_extension_version } = data.dataServicesStorefrontInstanceContext; const { base_currency_code } = data.storeConfig; const context = { environmentId: environment_id, environment, storeUrl: store_url, websiteId: website_id, websiteCode: website_code, storeId: store_id, storeCode: store_code, storeViewId: store_view_id, storeViewCode: store_view_code, websiteName: website_name, storeName: store_name, storeViewName: store_view_name, baseCurrencyCode: base_currency_code, storeViewCurrencyCode: base_currency_code, catalogExtensionVersion: catalog_extension_version };

mse.context.setStorefrontInstance(context);

}); `;