1、how local cart implemented
Because the ShoppingCart part needs to store information locally, this is now done with the local database Realm,
This is its docment https://docs.mongodb.com/realm/sdk/react-native/
This is the database structure, which you can find under the db folder under the project
2、local cart refresh - checking product avaialbility
Since we store the product information locally, we need to check whether the local product is still available when the server inventory and whether it is on the shelves are changed
The following method is called when we open the shopping cart page
const [queryAvailble, { data: availbleList }] = useLazyQuery(
IsListingAvailable,
{
variables: { listings: isAvailableList },
}
);
useEffect(() => {
if (isAvailableList.length > 0) {
queryAvailble();
}
}, [isAvailableList, queryAvailble]);
3、guest user and register buyer id and delivery address id
You can get buyerid directly by using global.buyerId
, no matter a registerd buyer or a guest user
You can get delivery address id from apollo cache
const {
data: { localCartVar },
} = useQuery(GET_LOCAL_CART);
then use localCartVar.deliverAddress
4、prepare list of data to send to back end for oder creation
you must get local shoppingcart info then call the checkout-related api
网友评论