# mageprince/magento2-mage-ai-predict

> Magento 2 AI Predictive Inventory & Raw Material Forecaster (MageAI add-on)

`composer require mageprince/magento2-mage-ai-predict`

Canonical URL: https://packagento.com/mageprince/magento2-mage-ai-predict

## At a glance

- **Vendor**: mageprince (https://packagento.com/mageprince.md)
- **Latest version**: 1.0.0 — released 2026-07-22
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/mageprince/magento2-mage-ai-predict and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require mageprince/magento2-mage-ai-predict:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

Magento 2 AI Predictive Inventory & Raw Material Forecaster (MageAI add-on)

## README

This Magento 2 extension is an **AI-powered Predictive Inventory & Raw Material Forecaster**. It analyses your store's **historical sales**, predicts **next month's demand** for every product, and turns that into clear, actionable advice: **what to reorder and by when**, and **what is overstocked or dead stock** tying up your capital. It uses **OpenAI (GPT)**, **Anthropic (Claude)**, or **Google Gemini** — reusing the AI provider you already configured in the **MageAI** extension.

❤️ This is a companion to the open-source [MageAI](https://github.com/mageprince/magento2-mage-ai) extension. The goal is the same: keep it fully open-source and continuously expand the ways AI can help run a Magento 2 store — this time on the operations side, helping merchants avoid lost sales from stock-outs and frozen cash from over-stocking. If you're into Magento, AI, or supply-chain, your ideas and contributions are always welcome. Let's build something useful together!

> **Why not just ask an LLM to predict the numbers?** Because LLMs are poor at raw numeric forecasting. This extension does the maths with a deterministic statistical engine, then uses the AI only for what it's genuinely good at — reasoning over trend/seasonality/context and explaining the recommendation in plain language. The AI can be turned off entirely for free, instant, statistics-only forecasts.

### Features
- **Demand forecast for the upcoming month** — per-product prediction from 2–3 years of sales history (moving average × seasonality × recent trend)
- **AI-adjusted forecasts + plain-language recommendations** — the LLM refines the statistical baseline and explains *why* in merchant-friendly language
- **Automated procurement alerts** — recommended **reorder quantity** and a **reorder-by date** based on your lead time and safety-stock settings
- **Overstock / dead-stock detection** — flags capital tied up in slow-moving inventory
- **Colour-coded admin grid** — status and confidence shown as badges, plus a summary dashboard (out-of-stock risk / reorder soon / overstock / healthy / total units to reorder)
- **Multi-provider AI support** — reuses the OpenAI / Anthropic / Gemini provider configured in MageAI (one place for API keys)
- **Optional AI layer** — disable it for a free, instant, statistics-only baseline (no API calls)
- **Scheduled forecasting (cron)** — keeps the grid current automatically; configurable schedule
- **Run on demand** — a **"Generate Forecasts Now"** button for an immediate refresh
- **Tunable** — configure history window, lead time, safety stock and overstock threshold to match your business

### Supported AI Providers

Provider, models and API keys are inherited from the **MageAI** extension configuration.

| Provider | Models |
|---|---|
| **Google Gemini** *(default)* | `gemini-2.5-flash`, `gemini-2.5-pro`, `gemini-1.5-flash`, `gemini-1.5-pro` |
| **OpenAI (ChatGPT)** | `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo`, `gpt-4`, `gpt-3.5-turbo` |
| **Anthropic (Claude)** | `claude-opus-4-5`, `claude-sonnet-4-6`, `claude-haiku-4-5` |

### Usage

#### Setup
1. Make sure the **MageAI** extension is installed and its AI **provider + API key** are configured (`Stores > Configuration > Mageprince > MageAI`)
2. Go to `Stores > Configuration > Mageprince > MageAI Predict (Demand Forecast)`
3. Enable **Forecasting**, and choose whether to **Use AI Adjustment** (off = statistics only, no API calls)
4. Set your **Sales History (years)**, **Restock Lead Time**, **Safety Stock (days)** and **Overstock Threshold**
5. Optionally set a **Max Products Per Run** and enable the **Scheduled Forecast** with a cron expression
6. Save the configuration

#### Generate a forecast
1. Open **MageAI Predict > Demand Forecast** from the admin menu
2. Click **"Generate Forecasts Now"** (or wait for the scheduled cron)
3. The grid fills with per-product forecasts, statuses, reorder recommendations and AI rationales

#### Read the grid
| Column | Meaning |
|---|---|
| **Baseline Forecast** | Prediction from pure statistics (sales history only) |
| **Forecast (units)** | Final prediction after AI adjustment (falls back to baseline if AI is off/unavailable) |
| **Current Stock** | On-hand quantity right now |
| **Reorder Qty / Reorder By** | How many units to order, and the deadline to order them |
| **Status** | 🔴 Out-of-stock risk · 🟠 Reorder soon · 🔵 Overstock / dead stock · 🟢 Healthy |
| **Confidence** | How much history backs the forecast (high / medium / low) |
| **AI Recommendation** | Plain-language reasoning for the number |

> The AI is only called for products with **at least 2 months of sales history** — there's no point spending an API call on a product with nothing to reason about. Products below that threshold use the statistical baseline.

### How to Install

#### Install via Composer

Run the following commands in your Magento 2 root folder:

```bash
composer require mageprince/magento2-mage-ai-predict
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
```

> Requires the **MageAI** extension (`mageprince/magento2-mage-ai`), which is pulled in automatically as a dependency.

### Contribution
Contributions are highly welcome and encouraged! 🙌

This project is a personal open-source effort to bring the power of AI to Magento 2. Whether you want to:
- Add new features (weather/festival signals, dashboards, bill-of-materials forecasting)
- Improve the forecasting logic or prompts
- Fix bugs
- Help with translations or documentation
- Or just share feedback…

You're very welcome to join in.

**To contribute:**
1. Fork the repository
2. Create your feature branch: `git checkout -b feature/my-feature`
3. Commit your changes: `git commit -m 'Add new feature'`
4. Push to the branch: `git push origin feature/my-feature`
5. Create a new Pull Request

_(README truncated for .md surface. Full README on https://packagento.com/mageprince/magento2-mage-ai-predict.)_

## Recent Versions

| Version | Released |
|---|---|
| 1.0.0 | 2026-07-22 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| mageprince/magento2-mage-ai | * |
| php | ~8.1.0\|\|~8.2.0\|\|~8.3.0\|\|~8.4.0 |

## Quality

Latest release (1.0.0) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | Pass | not tested |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Warning | 1 | 1 warning (ruleset: Magento2) |
| PHPMD | Warning | 23 | 23 rule violations (UnusedPrivateField:23) |
| Cpd | Pass | 0 |  |
| Composer validate | Info | 2 | valid; 2 advisory notes (composer validate --strict) |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | 11 | 11 | – | – |
| 2.4.8 | – | 11 | 11 | – |
| 2.4.9 | – | – | 11 | N/A |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["mageprince/magento2-mage-ai-predict"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

mageprince is a Magento 2 vendor on Packagento. See https://packagento.com/mageprince.md for their full catalogue.

