Open phillipsja97 opened 4 years ago
if a cart exists, clicking add to cart on the product modal will add to the cart
if a cart does not exist, clicking add to cart on the product will create a new cart with quantity, price,
display the cart and add to the cart
DevStory
UserStory
AC
WHEN a user clicks on the add cart button THEN the item will be added to the cart AND as a user WHEN I click on the cart page THEN I should be lead to the page where I can view items in my cart, and checkout options.
DevNotes
IN EAST & BARLEY API:
[x] Create a method in the controller to get Open Cart by userId:
IN EAST & BARLEY.UI
cartData.js
folder in the data folder of Helpers.cartData.js
create a function to getLineItemsByInvoiceId();const getLineItemsByInvoiceId = (invoiceId) => new Promise((resolve, reject) => { axios.get(
https://localhost:44319/api/invoices/lineitems/${invoiceId}
) .then((result) => resolve(result.data)) .catch((error) => reject(error)); });export default { getLineItemsByInvoiceId };
const addToExistingOrNewCart = (product) => axios.post(
axios.get('https://localhost:44319/api/invoices/newCart/${userId}
), newOrder);const checkForCart = (userId) => new Promise((resolve, reject) => { axios.get(
https://localhost:44319/api/invoice/openCart/${userId}
) .then((result) => resolve(result.data)) .catch((error) => reject(error)); });state = { openCart: [ ], lineItems: [ ], }
componentDidMount() { const checkForOpenCart = () => { const { user } = this.props; cartData.checkForCart(user.userId) .then((openCart) => { this.setState({ openCart }); }); }; }
.then((invoice) => cartData.getLineItemsByInvoiceId(openCart.invoiceId) .then((lineItems) => { this.setState({ lineItems: lineItems }); }) .catch((errorFromCart) => console.error(errorFromCart)); }