Skip to content

Commit f95ead4

Browse files
authored
Merge pull request #12 from imranhsayed/fix/build
Fix build
2 parents dcc2401 + 34a84b3 commit f95ead4

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pages/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { GET_PRODUCTS_ENDPOINT, HEADER_FOOTER_ENDPOINT } from '../src/utils/cons
1010
* External Dependencies.
1111
*/
1212
import axios from 'axios';
13+
import { getProductsData } from '../src/utils/products';
1314

1415
export default function Home({ headerFooter, products }) {
1516

@@ -30,12 +31,12 @@ export default function Home({ headerFooter, products }) {
3031
export async function getStaticProps() {
3132

3233
const { data: headerFooterData } = await axios.get( HEADER_FOOTER_ENDPOINT );
33-
const { data: productsData } = await axios.get( GET_PRODUCTS_ENDPOINT );
34+
const { data: products } = await getProductsData();
3435

3536
return {
3637
props: {
3738
headerFooter: headerFooterData?.data ?? {},
38-
products: productsData?.products ?? {}
39+
products: products ?? {}
3940
},
4041

4142
/**

src/utils/products.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const WooCommerceRestApi = require( '@woocommerce/woocommerce-rest-api' ).default;
2+
3+
const api = new WooCommerceRestApi( {
4+
url: process.env.NEXT_PUBLIC_WORDPRESS_SITE_URL,
5+
consumerKey: process.env.WC_CONSUMER_KEY,
6+
consumerSecret: process.env.WC_CONSUMER_SECRET,
7+
version: 'wc/v3',
8+
} );
9+
10+
/**
11+
* Get Products.
12+
*
13+
* @return {Promise<void>}
14+
*/
15+
export const getProductsData = async ( perPage ) => {
16+
return await api.get(
17+
'products',
18+
{
19+
per_page: perPage || 50,
20+
},
21+
);
22+
};

0 commit comments

Comments
 (0)