-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignCardData.js
35 lines (27 loc) · 1.05 KB
/
assignCardData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import CardOperations from './CardOperations.js';
export function assignCardData(product) {
const cardOps = CardOperations();
const img = document.getElementById('imagecart');
const title = document.getElementById('titlecart');
const descrip = document.getElementById('descriptioncart');
const rate = document.getElementById('ratingcart');
const price = document.getElementById('pricecart');
img.src = product.img;
title.innerHTML = product.title;
descrip.innerHTML = product.description;
rate.innerHTML = `rating: ${product.rating}`;
price.innerHTML = `$${product.price}`;
const obj = {
id:product.id,
img:product.img,
title:product.title,
desc:product.description,
rating:product.rating,
price:product.price,
quant:cardOps.getFinalNum(),
reviews:product.reviews
}
let products = JSON.parse(localStorage.getItem('products')) || [];
products.push(obj);
localStorage.setItem('products', JSON.stringify(products));
}