Migrating B2B projects to version 2 of the Frontend SDK
This guide helps you migrate your B2B projects from version 1 to version 2 of the commercetools Frontend SDK. If you made custom changes to your project, you must check if these need updates too.
For migrating B2C projects, see the migration guide for B2C projects.
Version 2 of the SDK contains breaking changes.
Migrate your project
To migrate your B2B project to version 2 of the Frontend SDK, follow these steps:
Update the
@commercetools/frontend-sdk
package to the latest SDK version in one of the following ways:- Run the Yarn command:
yarn upgrade @commercetools/frontend-sdk
. - Go to your project's
package.json
file and update the version number to the latest version listed on NPM. Save the file, then runyarn install
andyarn.lock
.
- Run the Yarn command:
Go to your project's
events
file at:packages/PROJECT_NAME/frontend/src/sdk/composable-commerce-b2b/types/events/ComposableCommerceEventsB2B.ts
. Add the following event to the file:Event to add to the ComposableCommerceEvents.ts fileTypeScript ReactprojectSettingsFetched: {projectSettings: unknown;}In version 1 of the SDK, this event was located in the
StandardEvents.ts
file.In all files at this path
packages/PROJECT_NAME/frontend/src/sdk/composable-commerce-b2b/library/actions
, replaceskipQueue
withparallel
in theoptions
parameters of theSDK.callAction
arguments. By default, all actions are executed asynchronously in version 2 of the SDK. To override this and queue actions for sequential execution, passparallel: false
to theSDK.callAction
argument.In
packages/PROJECT_NAME/frontend/sdk/src/composable-commerce-b2b/library/actions/AccountActions
, replace therememberMeCookieAsync
import withrememberMeCookie
, and update all references to it.By default, all cookie management methods are asynchronous.
In
packages/PROJECT_NAME/frontend/src/lib/hooks/usePurchaseLists/index.ts
, wrap theremoveFromWishlists
payload object in a{ wishlists }
object. Then, inpackages/PROJECT_NAME/backend/commerce-commercetools/actionControllers/WishlistController.ts
, update therequestBody
in theremoveLineItems
action to reflect the change to the{ wishlists }
object.Delete the following files:
packages/PROJECT_NAME/frontend/src/types/lib/page.d.ts
packages/PROJECT_NAME/frontend/src/types/lib/response.ts
.
In
packages/PROJECT_NAME/frontend/src/lib/renderer/index.tsx
, add a non-null assertion operator to section errors. For example, updatesection.
tosection!.
in the sections mapping in the component return. This is to ensure compatibility and correct syntax for TypeScript.In
packages/PROJECT_NAME/frontend/src/app/[locale]/[[...slug]]/page.tsx
, replace all of the file's content with the content in the latest version of thepage.tsx
file.If you have made custom updates to your project, check them against this guide and the list of changes, and update any references or dependencies as needed.