Feat/Cart and order data persistence on the server side #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Voucherify is a Promotion Engine which allows marketing teams to run digital promotions like coupons, gift cards, referrals, bundles and loyalty. As the headless commerce solution and Mach Alliance member, we want to integrate Composable UI with Voucherify to help our community better understand how to build promotion features efficiently in the composable commerce storefront.
I appreciate your effort to build and share the Composable UI accelerator. I really enjoy working on this application; it's flexible and well-designed. Still, I encountered a problem which I need to solve first before I will be able to continue building this integration (as a part of another future PR).
Problem
To show a little more advanced digital promotion scenarios in the storefront, we need functionality that allows users to add more than one product to the cart in Composable UI. Unfortunately, currently as the user :
Venture Daypack
product) after refreshing the page in the browser,The reason for this behaviour is an example
commerce-generic
service that manages the cart and orders data without any data persistence on the server side. Because ofcommerce-generic
implementation simplification, this service can not keep consistent responses in a series ofcreateCart
,addCartItem
,updateCartItem
, andgetCart
requests.Solution
We have prepared a Pull Request to Composable UI repository, where we have improved
commerce-generic
service by adding cart and order data file-based persistence, so it allows users to manage products in the cart more freely.Summary of the changes:
node-persist
package, which provides a minimalistic API to persist data in JSON files and reduce code complexity,/tmp
folder. From our experience, this lasts long enough (10+ minutes) to keep a nice user experience.next-runtime
library: Linkcommerce-generic
service, except:cartId
param to thecreateOrder
requestcomposable-ui/src/utils/__mocks__/api.ts
- we have added missing mocked data fixing testsrc/components/__tests__/home-page.test.tsx
, which fails onmain
branchHere is a video that shows the difference in behaviour. On the left side, we have changes from this PR; on the right side application before changes:
Screen.Recording.2023-10-27.at.10.42.29.mov