Git Product home page Git Product logo

w3bdesign / nextjs-woocommerce Goto Github PK

View Code? Open in Web Editor NEW
448.0 6.0 110.0 8.73 MB

๐Ÿ”ฅ Next.js (React) headless eCommerce site with Typescript, WordPress (WooCommerce) backend and Algolia search

Home Page: https://next-woocommerce.dfweb.no

License: GNU General Public License v3.0

JavaScript 3.37% CSS 0.63% TypeScript 96.00%
nextjs react es6 woocommerce-api woocommerce graphql ecommerce-site wp-graphql algolia-search algolia

nextjs-woocommerce's Introduction

Playwright Tests Codacy Badge CodeFactor Quality Gate Status

Screenshot 1

Star History

Star History Chart

Next.js Ecommerce site with WooCommerce backend

Table Of Contents (TOC)

Installation

  1. Install and activate the following required plugins, in your WordPress plugin directory:

Optional plugin:

The current release has been tested and is confirmed working with the following versions:

  • WordPress version 6.3.2
  • WooCommerce version 7.4.0
  • WP GraphQL version 1.13.8
  • WooGraphQL version 0.12.0
  • WPGraphQL CORS version 2.1
  1. For debugging and testing, install either:

    https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/ (Firefox)

    https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm (Chrome)

  2. Make sure WooCommerce has some products already

  3. Clone or fork the repo and modify .env.example and rename it to .env

    Then set the environment variables accordingly in Vercel or your preferred hosting solution.

    See https://vercel.com/docs/environment-variables

  4. Modify the values according to your setup

  5. Start the server with npm run dev

  6. Enable COD (Cash On Demand) payment method in WooCommerce

  7. Add a product to the cart

  8. Proceed to checkout (Gรฅ til kasse)

  9. Fill in your details and place the order

Features

  • Next.js version 13.5.3
  • React 18
  • Typescript
  • Tests with Playwright
  • Connect to Woocommerce GraphQL API and list name, price and display image for products
  • Support for simple products and variable products
  • Cart handling and checkout with WooCommerce (Cash On Delivery only for now)
  • Algolia search (requires algolia-woo-indexer)
  • Meets WCAG accessibility standards where possible
  • Placeholder for products without images
  • Apollo Client with GraphQL
  • React Hook Form
  • Native HTML5 form validation
  • Animations with Framer motion, Styled components and Animate.css
  • Loading spinner created with Styled Components
  • Shows page load progress with Nprogress during navigation
  • Fully responsive design
  • Category and product listings
  • Show stock status
  • Pretty URLs with builtin Nextjs functionality
  • Tailwind 3 for styling
  • JSDoc comments

Troubleshooting

I am getting a cart undefined error or other GraphQL errors

Check that you are using the 0.12.0 version of the wp-graphql-woocommerce plugin

The products page isn't loading

Check the attributes of the products. Right now the application requires Size and Color.

Issues

Overall the application is working as intended, but it has not been tested extensively in a production environment. More testing and debugging is required before deploying it in a production environment.

With that said, keep the following in mind:

  • Currently only simple products and variable products work without any issues. Other product types are not known to work.
  • Only Cash On Delivery (COD) is currently supported. More payment methods may be added later.

TODO

  • Add total to cart/checkout page
  • Copy billing address to shipping address
  • Add order dashboard and require login
  • Hide products not in stock
  • Add better SEO
  • Re-add Next/image when it is working better

nextjs-woocommerce's People

Contributors

codacy-badger avatar code-factor avatar dependabot-preview[bot] avatar dependabot[bot] avatar imgbotapp avatar lgtm-migrator avatar mrbrianevans avatar renovate-bot avatar renovate[bot] avatar w3bdesign avatar zaxoavoki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nextjs-woocommerce's Issues

Graphql Error

ApolloError: Cannot query field "allPaColors" on type "VariableProduct".
Cannot query field "allPaSizes" on type "VariableProduct"

Footer

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Use CoCart to complete project

I think you will be able to complete this project with the help of my plugin CoCart specially with the session handling. Let me know if you have any questions.

Todo

  • Token structure (do not use object)
  • Margin bottom mobile

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm react-instantsearch-dom Unavailable

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql.yml
  • actions/checkout v4
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
.github/workflows/playwright.yml
  • actions/checkout v4
  • actions/setup-node v4
  • actions/upload-artifact v4
npm
package.json
  • @apollo/client ^3.10.5
  • @types/react ^18.3.3
  • algoliasearch ^4.23.3
  • autoprefixer ^10.4.19
  • framer-motion 11.2.11
  • graphql ^16.8.2
  • lodash ^4.17.21
  • next ^14.2.4
  • nprogress ^0.2.0
  • postcss ^8.4.38
  • react ^18.3.1
  • react-dom ^18.3.1
  • react-hook-form ^7.52.0
  • react-instantsearch-dom ^6.40.4
  • uuid ^9.0.1
  • @playwright/test ^1.44.1
  • @types/lodash ^4.17.5
  • @types/node 20.14.7
  • @types/nprogress ^0.2.3
  • @types/react-instantsearch-dom ^6.12.7
  • @types/uuid ^9.0.8
  • @typescript-eslint/eslint-plugin ^7.13.1
  • @typescript-eslint/parser ^7.13.1
  • babel-plugin-styled-components ^2.1.4
  • eslint ^8.57.0
  • eslint-config-next ^14.2.4
  • postcss-preset-env ^9.5.14
  • prettier ^3.3.2
  • tailwindcss ^3.4.4
  • typescript ^5.5.2

  • Check this box to trigger a request for Renovate to run again on this repository

Issue when npm run dev

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'dev'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle [email protected]predev: [email protected]
6 info lifecycle [email protected]
dev: [email protected]
7 verbose lifecycle [email protected]dev: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]
dev: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\felix\Downloads\nextjs-woocommerce-master\node_modules.bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Users\felix\AppData\Roaming\npm;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\libnvvp;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\QuickTime\QTSystem;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.5.0;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\PuTTY;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Apache24\bin;C:\Program Files\dotnet;C:\xampp\php;C:\composer;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\nodejs;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\Git\cmd;C:\Users\felix\AppData\Local\Programs\Python\Python38-32\Scripts;C:\Users\felix\AppData\Local\Programs\Python\Python38-32;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\felix\AppData\Local\Microsoft\WindowsApps;C:\Users\felix\AppData\Local\GitHubDesktop\bin;C:\Users\felix\AppData\Local\atom\bin;C:\Users\felix.dotnet\tools;C:\Users\felix\AppData\Roaming\Composer\vendor\bin;C:\Users\felix\AppData\Local\Microsoft\WindowsApps;C:\Users\felix\AppData\Local\Programs\Microsoft VS Code\bin
9 verbose lifecycle [email protected]dev: CWD: C:\Users\felix\Downloads\nextjs-woocommerce-master
10 silly lifecycle [email protected]
dev: Args: [ '/d /s /c', 'next dev' ]
11 silly lifecycle [email protected]dev: Returned: code: 1 signal: null
12 info lifecycle [email protected]
dev: Failed to exec dev script
13 verbose stack Error: [email protected] dev: next dev
13 verbose stack Exit status 1
13 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:376:20)
13 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:376:20)
13 verbose stack at maybeClose (internal/child_process.js:1055:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\Users\felix\Downloads\nextjs-woocommerce-master
16 verbose Windows_NT 10.0.19045
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "dev"
18 verbose node v14.17.0
19 verbose npm v6.14.13
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] dev: next dev
22 error Exit status 1
23 error Failed at the [email protected] dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Token expiration

When we add a product to the cart, and visit the store a week later or so, we get a token expiration error.

The fix for this is to manually clear the local storage, which is not ideal.

Apollo look like limited the JSON result?

I used this query to fetch all product from my store:

query MyQuery { products(first: 1000) { nodes { id image { sourceUrl } name onSale productCategories { nodes { slug } } productTags { nodes { slug } } sku status totalSales type visibleProducts { nodes { slug isRestricted } } ... on VariableProduct { manageStock onSale price(format: RAW) regularPrice(format: RAW) salePrice(format: RAW) soldIndividually weight width } ... on ExternalProduct { onSale price(format: RAW) regularPrice(format: RAW) salePrice(format: RAW) } ... on SimpleProduct { price(format: RAW) regularPrice(format: RAW) salePrice(format: RAW) virtual weight width } } } }

But, I received the error:

ApolloError: Response not successful: Received status code 500 at new ApolloError (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/errors/errors.cjs.js:31:28) at /Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/core/core.cjs.js:1490:19 at /Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/utilities/utilities.cjs.js:958:69 at new Promise (<anonymous>) at Object.error (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/utilities/utilities.cjs.js:958:21) at notifySubscription (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/zen-observable/lib/Observable.js:140:18) at onNotify (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/zen-observable/lib/Observable.js:179:3) at SubscriptionObserver.error (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/zen-observable/lib/Observable.js:240:7) at /Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/utilities/utilities.cjs.js:946:68 at Array.forEach (<anonymous>) at iterateObserversSafely (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/utilities/utilities.cjs.js:946:25) at Object.error (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/utilities/utilities.cjs.js:1031:21) at notifySubscription (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/zen-observable/lib/Observable.js:140:18) at onNotify (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/zen-observable/lib/Observable.js:179:3) at SubscriptionObserver.error (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/zen-observable/lib/Observable.js:240:7) at Object.error (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/zen-observable/lib/Observable.js:330:22) { graphQLErrors: [], networkError: Error [ServerError]: Response not successful: Received status code 500 at Object.throwServerError (/Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/link/utils/utils.cjs.js:45:17) at /Volumes/DATA/OwnCode/viet-healthy-dn/node_modules/@apollo/client/link/http/http.cjs.js:32:19 at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:97:5) { response: Response { size: 0, timeout: 0, [Symbol(Body internals)]: [Object], [Symbol(Response internals)]: [Object] }, statusCode: 500, result: { code: 'internal_server_error', message: '<p>There has been a critical error on this website.</p><p><a href="https://wordpress.org/support/article/debugging-in-wordpress/">Learn more about debugging in WordPress.</a></p>', data: [Object], additional_errors: [] } }, extraInfo: undefined }

It's look like any limit are here? I don't know. How can I solved this issue?
I just wanna fetch all products (about only 154 items) for SSG. I dont want pagination here.

Add Favicon

It looks like a favicon is missing for this website.

Adding a favicon for this website will help identify this project amongst a bunch of tabs.
I'm open for discussion.

Pls assign this issue to me so that I can work on this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.