# SmartCart - Magento 2 contextual cart recommendations

> Magento 2 contextual cart recommendations that show shoppers the right add-on products at the right moment - on the cart page, mini-cart, and checkout sidebar.

---

## Overview

SmartCart places contextual cart recommendations in your shoppers' path at the moment they're most likely to add something extra. When a customer has items in their cart, SmartCart evaluates a set of rules you've created, picks the most relevant complementary products, and shows them as add-on tiles - directly on the cart page, in the slide-out mini-cart, or in the checkout sidebar.

![SmartCart admin configuration overview](images/overview.png)

Every recommendation is entirely rule-based and runs locally with no third-party calls at runtime. You decide which products appear and when, through a rule editor with three trigger types (specific SKUs in cart, category in cart, or attribute match) and three pool types (specific products, a category, or an attribute value). Optional guardrails keep out-of-stock, already-in-cart, or previously-purchased products off the list automatically.

A separate offline toolset - association mining and an optional AI provider - can analyse your order history and propose draft rules for your review. You approve or reject each draft; nothing goes live without your sign-off.

This module helps you:

- Present relevant add-on products in the cart, mini-cart, and checkout sidebar without touching theme templates
- Suppress products a shopper already owns, has already added, or has dismissed - keeping suggestions fresh and useful
- Build recommendation rules manually or let the system propose them from your order history
- Track impressions, clicks, add-to-carts, and revenue per rule so you can see what's actually working
- Restrict offers by customer group, cart subtotal threshold, or coupon status

---

## When to use this

Use SmartCart when you want to:

- Surface complementary accessories or consumables at the point in the journey where the shopper has already committed to buying
- Replace a static "You may also like" cross-sell block with context-aware suggestions that respond to what's actually in the cart
- Test which add-on products convert best - rule-level stats show impressions, add rate, and purchase rate over 30 days
- Avoid pestering returning customers with products they already bought - purchase history suppression handles that automatically
- Get rule suggestions from your own order data without having to comb through reports yourself

---

## Key capabilities

- Rule-based recommendations - define triggers (SKU, category, attribute) and pools (specific products, category, attribute) per rule
- Three placement zones - cart page, mini-cart, and checkout sidebar, each independently enabled
- Guardrail filtering - automatically removes out-of-stock, already-in-cart, excluded, and incompatible candidates
- Dismissal memory - dismissed offers stay hidden for a configurable number of hours per shopper, per store
- Purchase history suppression - skip products the shopper has already ordered, matched by customer ID or guest email
- Performance stats - 30-day impressions, add rate, purchase rate, and revenue visible on the Rules grid without extra queries
- Offline AI tooling - mine co-purchase associations from order history, optionally enrich with AI tags, generate draft rules for admin review
- Draft approval workflow - mined and AI-generated rules require explicit approve or reject before going live
- Event tracking - impressions, clicks, dismissals, and purchases logged with placement context for analysis
- ProfitEasy integration - SmartCart-attributed revenue appears as a `smartcart` source bucket in ProfitEasy reporting

---

## Installation

SmartCart installs via Composer, then activates with a license key from your Moogento.com account. The whole flow takes about 5 minutes.

### Step 1: Get your Composer keys from Moogento.com

1. Sign in at **https://www.moogento.com** and open **My Plugins** in your account menu.
2. Find **SmartCart** in the list of plugins you own.
3. Generate (or reveal) the Composer access keys for that plugin - a **public key** and a **private key**.
4. **Add your install domain to the key.** Each Composer key is tied to a specific domain - if you're installing on `yourstore.com`, add `yourstore.com` to the key's allowed domains. The Composer download will be rejected on any other domain.

If you run staging and production on different domains, add both - separate keys per environment are fine too.

### Step 2: Install the module with Composer

From your Magento 2 root directory:

```
composer require moogento/module-smartcart
```

When Composer asks for credentials, paste the **public key** as the username and the **private key** as the password. They'll be cached in `~/.composer/auth.json` for future runs.

### Step 3: Enable the module in Magento

```
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:clean
```

If you run `php bin/magento module:status Moogento_Smartcart` you should see it listed as enabled.

### Step 4: Add your license key in the Moogento admin

1. Still on **https://www.moogento.com > My Plugins**, copy the **license key** for SmartCart (separate from the Composer keys you used above).
2. In your Magento admin, go to **Stores > Configuration > Moogento > Licenses**.
3. Find the row for **SmartCart** and paste the license key.
4. Click **Save Config**, then run `php bin/magento cache:clean` once.

The license validates within a few seconds. You should see the module's status flip to active. If it stays inactive, double-check the domain on the license matches where you've installed - domain mismatch is the most common cause.

---

## Setup overview

Most setup happens in:

Stores > Configuration > Moogento > SmartCart

You'll mainly work with:

- General - master on/off switch, offer limit, cache TTL, and debug logging
- Setup: Placements - choose which zones (cart page, mini-cart, checkout sidebar) show recommendations
- Setup: Eligibility Rules - customer group restrictions, minimum cart subtotal, excluded SKUs and categories, coupon suppression
- Setup: Compatibility Constraints - filter candidates by attribute compatibility with cart contents
- Setup: Dismissal Memory - how long dismissed offers stay hidden per shopper
- Setup: Purchase History - suppress products the shopper has already ordered
- Setup: Event Tracking - record impressions, clicks, dismissals, and purchases for analysis
- Setup: Security - auto-generated context hash key for request signing (rarely touched manually)
- Setup: AI-Powered SmartCart Rules - configure an AI provider and trigger rule generation from order history

Rules and draft review live under the Moogento menu:

- **Moogento > SmartCart > Rules** - create, edit, enable, disable, and delete recommendation rules
- **Moogento > SmartCart > Drafts** - review, approve, or reject AI-mined draft rules

---

## Common setups

### Turn SmartCart on and place it on the cart page

New installations have SmartCart disabled by default so you can create at least one rule before shoppers see anything. Once a rule is ready, enable the module and choose where offers appear.

#### How to set it up

1. Go to:
   Stores > Configuration > Moogento > SmartCart > General

2. Set:
   - Enable = Yes
   - Maximum Offers = 2 (1–2 converts best; you can test with 3 if your layout allows it)
   - Cache TTL (seconds) = 300 (default - keeps server load low; set to 0 to disable caching during rule testing)

3. Go to:
   Stores > Configuration > Moogento > SmartCart > Setup: Placements

4. Set:
   - Show: Cart Page = Yes
   - Show: Mini-Cart = No (enable separately once cart placement is working)
   - Show: Checkout Sidebar = No

5. Save Config

![SmartCart General configuration group](images/config-general.png)

#### Notes

- The module will not show any suggestions if there are no active rules. Go to **Moogento > SmartCart > Rules** and create at least one rule before enabling.
- If you change cache TTL during testing, remember to set it back to 300 or higher in production - a TTL of 0 fires a pipeline call on every cart page load.

---

### Create a manual recommendation rule

Rules tell SmartCart which products to suggest and when. Each rule has a trigger (what must be in the cart) and a pool (which products to suggest).

#### How to set it up

1. Go to:
   Moogento > SmartCart > Rules

2. Click **Add New Rule**.

3. Fill in the form:
   - **Code** - a unique slug for this rule, e.g. `camera-accessories`
   - **Priority** - higher numbers run first when multiple rules match; start at 10 and leave gaps to insert later
   - **Status** - set to Enabled when ready to go live
   - **Store View** - choose a specific store or leave as All Store Views
   - **Trigger Type** - choose SKU in Cart, Category in Cart, or Attribute in Cart, then fill the trigger values
   - **Pool Type** - choose Specific Products, Category, or Attribute, then select the candidates
   - **Display Copy** - optional title and helper text shown above the offer tiles

4. Save the rule.

#### Notes

- Rules only fire if a shopper's cart matches the trigger. A rule with trigger type "SKU in Cart" and no matching SKU in the cart will never show.
- Guardrails run automatically - out-of-stock, already-in-cart, and excluded products are filtered out before display regardless of pool contents.
- The Rules grid shows 30-day impressions, add rate, and purchase rate per rule once event tracking is enabled. Check back after a week to compare rule performance.

---

### Restrict offers by customer group and minimum cart value

Not every offer is right for every customer. Use eligibility rules to limit suggestions to guests, logged-in customers, or specific groups - and only show when the cart is large enough to make the add-on relevant.

#### How to set it up

1. Go to:
   Stores > Configuration > Moogento > SmartCart > Setup: Eligibility Rules

2. Set:
   - Show to: Customer Groups - select the groups you want to target (leave empty for all groups)
   - Threshold: Minimum Cart Subtotal - enter a value, e.g. `50` to only show offers on carts worth $50 or more (use `0` for no minimum)
   - Exclude: Product SKUs - paste any SKUs that should never appear as suggestions, comma-separated
   - Exclude: Categories - select any categories whose products should never be suggested
   - Disable: When Coupon Applied - set to Yes to hide all recommendations whenever a coupon code is active

3. Save Config

![SmartCart Eligibility Rules configuration group](images/config-eligibility.png)

#### Notes

- Coupon suppression (Disable: When Coupon Applied) is useful if your coupons already give a discount - showing an add-on alongside a discount code can dilute the incentive.
- Excluded SKUs and categories act as a blocklist across all rules. You can also exclude a pool at the rule level by simply not including those products in the pool.

---

### Use purchase history suppression to avoid re-suggesting owned products

Recommending a product someone already bought feels out of touch. Enable history suppression so SmartCart automatically skips candidates the shopper has ordered before.

#### How to set it up

1. Go to:
   Stores > Configuration > Moogento > SmartCart > Setup: Purchase History

2. Set:
   - Enable: Purchased Product Suppression = Yes
   - Look Back: Days = 90 (how far back to check; increase for slow-moving products)
   - Include: Guest Orders = Yes (if you want to match by email for guests)

3. Save Config

![SmartCart Purchase History configuration group](images/config-history.png)

#### Notes

- Guest order matching requires the guest's email to be available in the session. If a guest checks out without logging in, the email from their most recent checkout attempt is used.
- History lookups are cached (`Cache: History TTL` in the same group, default 3600 seconds) so the database is not queried on every page load.

---

### Generate rule drafts from order history (offline AI workflow)

SmartCart can mine your order history to find products that are frequently bought together, then generate pending draft rules for you to review. AI is optional - mining and draft creation work without a provider configured.

#### How to set it up

1. Go to:
   Stores > Configuration > Moogento > SmartCart > Setup: AI-Powered SmartCart Rules

2. Set:
   - Enable: AI-Powered Rule Generation = Yes
   - Provider: AI Service - select your preferred provider if you want AI-enhanced tagging; leave as None for mining-only workflow
   - Credentials: API Key - paste the API key from your provider's console (only required if a provider is selected)

3. Save Config.

![SmartCart AI-Powered SmartCart Rules configuration group](images/config-ai.png)

4. From the server command line, run the mining and draft generation sequence:

```
php bin/magento smartcart:mine:associations --since=90 --min-support=3
php bin/magento smartcart:tag:products --batch=50   # optional, requires AI provider
php bin/magento smartcart:generate:drafts --min-confidence=0.1
```

5. Go to **Moogento > SmartCart > Drafts**. Review each pending draft - you'll see the trigger, pool, copy, evidence (pair count, confidence, lift), and source. Click **Approve** to create a live rule, or **Reject** to discard it.

#### Notes

- Mining requires qualifying orders (status `processing` or `complete`) containing two or more distinct products. Stores with few multi-product orders may produce few associations.
- Association mining runs weekly on a cron schedule (by default Sunday at 4 AM). The rule-generation pipeline (mine → tag → generate drafts) then runs Monday at 5:15 AM, with a change-detection guard that skips weeks with no new orders or products - no need to re-run the CLI commands each week.
- AI tagging enriches draft copy (helper text) but is not required for the pipeline to work. Even without a provider, mined rules produce useful draft rules.

---

## Features reference

### Setup: Placements

Controls where add-on suggestions appear for shoppers. Each zone can be enabled or disabled independently.

- Cart Page (default Yes) - recommendations appear below the main cart form; highest visibility and conversion
- Mini-Cart (default No) - compact suggestions in the slide-out mini-cart; good for impulse adds
- Checkout Sidebar (default No) - last-chance prompts alongside the order summary before purchase

Config path: Stores > Configuration > Moogento > SmartCart > Setup: Placements (`moogento_smartcart/placement/`)

![SmartCart Placements configuration group](images/config-placement.png)

---

### Setup: Compatibility Constraints

Filters suggestions so that only products compatible with what's already in the cart are shown. Each row in the Compatibility Rules table specifies a product attribute and a match mode: `must_match` (candidate shares the attribute value with a cart item), `must_differ` (candidate has a different value), or `any` (no constraint on that attribute).

- What it does: prevents recommending, for example, a US-spec accessory when the cart contains a UK-spec product
- When to use it: stores with region-specific or voltage-specific products where mismatched accessories would be a poor experience

Config path: Stores > Configuration > Moogento > SmartCart > Setup: Compatibility Constraints (`moogento_smartcart/compatibility/`)

---

### Setup: Dismissal Memory

When a shopper closes a suggestion, SmartCart remembers it so the same tile does not keep reappearing. Dismissal state is stored in browser localStorage (per shopper, per store, per rule).

- Remember: Dismissed Offers (hours, default 24) - how long a dismissed offer stays hidden
- Set to a higher value (e.g. 168 for one week) for products with long purchase cycles
- Dismissed offers clear automatically when the TTL expires - no admin action needed

Config path: Stores > Configuration > Moogento > SmartCart > Setup: Dismissal Memory (`moogento_smartcart/dismissal/ttl_hours`)

---

### Setup: Event Tracking

Records impressions (50% visible for 250ms), clicks, dismissals, add-to-carts, and purchases per rule. Once enabled, the Rules grid shows 30-day stats columns - Shown, Adds, Orders, Revenue, Add Rate, Purchase Rate, and Dismiss Rate - updated every 15 minutes.

- Enable: Event Tracking = Yes to start collecting data
- Retention: Tracking Data (days, default 90) - events older than this are auto-deleted by a daily cron

Config path: Stores > Configuration > Moogento > SmartCart > Setup: Event Tracking (`moogento_smartcart/tracking/`)

---

### Setup: Security

Holds the auto-generated context hash key used to sign cart context payloads. The key is created on first use - you do not need to set it manually.

- Secret: Context Hash Key - a 64-character key auto-generated on first use. Changing it invalidates all in-flight event hashes immediately; only change it if you have reason to believe the key is compromised.
- Grace Window: Accept Legacy Hashes Until - a Unix timestamp. If you rotate the key, set this to a future timestamp to accept old hashes during the transition window. Leave at 0 to require signed hashes immediately after a key change.

Config path: Stores > Configuration > Moogento > SmartCart > Setup: Security (`moogento_smartcart/security/`) - global scope only

---

## Advanced configuration

### Offline AI rule generation pipeline

The offline tooling layer mines your order history for frequently co-purchased product pairs, optionally enriches them with AI-generated semantic tags, and proposes draft rules. Nothing in this layer touches the storefront runtime.

#### What it does

1. **Association mining** (`smartcart:mine:associations`) reads qualifying orders in batches of 500, counts product co-occurrences, and calculates confidence and lift scores. Results land in the database.
2. **Product tagging** (`smartcart:tag:products`) sends product names, SKUs, and descriptions to the configured AI provider and stores semantic tags for each product. This step is optional but improves draft helper-text quality.
3. **Draft generation** (`smartcart:generate:drafts`) combines associations and tags into pending draft rules. Each draft shows the mined evidence so you can judge whether it's worth approving.

Association mining runs weekly on a cron schedule (by default Sunday at 4 AM). The rule-generation pipeline (mine → tag → generate drafts) then runs Monday at 5:15 AM, with a change-detection guard that skips weeks where no new orders or products exist.

#### Setup

1. Enable AI-Powered Rule Generation in:
   Stores > Configuration > Moogento > SmartCart > Setup: AI-Powered SmartCart Rules

2. Optionally select an AI Provider and paste the API key.

3. Run the pipeline manually for the first time:
   ```
   php bin/magento smartcart:mine:associations --since=90 --min-support=3
   php bin/magento smartcart:generate:drafts --min-confidence=0.1
   ```

4. Review drafts at **Moogento > SmartCart > Drafts**.

5. Click **Generate: Rules Now** in the config section to re-run at any time without SSH access.

#### Notes

- AI is **never** called during runtime recommendation generation - only the CLI commands and the weekly cron invoke external AI APIs.
- Associations require orders with 2+ distinct products and status `processing` or `complete`. Fewer than 3 orders sharing a pair (the `--min-support` default) produce no association rows.
- `--min-confidence=0.1` means "at least 10% of orders containing product A also contained product B". Raise this for higher-confidence suggestions; lower it to see more (but noisier) drafts.
- The Generate button in admin (`Setup: AI-Powered SmartCart Rules > Generate: Rules Now`) runs the same pipeline in force mode, bypassing the change-detection skip. Use it after adding a new product range or importing a batch of orders.

---

## Tips & best practices

- Start with 1–2 rules covering your highest-volume cart scenarios before scaling up. Check 30-day stats before creating more - rule quality matters more than quantity.
- Keep Maximum Offers at 2. Showing 3 or more offer tiles increases visual noise and typically reduces conversion on each individual tile.
- Set a cache TTL of at least 300 seconds in production. A TTL of 0 runs the full pipeline on every cart page load and adds latency.
- Use priority numbers with gaps (10, 20, 30) so you can insert new rules between existing ones without renumbering.
- Enable event tracking from day one. The 30-day stats columns on the Rules grid are the fastest way to tell which rules are worth keeping.
- If a rule's dismiss rate is consistently above 40–50%, the pool is probably too broad or the product is not a good fit for that trigger. Narrow the pool or revise the trigger.
- Use the Disable: When Coupon Applied toggle if your promotions already offer a clear incentive - adding an upsell alongside a coupon code can feel pushy and reduce trust.
- Run association mining against 90 days of orders first. If your catalogue changes seasonally, re-run after each season ends.
- Approve AI-generated drafts selectively. Check the evidence column - pair count below 5 or confidence below 15% usually means a weaker association. Reject freely.

---

## Troubleshooting

### No recommendations appear on the cart page

- Cause: Module is disabled, no active rules exist, or placement is off
- Check: Stores > Configuration > Moogento > SmartCart > General > Enable = Yes
- Check: Stores > Configuration > Moogento > SmartCart > Setup: Placements > Show: Cart Page = Yes
- Check: Moogento > SmartCart > Rules - at least one rule must be enabled and scoped to the current store

### Recommendations appear but never include a specific product

- Cause: The product is filtered out by a guardrail
- Check: The product is in stock and salable
- Check: The product SKU is not in Excluded: Product SKUs (`moogento_smartcart/eligibility/excluded_skus`)
- Check: The product's category is not in Excluded: Categories (`moogento_smartcart/eligibility/excluded_categories`)
- Check: The product is not already in the shopper's cart (SmartCart never suggests items already in cart)
- Check: If history suppression is enabled, the shopper may have purchased the product before

### A dismissed offer keeps coming back after the browser is refreshed

- Cause: The dismissal TTL has expired, or localStorage is being cleared between sessions
- Check: Stores > Configuration > Moogento > SmartCart > Setup: Dismissal Memory > Remember: Dismissed Offers - increase the value if needed
- The dismissal key includes the context hash - if the cart changes (a different item is added), the context hash changes and dismissed offers may reappear

### Rule stats columns show zeros even though the module is active

- Cause: Event tracking is disabled
- Check: Stores > Configuration > Moogento > SmartCart > Setup: Event Tracking > Enable: Event Tracking = Yes
- Note: Stats aggregate on a 15-minute cron. Allow up to 15 minutes after enabling before expecting data

### Mining produces no associations or drafts

- Cause: Not enough qualifying orders, or minimum support threshold is too high
- Check: Orders must have status `processing` or `complete` and contain 2+ distinct products
- Try: Lower `--min-support` to 2, or extend `--since` to 180 days
- Check: `var/log/moogento_smartcart.log` for pipeline output

### AI provider returns no results or a 401

- Cause: API key is missing, wrong provider selected, or key does not match the provider
- Check: Stores > Configuration > Moogento > SmartCart > Setup: AI-Powered SmartCart Rules - verify Provider and API Key match
- Check: `var/log/moogento_smartcart.log` - the error from the provider API is logged there
- Note: Changing the provider requires a matching API key - a key issued for OpenAI will not work if Provider is set to Anthropic

---

## FAQs

<!-- seo: FAQPage schema - the page converter should emit JSON-LD for this section -->

### How do I add product recommendations to my Magento 2 cart?

Install SmartCart, create at least one recommendation rule under Moogento > SmartCart > Rules, and enable the module at Stores > Configuration > Moogento > SmartCart > General. Offers appear automatically on the cart page without any template changes.

### Why are no recommendations showing even though the module is enabled?

SmartCart needs at least one active rule whose trigger matches the current cart contents. Go to Moogento > SmartCart > Rules and confirm a rule is enabled, scoped to the right store view, and that the trigger SKU, category, or attribute is present in the shopper's cart. See [Troubleshooting](#troubleshooting) for a full checklist.

### Can I show add-on suggestions in the mini-cart or during checkout?

Yes - SmartCart supports three independent placement zones: the cart page, the mini-cart slide-out, and the checkout sidebar. Enable each one at Stores > Configuration > Moogento > SmartCart > Setup: Placements. Mini-cart and checkout placements use a compact tile layout without product images.

### How does SmartCart choose contextual cart recommendations?

SmartCart evaluates your active rules in priority order against the current cart contents. Each rule has a trigger (which products or categories must be in the cart) and a pool (which products to suggest). Only in-stock, eligible, and compatible candidates from the winning rules are shown. See [Create a manual recommendation rule](#create-a-manual-recommendation-rule) for how to build rules.

### Does SmartCart work with Hyvä, Luma, or Porto themes?

SmartCart is compatible with Luma and Porto themes out of the box. For Hyvä, the module requires the Hyvä compatibility layer - check the Moogento.com plugin page or contact moo@moogento.com to confirm compatibility with your specific Hyvä version before installing.

### Will shoppers keep seeing a suggestion for something they already bought?

Not if you enable purchase history suppression. Set Stores > Configuration > Moogento > SmartCart > Setup: Purchase History > Enable: Purchased Product Suppression = Yes and SmartCart will automatically skip products the shopper has ordered before. See [Use purchase history suppression](#use-purchase-history-suppression-to-avoid-re-suggesting-owned-products) for setup steps.

### Can I hide recommendations when a discount code is applied?

Yes. Set Stores > Configuration > Moogento > SmartCart > Setup: Eligibility Rules > Disable: When Coupon Applied = Yes. All recommendations will be hidden for that cart session while a coupon code is active.

### How much does SmartCart cost and do I need a paid plan?

SmartCart is a paid Moogento plugin. Pricing and plan details are on the Moogento.com plugin page. You need a valid license key (entered at Stores > Configuration > Moogento > Licenses) for the module to remain active.

### What happens if I disable SmartCart?

When Enable is set to No, no recommendations are fetched or displayed on the storefront. Existing rules, drafts, and event data are preserved. Re-enabling the module restores normal operation - no reconfiguration needed.

### How do I know which recommendation rules are performing best?

Enable event tracking at Stores > Configuration > Moogento > SmartCart > Setup: Event Tracking, then check the Rules grid at Moogento > SmartCart > Rules. The grid shows 30-day impressions, add rate, purchase rate, and revenue per rule, updated every 15 minutes.

---

## Related guides

- [Pulse](../pulse) - real-time dashboard with a SmartCart ecosystem widget showing add-on performance at a glance
- **ProfitEasy** - revenue attribution reports with a dedicated SmartCart source bucket

---

## Need help?

- moo@moogento.com
- Include:
  - Magento version
  - Module name
  - What you're trying to do

