11import { Component } from '@angular/core' ;
2- import { NavController , NavParams , ToastController } from 'ionic-angular' ;
3- import * as WC from 'woocommerce-api' ;
2+ import { NavController , NavParams } from 'ionic-angular' ;
43
54@Component ( {
65 selector : 'page-search' ,
@@ -9,50 +8,14 @@ import * as WC from 'woocommerce-api';
98export class SearchPage {
109
1110 searchQuery : string = "" ;
12- WooCommerce : any ;
13- products : any [ ] = [ ] ;
14- page : number = 2 ;
1511
1612 constructor ( public navCtrl : NavController , public navParams : NavParams , public toastCtrl : ToastController ) {
1713 console . log ( this . navParams . get ( "searchQuery" ) ) ;
18- this . searchQuery = this . navParams . get ( "searchQuery" ) ;
19-
20- this . WooCommerce = WC ( {
21- url : "http://samarth.cloudapp.net" ,
22- consumerKey : "ck_d6c5feec9ea1c407d2f91661c5137c6e3e48ae3b" ,
23- consumerSecret : "cs_de8e6cf03a5afd10491dfb1756415ac5a0169ae8"
24- } ) ;
25-
26- this . WooCommerce . getAsync ( "products?filter[q]=" + this . searchQuery ) . then ( ( searchData ) => {
27- this . products = JSON . parse ( searchData . body ) . products ;
28- } ) ;
29-
30-
14+
3115 }
3216
3317 ionViewDidLoad ( ) {
3418 console . log ( 'ionViewDidLoad SearchPage' ) ;
3519 }
3620
37- loadMoreProducts ( event ) {
38-
39- this . WooCommerce . getAsync ( "products?filter[q]=" + this . searchQuery + "&page=" + this . page ) . then ( ( searchData ) => {
40- this . products = this . products . concat ( JSON . parse ( searchData . body ) . products ) ;
41-
42- if ( JSON . parse ( searchData . body ) . products . length < 10 ) {
43- event . enable ( false ) ;
44-
45- this . toastCtrl . create ( {
46- message : "No more products!" ,
47- duration : 5000
48- } ) . present ( ) ;
49-
50- }
51-
52- event . complete ( ) ;
53- this . page ++ ;
54-
55- } ) ;
56- }
57-
5821}
0 commit comments