https://github.com/michaeldoye/ng2woo
Very simple Angular2+ wrapper for the WooCommerce API
https://github.com/michaeldoye/ng2woo
angular woocommerce-api
Last synced: 12 months ago
JSON representation
Very simple Angular2+ wrapper for the WooCommerce API
- Host: GitHub
- URL: https://github.com/michaeldoye/ng2woo
- Owner: michaeldoye
- Created: 2017-04-21T16:57:21.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-22T12:09:48.000Z (almost 9 years ago)
- Last Synced: 2025-04-22T21:07:00.762Z (12 months ago)
- Topics: angular, woocommerce-api
- Language: TypeScript
- Homepage:
- Size: 18.6 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# ng2woo
Very simple Angular2+ wrapper for the WooCommerce API
[](https://badge.fury.io/gh/michaeldoye%2FWaNG)
[](https://david-dm.org/michaeldoye/WaNG)
[](https://github.com/michaeldoye/woo-wrapper/WaNG)
[](https://discord.gg/xyUdZKh)
## Usage
Import ng2woo in any Angular application by running:
```bash
$ npm install --save ng2woo
```
Install the WooCommerce API:
```bash
$ npm install --save woocommerce-api
```
You will need to get the [WooCommerce credentials](https://woocommerce.github.io/woocommerce-rest-api-docs/#rest-api-keys) from your WooCommerce website.
Then from your Angular `AppModule`:
```typescript
...
// Import ng2woo
import { WooApiModule, WooApiService } from 'ng2woo';
// Add your WooCommerce Credentials
const WooCommerceConfig = {
url: 'your_site_url',
consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
wpAPI: true,
version: 'wc/v1'
};
@NgModule({
declarations: [ ... ],
imports: [
...
// Specify as an import and pass in your config
WooApiModule.forRoot(WooCommerceConfig)
],
// Add the Api service
providers: [ WooApiService ]
})
export class AppModule { }
```
Once ng2woo is imported, you can use the `WooApiService` in your components/services:
```typescript
import { Component, OnInit } from '@angular/core';
// Import the service
import { WooApiService } from 'ng2woo';
@Component({...})
export class HomePage implements OnInit {
products: any;
// Inject the service
constructor(private woo: WooApiService) { }
ngOnInit(): void {
// Fetch all products
this.woo.fetchItems('products')
.then(products => console.log(products));
}
}
```
## Methods
### `fetchItems(itemType)`
- Accepts: `string` (_required_) - the type of WooCommerce item you want to fetch (_products, orders, customers, categories_). Accepts query parameters, see the [WooCommerce Api docs](https://woocommerce.github.io/woocommerce-rest-api-docs) for a full list of query parameters.
- Returns: `Promise`
**Examples**
```typescript
this.woo.fetchItems('products')
.then(products => console.log(products))
.catch(error => console.log(error));
```
## Development
To generate all `*.js`, `*.js.map` and `*.d.ts` files:
```bash
$ npm run tsc
```
To lint all `*.ts` files:
```bash
$ npm run lint
```
## License
MIT © [Michael Doye](mailto:michaeldoye[@]gmail.com)