-
Notifications
You must be signed in to change notification settings - Fork 894
18l Solution #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18l
Are you sure you want to change the base?
18l Solution #113
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import {getProduct, loadProductsFetch} from '../data/products.js'; | ||
| import {orders} from '../data/orders.js'; | ||
| import dayjs from 'https://unpkg.com/dayjs@1.11.10/esm/index.js'; | ||
| import formatCurrency from './utils/money.js'; | ||
|
|
||
| async function loadPage() { | ||
| await loadProductsFetch(); | ||
|
|
||
| let ordersHTML = ''; | ||
|
|
||
| orders.forEach((order) => { | ||
| const orderTimeString = dayjs(order.orderTime).format('MMMM D'); | ||
|
|
||
| ordersHTML += ` | ||
| <div class="order-container"> | ||
| <div class="order-header"> | ||
| <div class="order-header-left-section"> | ||
| <div class="order-date"> | ||
| <div class="order-header-label">Order Placed:</div> | ||
| <div>${orderTimeString}</div> | ||
| </div> | ||
| <div class="order-total"> | ||
| <div class="order-header-label">Total:</div> | ||
| <div>$${formatCurrency(order.totalCostCents)}</div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="order-header-right-section"> | ||
| <div class="order-header-label">Order ID:</div> | ||
| <div>${order.id}</div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="order-details-grid"> | ||
| ${productsListHTML(order)} | ||
| </div> | ||
| </div> | ||
| `; | ||
| }); | ||
|
|
||
| function productsListHTML(order) { | ||
| let productsListHTML = ''; | ||
|
|
||
| order.products.forEach((productDetails) => { | ||
| const product = getProduct(productDetails.productId); | ||
|
|
||
| productsListHTML += ` | ||
| <div class="product-image-container"> | ||
| <img src="${product.image}"> | ||
| </div> | ||
|
|
||
| <div class="product-details"> | ||
| <div class="product-name"> | ||
| ${product.name} | ||
| </div> | ||
| <div class="product-delivery-date"> | ||
| Arriving on: ${ | ||
| dayjs(productDetails.estimatedDeliveryTime).format('MMMM D') | ||
| } | ||
| </div> | ||
| <div class="product-quantity"> | ||
| Quantity: ${productDetails.quantity} | ||
| </div> | ||
| <button class="buy-again-button button-primary"> | ||
| <img class="buy-again-icon" src="images/icons/buy-again.png"> | ||
| <span class="buy-again-message">Buy it again</span> | ||
| </button> | ||
| </div> | ||
|
|
||
| <div class="product-actions"> | ||
| <a href="tracking.html?orderId=${order.id}&productId=${product.id}"> | ||
| <button class="track-package-button button-secondary"> | ||
| Track package | ||
| </button> | ||
| </a> | ||
| </div> | ||
| `; | ||
| }); | ||
|
|
||
| return productsListHTML; | ||
| } | ||
|
|
||
| document.querySelector('.js-orders-grid').innerHTML = ordersHTML; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we used cart-class.js in our project how can we send the cart to the backend from local Storage? I've tried this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that might be because you have not imported cart onto scripts/order.js There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to import the cart in scripts/order.js, because here we have to work with the data received from the backend. When Simon makes a POST request to the backend, doesn't import the cart in that file . I think the data that I send to the backend is wrong. 🙃 🫣😬 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have private key for local Storage. Could this be a problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the 'cart' was imported, check files you've imported. is the product in the cart (stored), that he used to fetched data from the backend. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in paymentSummary.js file, where we add event listener to the button, not in scripts/orders.js. In this file we retrieve the data from backend and render the orders.html file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't really get you, document.querySelector('.js-place-order') }); but to make a 'POST' we must give the backend data which we want from it, this is the data, body: JSON.stringify( cart: cart }) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Troubleshooting Cart Submission IssueI encountered a similar issue while working with Example of Correct
|
||
| } | ||
|
|
||
| loadPage(); | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use more modular structure: