Skip to content

Auto Product Links

Module: Magenx_AutoProductLinks

Fills Magento’s Related Products, Up-Sells and Cross-Sells from rules you edit, every night. It also adds a Frequently Bought Together link, mined from what customers really bought in the same orders. The product page rails and cart suggestions fill themselves.

Related and frequently bought together rails on a product page
Product page rails filled by rules.

Install adds one active rule per link type, so the first cron run links the whole catalog with nothing to set up:

RuleShown asPicks
Related“You May Also Like”The cheapest products in the same category.
Up-Sells“We Also Recommend”The most expensive products in the same category.
Cross-SellsCart suggestionsA random pick from the 50 cheapest products in the catalog.
Frequently Bought Together“Frequently Bought Together”Products most often bought in the same orders.

“Same category” means the product’s most specific category: a shirt in both Men and Men > Shirts is matched against Shirts only.

Random picks are stable: a product keeps the same cross-sells night after night until its candidates change.

Rules live in Marketing > Promotions > Auto Product Link Rules.

Auto Product Link Rules grid in the admin with the four default rules: what each fills, how it chooses products, its priority and how many links it created
Marketing > Promotions > Auto Product Link Rules, with the four default rules.

A rule has:

PartMeaning
FillsRelated, Up-Sells, Cross-Sells or Frequently Bought Together.
Apply this rule to these productsWhich products get links. The standard condition editor, as on a Catalog Price Rule.
Link to these productsThe pool of candidates.
Choose products bySimilar products, Bought together, or Random products.
Must match the source product onAttributes a candidate must share (colour, size, brand…), plus “shares a category” and “price band”.
Price band (%)For example 20: within ±20% of the product’s price.
Maximum links per productCap on automatic links.
Show bestHow candidates are ranked before the cap.
Randomly pick from the bestOptional: a stable random pick from the best N.
PriorityLower runs first.

A Frequently Bought Together rule must choose by Bought together. Any other link type can use any method.

Rules of one link type run in priority order, and each product has one owning rule per link type: the first rule that finds links for it. A rule that finds nothing leaves the product to the next rule. That is how the default rules (priority 1000) fill whatever your own rules (priority 0) leave empty.

When a product stops matching any rule, or its rule is switched off, its automatic links are removed. A rule that fails keeps its existing links.

Run Now on a rule runs every rule of its link type, because ownership depends on the rules above it.

  • Related: similar products, matching colour and sharing a category, best sellers first.
  • Up-Sells: similar products, sharing a category, price band 60, target “price greater than…”, most expensive first.
  • Cross-Sells: random products from an Accessories category, cheapest first, randomly picked from the 30 cheapest.
  • Links are global. Magento product links have no store, website or customer-group scope. A rule’s store view only chooses which prices, attributes and orders are read, not who sees the links.
  • New links need the purge chain (see Caching) to show right away. Without it the storefront shows cached rails until they expire.
  • Frequently Bought Together needs orders. The first run reads the whole look-back window. A store with little history gets few pairs.
  • Very large orders are skipped when mining (more than 50 lines by default): one huge order would drown ordinary baskets.
  • Run the mining job before the rules job, and the rules job after the catalog reindex.
  • A condition on an attribute the rule engine can’t use is skipped. Inside an “all” group that is harmless; inside an “any” group it can match fewer products than expected.
  • Use Dry Run to compute and log without writing. Runs are logged to var/log/magenx_auto_product_links.log.

First night

  1. After install, one default rule per link type exists at low priority, and the feature is on.
  2. Order mining counts co-purchase pairs over the look-back period.
  3. The rule run links the whole catalog: related = cheapest products in the same most specific category; up-sell = most expensive there; cross-sell = a stable random pick from the 50 cheapest products; frequently bought together = strongest pairs.

Merchandiser rule

  1. The merchandiser creates a rule at higher priority, e.g. related = same colour and same category, best sellers first, 8 links.
  2. "Run now" runs every rule of that link type; products the rule covers use it, the rest fall back to the defaults.

Hand curation

  1. A merchandiser adds a related link by hand.
  2. Nightly runs never touch it; it sorts before automatic links and does not count toward the cap.

Cleanup

  1. A product no rule covers any more (it left the conditions or its rule was switched off) loses its automatic links of that type after the run.
  2. A rule that errors keeps its existing links.

These always hold:

  • A link without a link record is never changed or deleted.
  • At most one owning rule per product and link type per run.
  • Automatic links per product and type ≤ the owning rule's cap.
  • Hand-made links always sort before automatic ones.
  • Random pick = order candidates by a hash of (rule, product, candidate); stable while candidates do not change.
  • Price band: candidate price within source price × (1 ± band %).
  • Co-purchase strength = number of orders within the look-back containing both products.
  • A run on unchanged data writes nothing and refreshes no cache.
  • Products not covered by custom rules fall back to the defaults.
SituationWhat happens
A rule picks a product already linked by hand.Not claimed; counted as "hand link skipped".
Product in "Men" and "Men > Shirts".Matched against "Shirts" only.
Target conditions match 300,000 products.Rule skipped; existing links kept.
A rule fails.Its links kept; other rules run.
An order with 200 lines.Excluded from mining.
Store with few orders.Few or no "bought together" links; no error.
  • All products; the rule's store view decides which attribute values, prices and orders are read, not who sees the links.
  • Real-time or personalised recommendations.
  • Different links per store view, website or customer group (links are global).
  • Machine-learning models beyond co-purchase counts and attribute matching.
  • Links on individual variants (links are made on the parent product).
Terminal window
composer require magenxcommerce/module-auto-product-links
bin/magento module:enable Magenx_AutoProductLinks
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
  • PHP ~8.4.0||~8.5.0, Magento 2.4.8.
  • Optional: magento/module-reports - Enables the default 'Best sellers first' ranking, which reads sales_bestsellers_aggregated_monthly. Without it that ranking degrades to the candidate pool's own order; every other ranking is unaffected.

To link immediately after install, open any rule and press Run Now.

Stores > Configuration > Magenx > Auto Product Links

General

Fills Related Products, Up-Sells, Cross-Sells and Frequently Bought Together from the rules under Marketing → Auto Product Link Rules. A default rule for each ships with the module, so the whole catalog is linked on the first cron run. Links the module writes are recorded in a ledger, so products you linked by hand are never moved, overwritten or deleted. Needs the magenx_auto_link_apply_rules cron running. Note: Magento stores product links globally — catalog_product_link has no store, website or customer-group column — so a rule's store setting only decides which store's attribute values, prices and orders are read, not who sees the resulting links.

SettingDefaultScopeNotes
Enable Auto Product Links
magenx_auto_product_links/general/enabled
YesStore viewYes/No. When disabled both cron jobs return immediately and nothing is written. Existing auto links stay in place.
Dry Run
magenx_auto_product_links/general/dry_run
NoStore viewYes/No. Shown when Enable Auto Product Links = Yes. Compute every change and write it to var/log/magenx_auto_product_links.log without touching the catalog.
Invalidate Product Cache After a Run
magenx_auto_product_links/general/invalidate_cache
YesStore viewYes/No. Shown when Enable Auto Product Links = Yes. Broadcasts a cat_p_<id> cache identity for every product whose links changed, which is what lets the headless storefront drop its cached related/up-sell/cross-sell rails immediately instead of waiting for its own TTL. Requires Full Page Cache in Varnish mode and a configured http_cache_hosts; without those nothing is broadcast and new links appear only when the storefront cache expires.
Default Maximum Links per Product
magenx_auto_product_links/general/max_links_default
12Store viewText. Shown when Enable Auto Product Links = Yes. Used when a rule leaves its own limit empty. Counts auto links only — links you added by hand are additive and never capped.
Auto Link Position Offset
magenx_auto_product_links/general/auto_position_base
1000Store viewText. Shown when Enable Auto Product Links = Yes. Auto links are numbered from this position upward, so hand-picked links (normally 1, 2, 3…) always sort ahead of them. Raise it if you position manual links above 1000.

Run Limits

Every run processes every product a rule matches; these only bound memory and transaction size.

SettingDefaultScopeNotes
Maximum Candidate Products per Rule
magenx_auto_product_links/limits/target_pool_cap
200000GlobalText. Shown when enabled = Yes. Caps the pool a rule's "Link To These Products" conditions may resolve to; an empty condition means the whole catalog. A rule over the cap is skipped with an error in the log and keeps its existing links.
Products per Batch
magenx_auto_product_links/limits/batch_size
100GlobalText. Shown when enabled = Yes. How many source products are written in one database transaction. Keep it small: catalog_product_link is read on every product page.

Co-Purchase Mining

Counts how often products were bought in the same order. This is what Frequently Bought Together (and any rule using the Bought together strategy) is built from. Counts are stored per month: the first run backfills the whole look-back window, after that only the current month (and briefly the previous one) is recomputed each night.

SettingDefaultScopeNotes
Look-back Window (months)
magenx_auto_product_links/copurchase/lookback_months
6GlobalText. Shown when enabled = Yes. How far back pair counts are kept and summed. Older months are pruned.
Minimum Orders per Pair
magenx_auto_product_links/copurchase/min_support
2GlobalText. Shown when enabled = Yes. Two products must have been bought together in at least this many orders before they count as a pair. 1 links anything ever bought together once; higher is stricter but needs more order history before anything shows.
Maximum Orders per Run
magenx_auto_product_links/copurchase/max_orders_per_run
100000GlobalText. Shown when enabled = Yes. Safety bound on the mining query. If a month holds more orders than this, the run processes what fits and says so in the log.
Skip Orders With More Lines Than
magenx_auto_product_links/copurchase/max_items_per_order
50GlobalText. Shown when enabled = Yes. The number of pairs an order produces grows with the square of its line count, so one very large order can dominate the whole aggregate. Orders above this many lines are ignored.

Cron

SettingDefaultScopeNotes
Co-Purchase Mining Schedule (cron expression)
magenx_auto_product_links/cron/copurchase_schedule
0 3 * * *GlobalText. Default "0 3 * * *". Must run before the rule job below.
Rule Run Schedule (cron expression)
magenx_auto_product_links/cron/rules_schedule
30 3 * * *GlobalText. Default "30 3 * * *". Schedule it after the co-purchase job and after the catalog reindex, so it works from current prices and a current aggregate.
  • Magento_CatalogRule::promo > Auto Product Link Rules

Grant these under System > Permissions > User Roles > Role Resources:

ResourceUnderID
Auto Product Link RulesMarketing > Magento_CatalogRule::promoMagenx_AutoProductLinks::rules
Auto Product Links SectionStores > Settings > ConfigurationMagenx_AutoProductLinks::config
JobGroupDefault scheduleChange it at
magenx_auto_link_mine_copurchasedefault0 3 * * *magenx_auto_product_links/cron/copurchase_schedule
magenx_auto_link_apply_rulesdefault30 3 * * *magenx_auto_product_links/cron/rules_schedule

Related, up-sell and cross-sell links are read through Magento’s stock fields with no change. Frequently Bought Together has its own field:

Fields added to Magento types

FieldTypeDescription
ProductInterface.frequently_bought_together_products[ProductInterface]Products most often bought in the same order as this one, mined from order history by Magenx_AutoProductLinks. Separate from crosssell_products, which are the merchant's cart add-on suggestions.
TermMeaning
Link typeRelated, up-sell, cross-sell, or frequently bought together.
RuleFills one link type: source conditions, target conditions, strategy, matching, ranking, cap, priority.
Source / target conditionsWhich products get links / which products may be linked.
StrategySimilar products (attribute match), bought together (co-purchase strength), random (stable pseudo-random).
Match criteriaAttributes a candidate must share with the source; "shares a category"; "within ±N% of price".
Most specific categoryThe deepest of a product's categories on each branch.
Link recordEntry noting that the feature wrote a given link.
Hand-made linkA link with no link record.
Owning ruleThe first rule, by priority, that produces links for a product and link type.
Co-purchase pairTwo products in the same order, counted per month.
SupportNumber of orders containing a pair.