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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { deleteShopData } from 'src/app/shared/ngrx/e-commerce/shop.action';
import { ShopService } from 'src/app/shared/services/e-commerce/shop.service';
@Component({
selector: 'app-cart',
templateUrl: './cart.component.html',
styleUrls: ['./cart.component.scss'],
})
export class CartComponent {
delectOutData: any;
constructor(public ShopService: ShopService, private store: Store<any>) {
this.price();
}
ngOnInit(): void {}
input1 = 1;
input2 = 1;
input3 = 1;
input4 = 1;
input5 = 1;
counter = 0;
decrease(id: string) {
this.ShopService.decreaseQuantity(id);
}
plus = (id: string) => {
this.ShopService.addingQuantity(id);
};
data$ = this.store.select('data');
totalMoney: any = 0;
totalLength = 1;
delectFunction = false;
getdelectData: any;
price() {
this.data$.forEach((item) => {
this.totalLength = item.length;
if (item.length > 1) {
for (const i of item) {
this.totalMoney = this.totalMoney + i.offer_price;
}
} else {
if (item[0]?.offer_price != undefined) {
this.totalMoney = item[0].offer_price;
}
}
if (this.delectFunction) {
this.totalMoney = 0;
this.delectFunction = false;
}
});
}
ngAfterViewInit() {
const plus: any = document.querySelectorAll('.plus');
const minus: any = document.querySelectorAll('.minus');
function perfectChart() {
plus.forEach((element: any) => {
const parentDiv = element.parentElement.parentElement;
element.addEventListener('click', () => {
parentDiv.children[0].children[1].value++;
});
});
minus.forEach((element: any) => {
const parentDiv = element.parentElement.parentElement;
element.addEventListener('click', () => {
if (parentDiv.children[0].children[1].value > 0) {
parentDiv.children[0].children[1].value--;
}
});
});
}
perfectChart();
}
delete(id: string) {
if (confirm('Are you sure you want to delete this item?')) {
this.delectFunction = true;
this.store.dispatch(deleteShopData({ id }));
let delectOutData;
this.data$.forEach((item) => {
delectOutData = item;
});
this.getdelectData = this.delectOutData?.filter((x: { id: string }) => {
return id != x.id;
});
this.totalMoney = 0;
}
}
}