# Changelog

All notable changes to the MP Commerce plugin are documented here.

---

## [1.0.0] — 2026-04-25

### Added

#### AI Shopping Assistant
- Floating chat widget on all storefront pages for authenticated users and optionally guests
- Admin settings page (**MP Commerce → AI Assistant**) to configure provider, API key, model, guest access toggle, and welcome message
- Support for four AI providers: **OpenAI (ChatGPT)**, **Google Gemini**, **DeepSeek**, and **Groq**
- Server-Sent Events (SSE) streaming for real-time token-by-token response display
- Product search integration: assistant can look up products by name and return live results with prices and links
- Order lookup integration: authenticated users can ask about their orders; assistant retrieves real order data
- `[[ACTION:{}]]` protocol: assistant embeds JSON action blocks that the client renders as interactive product/order cards
- `[[LINK:url|label]]` protocol: assistant embeds styled links inside responses
- Session-based conversation history per user visit; history is not stored server-side
- Node.js proxy mode for shared-hosting environments where SSE through PHP is unreliable; falls back to direct PHP streaming automatically
- CSRF-exempt SSE endpoint with manual token validation for compatibility with `EventSource` (which cannot send headers)

#### Enhanced Coupons
- New coupon type: **Free Shipping** — zeroes out the shipping cost at checkout; not combinable with a value
- **New Users Only** flag: coupon is rejected if the user has any prior non-cancelled orders (guests are always blocked)
- **Max Discount Amount** cap for percentage coupons: limits the discount ceiling regardless of order size
- **Uses Per User** limit: tracked via a dedicated `commerce_coupon_usages` table; each successful order records a usage entry
- Edit coupon modal in admin with full field population (previously only add was supported)
- Admin coupon list updated to show type badge (Free Shipping / Percentage / Fixed), restrictions column, and max discount cap

#### Email Notifications
- SMTP configuration stored in `commerce_settings`: host, port, username, password (encrypted at rest), encryption, from address, and from name
- Five configurable notification types: **Registration**, **Order Placed**, **Payment Successful**, **Status Changed**, and **Order Cancelled**
- Each notification has an enable/disable toggle, a customisable subject, and a rich-text body editor powered by **Quill 2.0.3**
- Variable placeholder support in subject and body: `{{name}}`, `{{order_number}}`, `{{status}}`, `{{store_name}}`
- Clicking a variable chip inserts it at the cursor position in the Quill editor
- **Test email** button sends a live test using the SMTP values currently typed in the form (before saving) — no need to save first
- `CommerceMailService` singleton handles dynamic SMTP reconfiguration at send time via `Mail::purge('smtp')`
- Email views use an inline-CSS responsive layout (`emails/layout.blade.php`) with two templates: `simple` (body only) and `order-detail` (body + auto-generated order table)
- Registration email sent automatically after successful sign-up
- Order placed and payment success emails sent from `CheckoutController` / `PaymentCallbackController`
- Status changed and order cancelled emails sent from `AdminController`

#### Support Tickets
- Customer-facing ticket submission and thread view under **Account → Support**
- Admin ticket inbox with reply and status management

#### Storefront
- Product listing page with category filter, search, and sort options
- Single product page with image gallery, variant selector, stock indicator, and add-to-cart
- Category pages with breadcrumb navigation
- Order tracking page (guest and authenticated)
- Homepage section powered by configurable hero slides, promotional banners, and featured products

#### Cart
- Session-based cart for guests; persisted per session
- Add, update quantity, and remove items
- Coupon / discount code support (percentage and fixed amount)
- Real-time subtotal, discount, tax, and total recalculation via AJAX
- Client-side stock enforcement (quantity cannot exceed available stock)
- Server-side stock validation on every add and update

#### Checkout
- Single-page checkout with shipping address form
- Saved address selection for authenticated users
- Auto-fill of name, email, and phone from user profile and address history
- Multiple shipping method support with dynamic cost calculation
- Cash on Delivery (COD) support configurable from settings
- Tax rate support (configurable percentage)
- Address save option for authenticated users
- Order confirmation page

#### Payment Integrations
- Pluggable payment gateway interface via `PaymentService`
- Support for all gateways registered in the Billing plugin (Cashfree, PhonePe, Flutterwave, PayPal, Razorpay, and others)
- Commerce-specific payment flow: payment link creation, redirect, return callback, and webhook handling
- `PaymentCallbackController` handles return and webhook routes per gateway

#### Orders
- Order creation with items, shipping address, coupon, tax, and shipping cost snapshots
- Unique order number generation
- Payment status tracking (`pending`, `awaiting_payment`, `paid`, `failed`)
- Order status tracking (`pending`, `confirmed`, `packed`, `shipped`, `delivered`, `cancelled`)
- Status history log with optional notes per transition
- Admin order detail with status update and cancel actions

#### Admin Panel
- Dashboard with total revenue, total orders, active products, and pending orders KPIs
- 30-day sales chart
- Low-stock product alert table
- Recent orders table

#### Products Management
- Create, edit, and delete products
- Image upload with multiple images support
- Product variants (JSON-based)
- Product specifications (JSON-based)
- Categories (many-to-many)
- Tags, SKU, weight, and slug fields
- Sale price with date range
- Stock quantity management
- Status: `draft`, `active`, `archived`
- Featured and visibility toggles

#### Categories Management
- Create, edit, delete categories
- Category image
- Slug and active status

#### Customers
- Customer list with order counts and total spend per customer

#### Coupons
- Create, edit, delete coupons
- Type: percentage or fixed
- Minimum order amount
- Maximum usage limit and per-user usage limit
- Expiry date
- Active / inactive toggle

#### Shipping Methods
- Create, edit, delete shipping methods
- Type: flat rate or free shipping
- Free shipping threshold (order amount above which shipping becomes free)
- Sort order
- Active / inactive toggle

#### Settings
- Store name, logo, tagline, address, phone, and email
- Currency symbol and code
- Tax rate
- COD enabled toggle
- WhatsApp notification templates (order placed, payment pending/successful, confirmed, packed, shipped, delivered, cancelled)
- Admin alerts: new order and low-stock notifications
- Homepage hero slides (3 slides with title, subtitle, price, and image)
- Promotional banners (3 banners with text and link)

#### Reports
- Total revenue, total orders, average order value, and cancelled orders summary
- Sales by status breakdown
- Top 10 best-selling products by quantity

#### Import / Export
- Full ZIP backup export: all commerce database tables + product images
- ZIP backup import with confirmation step: truncates and restores all tables and images

#### WhatsApp Notifications
- `WhatsAppNotifyService` sends notifications on: order placed, payment successful, order confirmed, packed, shipped, delivered, cancelled, and low-stock admin alerts
- Template placeholders: `{order_number}`, `{customer_name}`, `{total}`, `{items}`, `{product_name}`, `{stock_quantity}`

#### Customer Account Area
- Orders list and order detail
- Profile and password update
- Saved addresses (create, update, delete, set default)
- Pay Now action for unpaid orders

#### Database
- 13 migrations covering: `commerce_categories`, `commerce_products`, `commerce_product_category`, `commerce_orders`, `commerce_order_items`, `commerce_addresses`, `commerce_coupons`, `commerce_shipping_methods`, `commerce_order_status_history`, `commerce_settings`, product specs column addition, `commerce_coupon_usages`, and `commerce_support_tickets`

#### Architecture
- Plugin registered via `PluginServiceProvider` with singleton services: `CartService`, `OrderService`, `PaymentService`, `WhatsAppNotifyService`, `CommerceMailService`
- User model extended with `commerceOrders`, `commerceProducts`, and `commerceAddresses` relations via `resolveRelationUsing`
- Admin sidebar section header injected dynamically without modifying core sidebar template
- Billing plugin nav items (Plans, Manage Plans, Orders) hidden from sidebar; Payment Gateways relocated into the MP Commerce section

---

## License

This plugin is proprietary software sold and distributed exclusively by **OneXGen Technology LLC**.
Unauthorized copying, distribution, or modification is strictly prohibited.

> Contact: info@onexgen.com - https://www.onexgen.com
