I have a cart in django that uses session to track the user. The cart is created when the user adds an item to cart, also checks if the cart existed by session id. But when I run an add to cart mutation in react, Django creates a new cart every time.
Related
Lets say we have a basic shopping app with a shopping cart, whenever the user adds an item to the cart a request is sent to the backend in order to persist the shopping cart.
I am contemplating between two approches to this achive this.
The client sends the updated shopping cart and awaits a response from the backend, only after the requests completes the shopping cart is updated to reflect the change, if the request fails an error is shown instead.
When the shopping cart is updated on the client the change is reflected immediately, then if the request failed an error is shown and the state reverts to before the request.
The advantage of the second method is that the changes are instantaneous while the first method has a response time, but the second method might confuse users in the case that a request fails.
I am wondering which method is better, or if there is a better way to go about this?
Is there an industry standard for this problem?
Note: I am working with react / nodejs backend in case this is relevent.
On a personal project related to an online shopping website I have a list of the products page, I'm trying that after I delete a product to refetch the products. I'm using Next.JS and Firebase as a database.
The first time when the page is loaded I'm getting the products with getStaticProps
export const getStaticProps = async (context) => {
const items = Array.from(await getItems({shouldShuffle: false}));
// more code + return items
}
How can I recall the items var after deleting a product to refetch items?
You can investigate using On-demand Revalidation (Beta), which allows you to manually purge the Next.js cache for a specific page.
This only works for v12.1.0 or more. If you're in a previous version, you will not be able to purge/bust the cache unless you either redeploy or set a revalidate property that specifies the seconds after which an automatic page re-generation will occur.
I'm building site using woocommerce as backend and react as UI but i'm not finding any solution to store cart items for logged in users. Is there any API or can any custom API endpoint can be created to store this? Also, for cart functionality i've use react-use-cart hooks to store state of cart and all the cart information is stored in localstorage.
I'm working on the backend for the eCommerce app and currently need to save cart items in the database
My question is it good practice to perform a crud operation on it each time user interacts with the cart?
ex: user add the item to cart so backend endpoint called to add an item, update quantity, remove the item and so on each operation hit backend
is that applicable or frontend should handle this and call cart API at some point to be persisted in the database?
thanks.
I was using react-redux/redux-persist to persist the cart data but whenever I tried to update and reload my webpage the cart returns to the version of data it was since persisted.
When you refresh the page redux data will be cleared.