diff --git a/checkout/src/arquivos/js/components/Footer.js b/checkout/src/arquivos/js/components/Footer.js
index 219a3ca..fa29cea 100644
--- a/checkout/src/arquivos/js/components/Footer.js
+++ b/checkout/src/arquivos/js/components/Footer.js
@@ -3,57 +3,75 @@ import { waitElement } from "m3-utils";
export default class Footer {
constructor() {
this.init();
- this.requestShelf();
- this.addCarrossel();
+
}
async init() {
+ this.list = await this.requestApi();
await this.selectors();
// this.onUpdate();
- this.requestShelf();
+ this.createShelf();
+ this.shelfList = await waitElement(".footerCheckout__shelfList");
+ this.shelfItens();
+
+
+
this.addCarrossel();
}
async selectors() {
this.itensShelf = await waitElement(".footerCheckout__prateleira", {
- timeout: 5000,
- interval: 1000})
- // this.itensShelf = await waitElement(".empty-cart-content")
- //Para verificar se o carrinho está vazio e remover a prateleira de produtos:
- // vocês devem olhar a doc fornecida no Desafio para aprender a usar o waitElement
- // this.checkoutVazio = await waitElement(".container-cart", {
-
- // });
- }
-
- requestShelf() {
- let prateleira= this.itensShelf;
- prateleira.innerHTML = `
-
-
- `;
- const api = "https://m3academy.myvtex.com/api/catalog_system/pub/products/search/?fq=productClusterIds:319";
- const prodUl = document.querySelector("carrosel-ul")
- fetch(api)
- .then((response) => response.json())
- .then(function(data) {
- return data.map(function(item) {
- let li = document.createElement("li")
- li.setAttribute("id", item.productId)
- li.innerHTML = `
-
- ${item.productName}
- ${item.items.map((name) => {
- return `
${name.name}`
-
- }).join("")}
-
- `;
- prateleira.children[1].appendChild(li);
- });
+ timeout: 5000,
+ interval: 1000,
});
}
+ createShelf() {
+ if(this.itensShelf) {
+ this.itensShelf.innerHTML = `
+
+
+ `
+ }
+ }
+
+ async shelfItens() {
+ let structure = "";
+
+ this.list.forEach((response) => {
+ const sku = response.skus.map((item) => `${item}`);
+
+ structure += `
+
+
+ ${response.name}
+
+
+
+ `
+ })
+ this.shelfList.innerHTML = structure
+ }
+
+ async requestApi() {
+ const api =
+ "https://m3academy.myvtex.com/api/catalog_system/pub/products/search/?fq=productClusterIds:319";
+ return fetch(api)
+ .then((response) => response.json())
+ .then((data) => {
+ const prodInfo = data.map((response) => ({
+ name: response.productName,
+ skus: response.items.map((item) => item.name),
+ img: response.items[0].images[0].imageUrl,
+ link: response.link,
+ }));
+ return prodInfo
+ });
+ }
+
+
onUpdate() {
//Função qeu fará a verificação se o carrinho está vazio para remover a prateleira de produtos:
// vocês devem olhar a doc fornecida no Desafio para aprender a usar a MutationObserver
@@ -69,12 +87,11 @@ export default class Footer {
observer.observe(target, config);
}
async addCarrossel() {
- const elemento = await waitElement(".carrosel-ul");
+ const elemento = await waitElement(".footerCheckout__shelfList");
$(elemento).slick({
slidesToShow: 4,
slidesToScroll: 1,
arrows: true,
- variableWidth: true,
infinite: false,
});
}