import { Component, OnInit, Input } from '@angular/core'; @Component({ selector: 'app-compact-view', templateUrl: './compact-view.component.html', styleUrls: ['./compact-view.component.css'], }) export class CompactViewComponent implements OnInit { @Input() products = []; @Input() variantsSeparated: boolean = false; constructor() {} ngOnInit(): void {} updatedProduct(updatedProductId: number) { let itemsInCart = JSON.parse(localStorage.getItem('cartItems')); let foundItems = itemsInCart.filter(cartItem => cartItem.item_id === updatedProductId) this.products.filter(product => { if( product.item_id == updatedProductId && product.variants.find(variant => { if(variant.is_default && foundItems.find(cartItem => { if(cartItem.variant_id === variant.variant_id){ product.numberOfCartItems = cartItem.numItems; return true; } else { product.numberOfCartItems = 0; } })) { return true; } })){ return true; }} ); this.products = JSON.parse(JSON.stringify(this.products)); } }