Skip to content

Modern, fast, and user-friendly REST API and Python Desktop Application developed for PrestaShop e-commerce platform.

Notifications You must be signed in to change notification settings

MorphyKutay/PrestaShop-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ PrestaShop Management System

Modern, fast, and user-friendly REST API and Python Desktop Application developed for PrestaShop e-commerce platform.

Python PHP PrestaShop License


πŸ“‹ Table of Contents


✨ Features

πŸ”Œ PHP REST API

  • βœ… RESTful Architecture: Standard HTTP methods (GET, POST, PUT, DELETE)
  • βœ… Product Management: Full CRUD operations
  • βœ… Order Management: View orders and update status
  • βœ… Secure: API Key authentication, IP restriction
  • βœ… CORS Support: Cross-origin resource sharing
  • βœ… JSON Format: All responses in standard JSON format
  • βœ… Pagination: Automatic pagination for large datasets
  • βœ… Filtering: Flexible search and filtering options
  • βœ… SQL Optimization: High performance with direct SQL queries
  • βœ… Error Handling: Detailed and clear error messages

πŸ–₯️ Python Desktop Application

  • βœ… Modern Interface: User-friendly GUI with Tkinter
  • βœ… Product Management: Add, edit, delete, search products
  • βœ… Order Management: View orders, update status
  • βœ… Detailed View: View product and order details
  • βœ… Context Menus: Right-click menus for quick access
  • βœ… Async Operations: Non-blocking UI with threading
  • βœ… Auto Connection Test: API status monitoring
  • βœ… Multi-language: Supports internationalization

πŸ› οΈ Technologies

Backend (PHP API)

  • PHP 7.2+
  • PrestaShop 1.7.x / 8.x
  • MySQL / MariaDB
  • Apache / Nginx

Frontend (Python Desktop)

  • Python 3.8+
  • Tkinter (GUI)
  • Requests (HTTP Client)
  • python-dotenv (Configuration)

πŸ“₯ Installation

Requirements

  • PrestaShop installed web server
  • PHP 7.2 or higher
  • Python 3.8 or higher
  • MySQL/MariaDB database

1️⃣ PHP API Setup

Step 1: Upload Files

Create a folder in your PrestaShop root directory:

/your-prestashop/
  β”œβ”€β”€ prestapi/           # API folder
  β”‚   β”œβ”€β”€ api.php
  β”‚   β”œβ”€β”€ config.php
  β”‚   β”œβ”€β”€ .htaccess
  β”‚   β”œβ”€β”€ test.php
  β”‚   └── classes/
  β”‚       β”œβ”€β”€ ApiHandler.php
  β”‚       β”œβ”€β”€ Response.php
  β”‚       β”œβ”€β”€ ProductManager.php
  β”‚       └── OrderManager.php

Step 2: Configure config.php

Open config.php and configure your settings:

<?php
// PrestaShop root directory
define('PS_ROOT_DIR', dirname(__FILE__) . '/../');

// Generate a secure API key
define('API_KEY', 'your_secret_api_key_here');

// Allowed IP addresses (empty array = public access)
define('ALLOWED_IPS', []); 

// Database settings
define('DB_SERVER', 'localhost');
define('DB_USER', 'your_db_user');
define('DB_PASSWD', 'your_db_password');
define('DB_NAME', 'your_db_name');
define('DB_PREFIX', 'ps_');

// API Settings
define('API_DEBUG', true);  // Development: true, Production: false
define('API_CORS_ENABLED', true);

Step 3: Test API

Open the test page in your browser:

https://yourstore.com/prestapi/test.php

or test the API directly:

https://yourstore.com/prestapi/api.php?resource=products&api_key=your_api_key

βœ… If you get a successful response, PHP API is ready!


2️⃣ Python Application Setup

Step 1: Install Python Packages

# Navigate to project directory
cd prestapi

# Install required packages
pip install -r requirements.txt

Step 2: Configure config.env

Edit the config.env file:

# PrestaShop API Configuration
API_URL=https://yourstore.com/prestapi/api.php
API_KEY=your_secret_api_key_here

⚠️ Important: API_KEY must match the API_KEY in PHP API (config.php)!

Step 3: Run Application

python app.py

βœ… Application opens and API connection is automatically tested!


πŸ“š Usage

Python Desktop Application

Product Operations

List Products:

  1. Select "πŸ“¦ Products" from left menu
  2. All products displayed in table

Search Products:

  1. Type product name in search box
  2. Click "Search" button

Add New Product:

  1. Click "βž• New Product" button
  2. Fill the form:
    • Product Name (required)
    • Price (required)
    • Reference, EAN13, Stock Quantity
    • Short Description
    • Status (Active/Inactive)
  3. Click "Save" button

Edit Product:

  • Right-click on product β†’ "✏️ Edit"
  • or select product and click edit button

View Product Details:

  • Double-click on product
  • or right-click β†’ "πŸ‘οΈ View Details"

Delete Product:

  • Right-click β†’ "πŸ—‘οΈ Delete" β†’ Confirm

Order Operations

List Orders:

  1. Select "πŸ“‹ Orders" from left menu
  2. Recent orders displayed in table

View Order Details:

  • Double-click on order
  • 3 tabs open:
    • General Info: Order summary
    • Customer Info: Customer and address
    • Products: Products in order

Update Order Status:

  1. Right-click β†’ "✏️ Update Status"
  2. Select new status:
    • Awaiting Payment (1)
    • Payment Accepted (2)
    • Processing (3)
    • Shipped (4)
    • Delivered (5)
    • Canceled (6)
    • Refunded (7)
  3. Click "Update" button

πŸ”Œ API Documentation

Authentication

API key must be sent with all requests:

Method 1: Header (Recommended)

curl -H "X-API-Key: your_api_key" https://yourstore.com/prestapi/api.php?resource=products

Method 2: Query String

curl https://yourstore.com/prestapi/api.php?resource=products&api_key=your_api_key

Product Endpoints

List All Products

GET /api.php?resource=products

Parameters:

  • page - Page number (default: 1)
  • limit - Products per page (default: 50, max: 100)
  • active - Status filter (0 or 1)
  • category - Category ID
  • search - Search in product name

Example:

curl -H "X-API-Key: your_api_key" \
  "https://yourstore.com/prestapi/api.php?resource=products&page=1&limit=10&search=tshirt"

Response:

{
  "success": true,
  "message": "Products retrieved successfully",
  "data": {
    "items": [
      {
        "id_product": "1",
        "name": "Sample T-Shirt",
        "price": "29.99",
        "stock_quantity": "100",
        "active": "1",
        "price_formatted": "29.99 β‚Ί"
      }
    ],
    "pagination": {
      "total": 150,
      "page": 1,
      "limit": 10,
      "pages": 15
    }
  }
}

Get Single Product

GET /api.php?resource=products&id=1

Create New Product

POST /api.php?resource=products
Content-Type: application/json

{
  "name": "New Product",
  "price": 49.99,
  "reference": "REF123",
  "quantity": 100,
  "active": 1
}

Update Product

PUT /api.php?resource=products&id=1
Content-Type: application/json

{
  "price": 59.99,
  "quantity": 150
}

Delete Product

DELETE /api.php?resource=products&id=1

Order Endpoints

List All Orders

GET /api.php?resource=orders

Parameters:

  • page - Page number
  • limit - Orders per page
  • customer - Customer ID
  • status - Order status
  • date_from - Start date (YYYY-MM-DD)
  • date_to - End date (YYYY-MM-DD)

Get Single Order

GET /api.php?resource=orders&id=1

Update Order Status

PUT /api.php?resource=orders&id=1
Content-Type: application/json

{
  "current_state": 3
}

Response Format

Success:

{
  "success": true,
  "message": "Operation successful",
  "data": { ... }
}

Error:

{
  "success": false,
  "message": "Error message",
  "errors": null
}

HTTP Status Codes

  • 200 - OK
  • 201 - Created
  • 400 - Bad Request
  • 401 - Unauthorized (Invalid API key)
  • 403 - Forbidden (IP restriction)
  • 404 - Not Found
  • 500 - Internal Server Error

πŸ”’ Security

API Key

Generate a strong API key:

// Generate random key with PHP
define('API_KEY', bin2hex(random_bytes(32)));

IP Restriction

Allow access only from specific IPs:

define('ALLOWED_IPS', [
    '192.168.1.100',  // Office
    '203.0.113.50'    // Server
]);

HTTPS

⚠️ Always use HTTPS in production!

Debug Mode

Disable debug mode in production:

define('API_DEBUG', false);

πŸ› Troubleshooting

API Connection Error

Problem: "Cannot connect to API"

Solution:

  1. Check URL in config.env
  2. Verify API key is correct
  3. Ensure server is accessible

Kernel Container Error

Problem: "Kernel Container is not available"

Solution: βœ… This issue is resolved! API no longer depends on PrestaShop Kernel.

SQL Syntax Error

Problem: SQL syntax error

Solution: Check database prefix (config.php β†’ DB_PREFIX)

Tkinter Not Installed

Problem: ModuleNotFoundError: No module named 'tkinter'

Solution:

Ubuntu/Debian:

sudo apt-get install python3-tk

macOS: Reinstall Python (includes Tkinter)

Windows: Ensure "tcl/tk" option is checked during Python installation

Module Not Found

Problem: ModuleNotFoundError: No module named 'requests'

Solution:

pip install -r requirements.txt

πŸ“Š Project Structure

prestapi/
β”œβ”€β”€ πŸ“ PHP API (Backend)
β”‚   β”œβ”€β”€ api.php                 # Main endpoint
β”‚   β”œβ”€β”€ config.php              # Configuration
β”‚   β”œβ”€β”€ test.php                # Test interface
β”‚   β”œβ”€β”€ .htaccess               # URL rewriting
β”‚   └── classes/
β”‚       β”œβ”€β”€ ApiHandler.php      # Request handler
β”‚       β”œβ”€β”€ Response.php        # Response handler
β”‚       β”œβ”€β”€ ProductManager.php  # Product operations
β”‚       └── OrderManager.php    # Order operations
β”‚
β”œβ”€β”€ 🐍 Python Desktop (Frontend)
β”‚   β”œβ”€β”€ app.py                  # Main application
β”‚   β”œβ”€β”€ api_client.py           # API client
β”‚   β”œβ”€β”€ config.env              # Configuration
β”‚   └── requirements.txt        # Python dependencies
β”‚
└── πŸ“„ Documentation
    β”œβ”€β”€ README.md               # This file
    └── README_PYTHON.md        # Python app details

🎯 Features and Development

Current Features βœ…

  • REST API
  • Product CRUD operations
  • Order management
  • Python desktop application
  • API security
  • Pagination and filtering
  • HTML sanitization
  • SQL optimization

Planned Features πŸš€

  • Category management
  • Customer management
  • Stock tracking
  • Bulk operations
  • Excel export
  • Charts and reports
  • Product image upload
  • Dark mode
  • Multi-language support
  • Real-time updates with WebSocket

🀝 Contributing

We welcome contributions!

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“ License

This project is licensed under the MIT License. See LICENSE file for details.


πŸ‘¨β€πŸ’» Developer

PrestaShop API & Desktop Manager


πŸ™ Acknowledgments

  • PrestaShop community
  • Python Tkinter developers
  • All contributors

πŸ“ž Contact

For questions or suggestions, please open an issue.


πŸ“Έ Screenshots

Python Desktop Application

Main Screen

  • Modern and clean design
  • Colorful status indicators
  • Easy navigation

Product Management

  • Table view
  • Search functionality
  • Context menus
  • Quick editing

Order Management

  • Detailed order view
  • Customer information
  • Product list
  • Status updates

PHP API Test Interface

  • Automatic API tests
  • Visual result display
  • Error details

πŸš€ Quick Start

For Developers

# Clone repository
git clone https://github.com/yourusername/prestapi.git

# Install PHP API
cd prestapi
# Upload to PrestaShop server

# Install Python app
pip install -r requirements.txt
python app.py

For Users

  1. Download latest release
  2. Follow installation guide above
  3. Configure config.php and config.env
  4. Run python app.py

πŸ’‘ Tips

  1. Quick Search: Use product search for fast lookup
  2. Context Menu: Right-click for quick operations
  3. Double Click: View details quickly
  4. Keyboard Shortcuts: Enter to save, Escape to cancel
  5. Multi-select: Planned for future versions

πŸ“ˆ Performance

  • Fast API: Direct SQL queries for optimal performance
  • Efficient Pagination: Handle large datasets smoothly
  • Async Operations: Non-blocking UI operations
  • Optimized Queries: Minimized database calls

πŸ”§ Configuration Options

PHP API

  • PS_ROOT_DIR - PrestaShop root directory
  • API_KEY - API authentication key
  • ALLOWED_IPS - IP whitelist
  • DB_PREFIX - Database table prefix
  • API_DEBUG - Debug mode
  • API_CORS_ENABLED - CORS support

Python Application

  • API_URL - API endpoint URL
  • API_KEY - Authentication key

🌐 Localization

Currently supports:

  • Turkish (tr)
  • English (en)

Want to add more languages? Contributions welcome!


πŸ“¦ Dependencies

PHP

  • PrestaShop 1.7+
  • PHP 7.2+
  • MySQL/MariaDB

Python

  • Python 3.8+
  • requests
  • python-dotenv
  • tkinter (included with Python)

⚑ Advanced Usage

Bulk Operations (Planned)

# Future feature
api.bulk_update_products([
    {'id': 1, 'price': 29.99},
    {'id': 2, 'price': 39.99}
])

Webhooks (Planned)

// Future feature
$api->registerWebhook('order.created', 'https://yourapp.com/webhook');

πŸŽ“ Learning Resources


⭐ If you like this project, please give it a star!

Made with ❀️ for PrestaShop community

About

Modern, fast, and user-friendly REST API and Python Desktop Application developed for PrestaShop e-commerce platform.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •