From 6d8563aa52ea1f9d820243492053b1e9c7bd095a Mon Sep 17 00:00:00 2001 From: vcua-mobify <47404250+vcua-mobify@users.noreply.github.com> Date: Tue, 24 Jan 2023 10:22:34 -0800 Subject: [PATCH] Update createOrder to send SLAS USID (#920) * Update createOrder to send SLAS USID * Modify some tests to include setting the header Co-authored-by: echessman <37908171+echessman@users.noreply.github.com> --- .../app/commerce-api/hooks/useBasket.js | 5 +++++ .../template-retail-react-app/app/commerce-api/index.test.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/template-retail-react-app/app/commerce-api/hooks/useBasket.js b/packages/template-retail-react-app/app/commerce-api/hooks/useBasket.js index eccf6c9d5c..0dd23e1bb1 100644 --- a/packages/template-retail-react-app/app/commerce-api/hooks/useBasket.js +++ b/packages/template-retail-react-app/app/commerce-api/hooks/useBasket.js @@ -365,6 +365,11 @@ export default function useBasket(opts = {}) { */ async createOrder() { const response = await api.shopperOrders.createOrder({ + // We send the SLAS usid via this header. This is required by ECOM to map + // Einstein events sent via the API with the finishOrder event fired by ECOM + // when an Order transitions from Created to New status. + // Without this, various order conversion metrics will not appear on reports and dashboards + headers: {_sfdc_customer_id: api.auth.usid}, body: {basketId: basket.basketId} }) diff --git a/packages/template-retail-react-app/app/commerce-api/index.test.js b/packages/template-retail-react-app/app/commerce-api/index.test.js index 29f93948dd..a37bec8b81 100644 --- a/packages/template-retail-react-app/app/commerce-api/index.test.js +++ b/packages/template-retail-react-app/app/commerce-api/index.test.js @@ -685,6 +685,7 @@ describe('CommerceAPI', () => { const api = getAPI() fetch.mockResponseOnce(JSON.stringify(ocapiBasketResponse)) const response = await api.shopperOrders.createOrder({ + headers: {_sfdc_customer_id: 'usid'}, parameters: {}, body: {basketId: ''} }) @@ -695,6 +696,7 @@ describe('CommerceAPI', () => { const api = getAPI() fetch.mockResponseOnce(JSON.stringify(ocapiBasketResponse)) const response = await api.shopperOrders.createOrder({ + headers: {_sfdc_customer_id: 'usid'}, parameters: {} }) expect(response.title).toEqual('Body is required for this request') @@ -704,6 +706,7 @@ describe('CommerceAPI', () => { const api = getAPI() fetch.mockResponseOnce(JSON.stringify(ocapiBasketResponse)) const response = await api.shopperOrders.getOrder({ + headers: {_sfdc_customer_id: 'usid'}, parameters: {orderNo: ''} }) expect(response).toBeDefined() @@ -713,6 +716,7 @@ describe('CommerceAPI', () => { const api = getAPI() fetch.mockResponseOnce(JSON.stringify(ocapiBasketResponse)) const response = await api.shopperOrders.getOrder({ + headers: {_sfdc_customer_id: 'usid'}, parameters: {} }) expect(response.title).toEqual( @@ -728,6 +732,7 @@ describe('CommerceAPI', () => { await expect( api.shopperOrders.createOrder({ parameters: {}, + headers: {_sfdc_customer_id: 'usid'}, body: {basketId: ''} }) ).rejects.toThrow(ocapiFaultResponse.fault.message)