Skip to content

Commit

Permalink
Show parent catagory items
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Jan 18, 2024
1 parent d39c2cb commit 1ff88da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/app/core/components/navigation/navigation.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<div class="navigation-container">
<vcl-navigation
*ngIf="categories$ | async"
layout="horizontal"
class="row justify-content-center"
style="text-align: center"
>
<vcl-navigation-item>
<vcl-navigation-item *ngFor="let category of categories$ | async">
<vcl-navigation-label class="navigation-item">
{{ category.name }}
</vcl-navigation-label>
</vcl-navigation-item>

<!--<vcl-navigation-item >
<vcl-navigation-label class="navigation-item">
{{ "Navigation.NewIn" | translate }}
</vcl-navigation-label>
Expand All @@ -19,7 +24,8 @@
<vcl-navigation-label class="navigation-item">
{{ "Navigation.Shoes" | translate }}
</vcl-navigation-label>
</vcl-navigation-item>
</vcl-navigation-item> -->

<!--<vcl-navigation-item>
<vcl-navigation-label>
{{ 'Navigation.Accessories' | translate }}
Expand Down
5 changes: 4 additions & 1 deletion src/app/core/components/navigation/navigation.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { map } from 'rxjs';
import { ProductCategoryService } from 'src/app/features/products/services/product-category.service';

@Component({
Expand All @@ -8,7 +9,9 @@ import { ProductCategoryService } from 'src/app/features/products/services/produ
styleUrls: ['./navigation.component.scss'],
})
export class NavigationComponent {
categories$ = this.productCategoryService.category$;
categories$ = this.productCategoryService.category$.pipe(
map((cat) => cat.filter((cat) => cat.parent === null))
);

constructor(
private router: Router,
Expand Down
20 changes: 14 additions & 6 deletions src/app/features/products/services/product-category.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { catchError, of, tap } from 'rxjs';
import { catchError, map, of, tap } from 'rxjs';
import {
IoRestorecommerceProductCategoryProductCategory,
IoRestorecommerceResourcebaseFilterOperation,
IoRestorecommerceResourcebaseFilterOpOperator,
ProductCategoryQueryGQL,
Expand All @@ -24,18 +25,25 @@ export class ProductCategoryService {
operation: IoRestorecommerceResourcebaseFilterOperation.In,
value: 'r-ug',
},
{
field: 'parent.parent_id',
value: '',
operation: IoRestorecommerceResourcebaseFilterOperation.Eq,
},
// Parent items are items with parent as null: The filter for this doesn't work.
// {
// field: 'parent.parent_id',
// value: '',
// operation: IoRestorecommerceResourcebaseFilterOperation.Eq,
// },
],
operator: IoRestorecommerceResourcebaseFilterOpOperator.And,
},
],
},
})
.pipe(
map((response) =>
response.data.catalog.product_category.Read.details.items.map(
(item) =>
item.payload as IoRestorecommerceProductCategoryProductCategory
)
),
tap((data) => console.log('category data', data)),
catchError((err) => {
console.log('Error:', err);
Expand Down

0 comments on commit 1ff88da

Please sign in to comment.