Skip to content

Commit

Permalink
Sección 20 Clase 10 - Terminada sección - Últimando detalles con la s…
Browse files Browse the repository at this point in the history
…incronización del carrito de compra
  • Loading branch information
mugan86 committed Jun 20, 2020
1 parent f95a293 commit 9c0642d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="container mt-4">
<div class="container mt-4" *ngIf="meData">
<div class="row">
<div class="col-md-4 order-md-2 mb-4">
<app-checkout-resume></app-checkout-resume>
Expand Down
17 changes: 17 additions & 0 deletions src/app/@public/pages/games/details/details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ActivatedRoute } from '@angular/router';
import { loadData, closeAlert } from '@shared/alerts/alerts';
import { CURRENCY_SELECT } from '@core/constants/config';
import { CartService } from '@shop/core/services/cart.service.ts.service';
import { ICart } from '@shop/core/components/shopping-cart/shoppin-cart.interface';
@Component({
selector: 'app-details',
templateUrl: './details.component.html',
Expand All @@ -30,12 +31,28 @@ export class DetailsComponent implements OnInit {
this.loading = true;
this.loadDataValue(+params.id);
});

this.cartService.itemsVar$.subscribe((data: ICart) => {
console.log(data);
if (data.subtotal === 0) {
this.product.qty = 1;
return;
}

this.product.qty = this.findProduct(+this.product.id).qty;
});
}

findProduct(id: number) {
return this.cartService.cart.products.find( item => +item.id === id);
}

loadDataValue(id: number) {
this.productService.getItem(id).subscribe((result) => {
console.log(result);
this.product = result.product;
const saveProductInCart = this.findProduct(+this.product.id);
this.product.qty = (saveProductInCart !== undefined) ? saveProductInCart.qty : this.product.qty;
this.selectImage = this.product.img;
this.screens = result.screens;
this.relationalProducts = result.relational;
Expand Down

0 comments on commit 9c0642d

Please sign in to comment.