# Digital Marketplace - Premium Version 2.0

A production-ready, premium digital products marketplace built with PHP, MySQL, and modern web technologies.

![Version](https://img.shields.io/badge/version-2.0.0-blue)
![PHP](https://img.shields.io/badge/PHP-8.0+-purple)
![License](https://img.shields.io/badge/license-Premium-green)

---

## Features

### Core Features

- **Product Management**: Add, edit, and manage digital products with multiple file types
- **License System**: Regular and Extended license pricing
- **Category Management**: Organize products with categories and subcategories
- **Cart & Checkout**: Full-featured shopping cart with multiple payment options
- **Order Management**: Track orders, payments, and downloads
- **User Management**: Customer accounts with order history
- **Admin Dashboard**: Comprehensive analytics and management tools

### Premium Features

- **Dark Luxury Theme**: Modern, responsive design with premium aesthetics
- **Multiple Payment Gateways**: PayPal, Stripe, Paystack, Flutterwave, Bitcoin, Bank Transfer
- **Affiliate System**: Referral tracking with commission management
- **Price Negotiation**: Customers can make offers on products
- **Email Marketing**: Newsletter system with campaign management
- **Blog System**: Content marketing with SEO optimization
- **Product Reviews**: Customer reviews and ratings
- **Wishlist**: Save products for later
- **Coupon System**: Discount codes and promotions
- **WhatsApp Integration**: Floating chat button
- **Popup System**: Promotional popups and lead capture
- **Notification Bar**: Admin-controlled announcements

### Security Features

- CSRF Protection
- SQL Injection Prevention (Prepared Statements)
- XSS Protection
- Password Hashing (Bcrypt)
- Login Attempt Limiting
- Session Security
- Input Validation

---

## System Requirements

- PHP 8.0 or higher
- MySQL 5.7+ or MariaDB 10.3+
- Apache with mod_rewrite OR Nginx
- SSL Certificate (required for payments)

### PHP Extensions

- PDO & PDO_MySQL
- GD/ImageMagick
- cURL
- OpenSSL
- Mbstring
- JSON
- Fileinfo
- ZIP

---

## Installation

### Quick Install

1. **Upload files** to your web server
2. **Create database** and import `database_upgrade.sql`
3. **Configure database** in `config/database.php`
4. **Set permissions**: `chmod -R 755 uploads/`
5. **Access admin**: `/admin/` (default: admin@localhost / password)

### Detailed Installation

See [INSTALLATION.md](INSTALLATION.md) for complete instructions.

---

## Configuration

### Basic Settings

Edit `config/database.php`:

```php
define('DB_HOST', 'localhost');
define('DB_NAME', 'your_database');
define('DB_USER', 'your_username');
define('DB_PASS', 'your_password');
```

### Payment Gateways

Configure in Admin Panel > Settings > Payments:

- PayPal (Client ID, Secret)
- Stripe (Publishable/Secret Keys)
- Paystack (Public/Secret Keys)
- Flutterwave (Public/Secret Keys)
- Bitcoin (API Key)
- Bank Transfer (Account Details)

See [PAYMENT_SETUP.md](PAYMENT_SETUP.md) for detailed setup.

---

## File Structure

```
marketplace/
├── admin/                  # Admin panel
│   ├── includes/          # Admin header/footer
│   ├── assets/            # Admin CSS/JS
│   └── *.php              # Admin pages
├── api/                   # AJAX API endpoints
├── assets/                # Frontend assets
│   ├── css/              # Stylesheets
│   ├── js/               # JavaScript files
│   └── images/           # Images
├── config/                # Configuration files
│   └── database.php      # Database config
├── includes/              # Shared includes
│   ├── functions.php     # Helper functions
│   ├── header.php        # Frontend header
│   └── footer.php        # Frontend footer
├── payments/              # Payment gateway handlers
├── uploads/               # User uploads
│   ├── products/         # Product files
│   └── avatars/          # User avatars
├── account/               # User account pages
├── database_upgrade.sql   # Database schema
├── index.php             # Homepage
├── products.php          # Product listing
├── product.php           # Product detail
├── cart.php              # Shopping cart
├── checkout.php          # Checkout
├── login.php             # User login
├── register.php          # User registration
└── *.md                  # Documentation
```

---

## API Endpoints

### Cart API

```
POST /api/cart.php
  action=add&product_id=1&quantity=1&license_type=regular
  action=update&cart_id=1&quantity=2
  action=remove&cart_id=1
  action=clear
```

### Wishlist API

```
POST /api/wishlist.php
  action=add&product_id=1
  action=remove&product_id=1
  action=toggle&product_id=1
```

### Coupon API

```
POST /api/coupon.php
  action=apply&code=DISCOUNT10
  action=remove
```

### Newsletter API

```
POST /api/subscribe.php
  email=user@example.com&name=John
```

---

## Database Schema

### Core Tables

- `admins` - Admin users
- `users` - Customer accounts
- `categories` - Product categories
- `products` - Product listings
- `product_images` - Product gallery
- `product_licenses` - License pricing
- `cart` - Shopping cart items
- `orders` - Order records
- `order_items` - Order line items
- `coupons` - Discount codes
- `reviews` - Product reviews
- `testimonials` - Customer testimonials
- `faqs` - FAQ entries
- `blog_posts` - Blog articles
- `subscribers` - Newsletter subscribers
- `affiliates` - Affiliate accounts
- `affiliate_referrals` - Affiliate sales
- `negotiations` - Price negotiations
- `payment_settings` - Payment gateway config
- `email_templates` - Email templates
- `settings` - Site settings

---

## Customization

### Theme Colors

Edit CSS variables in `assets/css/style.css`:

```css
:root {
    --primary: #8b5cf6;
    --secondary: #6366f1;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
}
```

### Email Templates

Customize in Admin Panel > Settings > Email Templates

Available variables:
- `{{site_name}}` - Site name
- `{{user_name}}` - Customer name
- `{{order_number}}` - Order number
- `{{order_total}}` - Order total
- `{{product_name}}` - Product name

---

## Troubleshooting

### Common Issues

**500 Internal Server Error**
- Check PHP version (must be 8.0+)
- Verify `.htaccess` exists
- Check file permissions

**Database Connection Error**
- Verify credentials in `config/database.php`
- Ensure database exists
- Check MySQL server is running

**Payment Not Working**
- Verify API keys are correct
- Check gateway is enabled
- Test in sandbox mode first

See [INSTALLATION.md](INSTALLATION.md) for more troubleshooting.

---

## Security

- Always use HTTPS in production
- Keep software updated
- Use strong passwords
- Enable CSRF protection
- Validate all inputs
- Sanitize output
- Use prepared statements

---

## Performance

### Optimization Tips

1. Enable browser caching
2. Use CDN for assets
3. Optimize images
4. Enable Gzip compression
5. Use database indexing
6. Implement caching layer

---

## Support

For support and assistance:

1. Check documentation
2. Review error logs
3. Contact support team

---

## Changelog

### Version 2.0.0

- Complete UI/UX redesign with dark luxury theme
- Added affiliate system
- Added price negotiation feature
- Added blog system
- Added newsletter campaigns
- Added popup system
- Added WhatsApp integration
- Added notification bar
- Enhanced payment gateways
- Improved security features
- Added product licenses
- Added wishlist functionality
- Enhanced admin dashboard with charts

---

## License

This software is licensed under the terms provided with your purchase.

**Copyright © 2024 Digital Marketplace. All rights reserved.**

---

## Credits

- Bootstrap 5 - Frontend framework
- Font Awesome - Icons
- Chart.js - Charts and graphs
- AOS - Animation library
- PHPMailer - Email handling

---

**Built with passion for digital entrepreneurs.**
