This application integrates Odooโs eCommerce functionalities with NestJS through external APIs, utilizing Odoo ERP via XML-RPC. The integration allows seamless management of key business operations, including product listings, order processing, and cart management, by leveraging Odooโs powerful eCommerce features.
To secure sensitive operations, the application incorporates JWT (JSON Web Token) authentication. This ensures that only authorized users can access protected routes, such as adding products to the cart, viewing orders, and updating cart items, providing a secure environment for eCommerce transactions.
By leveraging Odoo's external APIs via XML-RPC for eCommerce features, users benefit from the full capabilities of Odoo ERP, while the system remains protected with token-based authentication to ensure both security and efficiency in online store management.
- Odoo Documentation: [https://www.odoo.com/documentation/18.0/]
๐ JWT Authentication: Secure routes with token-based authentication.
๐ XML-RPC Integration: Seamless communication between the NestJS application and Odoo ERP for eCommerce management.
๐ Basic eCommerce Features:
โ Add products to the cart
โ View cart products
โ Update cart products
โ Remove products from the cart
๐ Security Enhancements: Strengthening application security through secure authentication practices.
- NestJS: A progressive Node.js framework for building efficient, reliable, and scalable server-side applications.
- Odoo ERP 18.0: Open-source business application suite for managing various business operations like sales, inventory, accounting, and more.
- JWT (JSON Web Tokens): For securing API routes.
- XML-RPC: For integrating Odoo ERP with the NestJS application.
Follow these steps to set up the application locally:
- Node.js (v16 or later)
- NPM (or Yarn)
- Odoo ERP 18.0 instance
git clone https://github.com/alaparsalan/odoo-erp-nest-shop.git
cd odoo-erp-nest-shop
Run the following command to install the necessary dependencies for the project:
bash npm install
Create a .env
file in the root directory of the project and add the necessary environment variables:
.env
ODOO_URL=<your_odoo_instance_url>
ODOO_DB=<your_odoo_db_name>
ODOO_USERNAME=<your_odoo_username>
ODOO_PASSWORD=<your_odoo_password>
JWT_SECRET=<your_jwt_secret_key>
Make sure to replace the placeholders with your actual Odoo instance details and JWT secret key.
Start the NestJS application locally:
npm run start:dev
This will start the server on http://localhost:3000
.
- Navigate to
http://localhost:3000
to access the eCommerce functionality. - Use Postman or any API testing tool to test the JWT-secured routes.
- POST
http://localhost:3000/auth/register
Request Body:
json
"name": "<your_name>",
"password": "<your_password>",
"new_password": "<new_password>",
"email": "<your_email>"
Response:
json
"message": "User Registered Successfully!",
"ID": "your user ID is <ID>"
- POST
bash http://localhost:3000/auth/signin
Request Body:
json
"email": "<your_email>",
"password": "<your_password>"
Response:
json
"message": "Login Successful",
"token": "<encrypted_token>"
Token Encryption:
- The JWT token is encrypted with two key elements:
- User ID: A unique identifier for the user, ensuring that each token is linked to a specific user.
- Partner ID: The identifier used to manage Odoo eCommerce functionalities, such as product listings, orders, and customer data.
Storing Token:
- After a successful login, the JWT token is stored in the browser's Local Storage. This provides easy access to the token for making subsequent API calls, ensuring secure communication for all interactions.
How to Use the Token:
- The JWT token saved in Local Storage should be included in the Authorization header for all requests to secure routes. The format will be:
bash Authorization: Bearer <encrypted_token>
- GET
http://localhost:3000/cart/products
- GET
http://localhost:3000/cart/:partnerId
- POST
http://localhost:3000/cart/addtocart
Request Body:
json
"partnerId": <partner_id>,
"productId": <product_id>,
"quantity": <quantity>
- PUT
http://localhost:3000/cart/updatecart
Request Body:
json
"partnerId": <partner_id>,
"cartId": <cartitem_id>,
"qty": <quantity>
- DELETE
http://localhost:3000/cart/removeitem
Request Body:
json
"cartId": <cartitem_id>
- GET
http://localhost:3000/orders/fetch
- GET
http://localhost:3000/products/fetch?limit=1&offset=0
Query Parameters:
limit
: Number of products to fetch.offset
: Starting point for pagination.
Ensure that any route requiring authentication has the JWT token in the Authorization
header. The format should be:
bash Authorization: Bearer <jwt_token>
- NestJS Documentation
- Odoo ERP 18.0 Documentation
We welcome contributions to this project! If you'd like to contribute, feel free to fork the repository, submit pull requests, or open issues.
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make your changes.
- Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature/your-feature
). - Create a new pull request.
This project is licensed under the MIT License - see the LICENSE file for details.