I’m trying to use the WooCommerce API to retrieve a list of products for my Ionic APP, and I’ve created a provider for that purpose, which contains the following code:
import { Injectable } from '@angular/core';
import * as WC from 'woocommerce-api';
@Injectable()
export class WooCommerceProvider {
Woocommerce: any;
WoocommerceV2 : any;
constructor() {
this.Woocommerce = WC({
url: 'https://colorvet.ro/wp-json/wc/v1/products',
consumerKey: 'xxxxxxxxxxxxxxxx',
consumerSecret: 'xxxxxxxxxxxxx',
wpAPI: true, // Enable the WP REST API integration
queryStringAuth: true,
verifySsl: true,
version: 'wc/v2' // WooCommerce WP REST API version
});
}
init(){
return new Promise((resolve, reject) => {
this.Woocommerce;
});
}
}
I’ve replaced the consumer key and secret with my own. The following is the page where I try to receive the list of products:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
import * as WC from 'woocommerce-api';
import { WooCommerceProvider } from '../providers/woo-commerce/woo-commerce';
/**
* Generated class for the ShopPage page.
*
* See http://ionicframework.com/docs/components/#navigation for more info
* on Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-shop',
templateUrl: 'shop.html',
})
export class ShopPage {
produse: any[];
WooCommerce: any;
constructor(public navCtrl: NavController, public navParams: NavParams,
private alertCtrl: AlertController,private wooProvider: WooCommerceProvider ) {
this.WooCommerce = wooProvider.WooCommerce;
this.WooCommerce.getAsync("products").then((searchData) => {
this.produse = JSON.parse(searchData.body).products;
});
}
I get the following error : [ts] Cannot use namespace ‘WooCommerceProvider’ as a type.