diff --git a/src/app/home/content/content-header/content-header.component.html b/src/app/home/content/content-header/content-header.component.html index 599e43f6..dfdc8083 100644 --- a/src/app/home/content/content-header/content-header.component.html +++ b/src/app/home/content/content-header/content-header.component.html @@ -21,5 +21,14 @@

Showing {{productsCount}} of {{productsT
  • High
  • --> + +
    + Sort by +
    diff --git a/src/app/home/content/content-header/content-header.component.ts b/src/app/home/content/content-header/content-header.component.ts index 0c29a451..79a794ca 100644 --- a/src/app/home/content/content-header/content-header.component.ts +++ b/src/app/home/content/content-header/content-header.component.ts @@ -1,3 +1,4 @@ +import { Router } from '@angular/router'; import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core'; @Component({ @@ -11,9 +12,23 @@ export class ContentHeaderComponent implements OnInit { @Input() productsCount; @Input() productsTotal_count; + options = [ + { name: 'Newest', value: 1 }, + { name: 'A To Z', value: 2 }, + { name: 'Z To A', value: 3 } + ] + queryMap = { + Newest: 'updated_at+asc', + Relevance: '', + 'A To Z': 'ascend_by_master_price', + 'Z To A': 'name+desc', + } + + selectedOption: 'Relevance'; + selectedSize = 'COZY'; searchKeyword = '' - constructor() { } + constructor(private routernomal: Router) { } ngOnInit() { @@ -32,4 +47,12 @@ export class ContentHeaderComponent implements OnInit { return this.selectedSize === 'COMPACT'; } + sortFilter() { + const urlTree = this.routernomal.createUrlTree([], { + queryParams: { 'q[s]': this.queryMap[this.selectedOption] }, + queryParamsHandling: 'merge', + preserveFragment: true + }); + this.routernomal.navigateByUrl(urlTree); + } } diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 6f194626..c642e4d8 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -48,7 +48,6 @@ export class HomeComponent implements OnInit { products: any; isProducts = false; isFilterOn = false; - gopal = false; constructor( private store: Store, diff --git a/src/app/home/sidebar/categories/categories.component.html b/src/app/home/sidebar/categories/categories.component.html index 5fc8e56c..a9d587f7 100644 --- a/src/app/home/sidebar/categories/categories.component.html +++ b/src/app/home/sidebar/categories/categories.component.html @@ -12,6 +12,7 @@

    Catgeories

      +

      {{taxonomiList.pretty_name}}

      Catgeories

    • diff --git a/src/app/home/sidebar/categories/categories.component.ts b/src/app/home/sidebar/categories/categories.component.ts index 37bb3b11..d276d38c 100644 --- a/src/app/home/sidebar/categories/categories.component.ts +++ b/src/app/home/sidebar/categories/categories.component.ts @@ -2,7 +2,7 @@ import { ActivatedRoute } from '@angular/router'; import { AppState } from './../../../interfaces'; import { Store } from '@ngrx/store'; import { SearchActions } from './../../reducers/search.actions'; -import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core'; +import { Component, OnInit, Input, EventEmitter, Output, OnChanges } from '@angular/core'; import { URLSearchParams } from '@angular/http' import { getChildTaxons } from '../../reducers/selectors'; diff --git a/src/app/layout/header/components/header-search/header-search.component.ts b/src/app/layout/header/components/header-search/header-search.component.ts index 274cfe38..cd600219 100644 --- a/src/app/layout/header/components/header-search/header-search.component.ts +++ b/src/app/layout/header/components/header-search/header-search.component.ts @@ -39,12 +39,23 @@ export class HeaderSearchComponent implements OnInit { if (keyword !== '') { keyword = keyword.trim(); const search = new URLSearchParams(); - search.set('q[name_cont]', keyword) + search.set('q[name_cont_any]', keyword) + if ('page' in this.queryParams) { search.set('page', this.queryParams.page) } + if ('q[s]' in this.queryParams) { + search.set('q[s]', this.queryParams['q[s]']) + } this.store.dispatch(this.searchActions.getproductsByKeyword(search.toString())); - this.router.navigate(['/search'], { queryParams: { 'q[name_cont_all]': keyword, 'page': this.queryParams.page } }); + this.router.navigate( + ['/search'], { + queryParams: { + 'q[name_cont_any]': keyword, + 'page': this.queryParams.page, + 'q[s]': this.queryParams['q[s]'] + } + }); this.store.dispatch(this.searchActions.clearCategeoryLevel()); } } @@ -53,20 +64,29 @@ export class HeaderSearchComponent implements OnInit { const search = new URLSearchParams(); search.set('id', this.queryParams.id); search.set('page', this.queryParams.page) + if ('q[s]' in this.queryParams) { + search.set('q[s]', this.queryParams['q[s]']) + } this.store.dispatch(this.searchActions.getProducsByTaxon(search.toString())); } loadPage() { - if ('q[name_cont_all]' in this.queryParams && 'page' in this.queryParams) { - this.onSearch(this.queryParams['q[name_cont_all]']) - } else if ('q[name_cont_all]' in this.queryParams) { - this.onSearch(this.queryParams['q[name_cont_all]']) + if ('q[name_cont_any]' in this.queryParams && 'page' in this.queryParams) { + this.onSearch(this.queryParams['q[name_cont_any]']) + } else if ('q[name_cont_any]' in this.queryParams) { + this.onSearch(this.queryParams['q[name_cont_any]']) } if ('id' in this.queryParams && 'page' in this.queryParams) { this.catgeoryFilter() + } else if ('id' in this.queryParams && 'q[s]' in this.queryParams) { + this.catgeoryFilter() } else if ('id' in this.queryParams) { this.catgeoryFilter() } + + if ('q[s]' in this.queryParams && 'q[name_cont_any]' in this.queryParams) { + this.onSearch(this.queryParams['q[name_cont_any]']) + } } } diff --git a/src/app/layout/header/header.component.ts b/src/app/layout/header/header.component.ts index f62291b5..56e25d3e 100644 --- a/src/app/layout/header/header.component.ts +++ b/src/app/layout/header/header.component.ts @@ -104,8 +104,6 @@ export class HeaderComponent implements OnInit { this.isAuthenticated = this.store.select(getAuthStatus); this.totalCartItems = this.store.select(getTotalCartItems); this.screenwidth = window.outerWidth; - - this.test() } diff --git a/src/app/product/actions/product-actions.ts b/src/app/product/actions/product-actions.ts index f80f6dba..0b2e5cbf 100644 --- a/src/app/product/actions/product-actions.ts +++ b/src/app/product/actions/product-actions.ts @@ -12,7 +12,7 @@ export class ProductActions { static GET_ALL_TAXONOMIES_SUCCESS = 'GET_ALL_TAXONOMIES_SUCCESS'; static GET_ALL_PRODUCTS_SEARCH_SUCCESS = 'GET_ALL_PRODUCTS_SEARCH_SUCCESS'; - getAllProducts(pageNumber= 1) { + getAllProducts(pageNumber = 1) { return { type: ProductActions.GET_ALL_PRODUCTS, payload: pageNumber