Skip to content

Commit d39c2cb

Browse files
committed
Add product category service and its filter
1 parent f73360e commit d39c2cb

13 files changed

+72
-13
lines changed

src/app/core/components/navigation/navigation.component.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<div class="navigation-container">
2-
<vcl-navigation layout="horizontal" class="row justify-content-center" style="text-align: center;">
2+
<vcl-navigation
3+
*ngIf="categories$ | async"
4+
layout="horizontal"
5+
class="row justify-content-center"
6+
style="text-align: center"
7+
>
38
<vcl-navigation-item>
49
<vcl-navigation-label class="navigation-item">
5-
{{ 'Navigation.NewIn' | translate }}
10+
{{ "Navigation.NewIn" | translate }}
611
</vcl-navigation-label>
712
</vcl-navigation-item>
813
<vcl-navigation-item>
914
<vcl-navigation-label class="navigation-item">
10-
{{ 'Navigation.Clothing' | translate }}
15+
{{ "Navigation.Clothing" | translate }}
1116
</vcl-navigation-label>
1217
</vcl-navigation-item>
1318
<vcl-navigation-item (click)="this.navigate('/shoes')">
1419
<vcl-navigation-label class="navigation-item">
15-
{{ 'Navigation.Shoes' | translate }}
20+
{{ "Navigation.Shoes" | translate }}
1621
</vcl-navigation-label>
1722
</vcl-navigation-item>
1823
<!--<vcl-navigation-item>
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { Component } from '@angular/core';
22
import { Router } from '@angular/router';
3+
import { ProductCategoryService } from 'src/app/features/products/services/product-category.service';
34

45
@Component({
56
selector: 'app-navigation',
67
templateUrl: './navigation.component.html',
78
styleUrls: ['./navigation.component.scss'],
89
})
910
export class NavigationComponent {
10-
constructor(private router: Router) {}
11+
categories$ = this.productCategoryService.category$;
1112

12-
public navigate(value: string): void {
13+
constructor(
14+
private router: Router,
15+
private productCategoryService: ProductCategoryService
16+
) {}
17+
18+
navigate(value: string): void {
1319
this.router.navigateByUrl(value);
1420
}
1521
}

src/app/features/products/components/products/products.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Router } from '@angular/router';
33
import { IoRestorecommerceProductProduct } from 'src/app/generated/graphql';
44

55
@Component({
6-
selector: 'products',
6+
selector: 'app-products',
77
templateUrl: './products.component.html',
88
styleUrls: ['./products.component.scss']
99
})
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
<products [pageTitle]="pageTitle" [currency]="currency" [products]=" products$ | async"></products>
1+
<app-products
2+
[pageTitle]="pageTitle"
3+
[currency]="currency"
4+
[products]="products$ | async"
5+
></app-products>

src/app/features/products/products.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { ProductCardComponent } from './components/product-card/product-card.com
1010
import { ProductColorPickerComponent } from './components/product-color-picker/product-color-picker.component';
1111
import { ProductInterestComponent } from './components/product-interest/product-interest.component';
1212
import { ProductDescriptionComponent } from './components/product-description/product-description.component';
13-
import { ProductInfoComponent } from './components/product-main/product-info/product-info.component';
14-
import { ProductGalleryComponent } from './components/product-main/product-gallery/product-gallery.component';
13+
import { ProductInfoComponent } from './components/product-info/product-info.component';
14+
import { ProductGalleryComponent } from './components/product-gallery/product-gallery.component';
1515
import { ProductNavigationComponent } from './components/product-navigation/product-navigation.component';
1616
import { ProductMainComponent } from './components/product-main/product-main.component';
1717
import { ProductRecommendComponent } from './components/product-recommend/product-recommend.component';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Injectable } from '@angular/core';
2+
import { catchError, of, tap } from 'rxjs';
3+
import {
4+
IoRestorecommerceResourcebaseFilterOperation,
5+
IoRestorecommerceResourcebaseFilterOpOperator,
6+
ProductCategoryQueryGQL,
7+
} from 'src/app/generated/graphql';
8+
9+
@Injectable({
10+
providedIn: 'root',
11+
})
12+
export class ProductCategoryService {
13+
constructor(private categoryGQL: ProductCategoryQueryGQL) {}
14+
15+
category$ = this.categoryGQL
16+
.fetch({
17+
input: {
18+
filters: [
19+
{
20+
// TODO Refactor this code as In-house boilerplate code.
21+
filters: [
22+
{
23+
field: 'meta.owners[*].attributes[0].value',
24+
operation: IoRestorecommerceResourcebaseFilterOperation.In,
25+
value: 'r-ug',
26+
},
27+
{
28+
field: 'parent.parent_id',
29+
value: '',
30+
operation: IoRestorecommerceResourcebaseFilterOperation.Eq,
31+
},
32+
],
33+
operator: IoRestorecommerceResourcebaseFilterOpOperator.And,
34+
},
35+
],
36+
},
37+
})
38+
.pipe(
39+
tap((data) => console.log('category data', data)),
40+
catchError((err) => {
41+
console.log('Error:', err);
42+
return of(null);
43+
})
44+
);
45+
}

src/app/features/products/services/product.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, EventEmitter } from '@angular/core';
1+
import { Injectable } from '@angular/core';
22

33
import { map, catchError, of, tap } from 'rxjs';
44
import {
@@ -7,12 +7,11 @@ import {
77
ProductsQueryGQL,
88
} from '../../../generated/graphql';
99

10+
1011
@Injectable({
1112
providedIn: 'root',
1213
})
1314
export class ProductService {
14-
productColorChanged = new EventEmitter<string>();
15-
1615
constructor(private productGQL: ProductsQueryGQL) {}
1716

1817
products$ = this.productGQL

0 commit comments

Comments
 (0)