Orchardcore marketing

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore marketing is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the CrestApps Orchard Core Marketing commerce module and how it works with checkout coupons and discounts. Covers CustomerPurchases kept per customer from paid and refunded orders, the purchases backfill, Segment rules by orders, spend, recency and country, Liquid email Campaigns sent thro

How to use this skill

Skill file

Orchard Core Marketing - Prompt Templates

Email the Store's Customers

You are an Orchard Core expert. Generate accurate setup and extension guidance for the CrestApps Marketing module, which keeps what each customer has bought, groups customers into segments, and sends Liquid email campaigns to a segment's customers who accept marketing.

Guidelines

Feature and Services

| Item | Value |

|---|---|

| Feature ID | CrestApps.OrchardCore.Marketing |

| YesSql collection | Marketing |

| Records | CustomerPurchases (CustomerPurchasesIndex), Segment (SegmentIndex), Campaign (CampaignIndex), PurchasesBackfill |

| Stores | ICustomerPurchasesStore, ISegmentStore, ICampaignStore |

| Services | CustomerPurchasesService (RecordAsync, BackfillAsync), CampaignService (CanSendAsync, RenderAsync, SendTestAsync, StartSendingAsync, CancelAsync, CountAsync) |

| Order seam filled | IOrderEventHandler (CustomerPurchasesOrderHandler) |

| Background task | MarketingBackgroundTask (every minute) |

| Unsubscribe | GET and POST marketing/unsubscribe?token= (MarketingUnsubscribe route and shape) |

| Permission | ManageMarketing (Administrator, Store manager, Marketing) |

| Admin | Commerce > Segments (marketing/segments), Commerce > Campaigns (marketing/campaigns) on the AdminList standard |

Enable the Feature

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Email",
        "CrestApps.OrchardCore.Customers",
        "CrestApps.OrchardCore.Orders",
        "CrestApps.OrchardCore.Marketing"
      ],
      "disable": []
    }
  ]
}

Customers' Purchases

CustomerPurchases (its id is the customer's) holds OrderCount, TotalSpent (paid orders less refunds, in the store currency, converted with IShopperCurrency), FirstOrderUtc, LastOrderUtc, Country (the last order's billing or shipping country), and OrderIds and RefundIds that make recording idempotent.

Segments

Segment has a Name, Description and SegmentRules. Every rule given must hold, on customers with at least one order.

| Rule | Meaning |

|---|---|

| MinOrders, MaxOrders | Order count range |

| MinSpent, MaxSpent | Lifetime spend range in the store currency |

| LastOrderAtLeastDaysAgo | Lapsed buyers |

| LastOrderWithinDays | Recent buyers |

| FirstOrderWithinDays | New customers |

| Country | Last order's country |

ICustomerPurchasesStore.ListAsync(rules, utcNow, afterId, take) pages a segment by document id, so customers added while a campaign sends come after the cursor. CountAsync counts a segment; the segment editor shows its customers and how many accept marketing (up to 10,000).

Campaigns

Campaign holds Name, SegmentId, Subject and Body (Liquid), Status (Draft, Scheduled, Sending, Sent, Canceled), ScheduledUtc, the Cursor, and Sent, Skipped and Failed counts.

Liquid values:

| Value | Content |

|---|---|

| Customer | CampaignCustomer: FirstName, LastName, Name, Email, OrderCount, TotalSpent, LastOrderUtc |

| StoreName | The site's name |

| UnsubscribeUrl | The customer's own unsubscribe link. One is appended when the body has none |

<p>Hi {{ Customer.FirstName }},</p>
<p>It has been a while since your last order at {{ StoreName }}.
Use <strong>COMEBACK15</strong> for 15% off your next order.</p>
<p><a href="{{ UnsubscribeUrl }}">Unsubscribe</a></p>

Campaigns are sent by the Outreach engine. MarketingBackgroundTask starts a scheduled campaign when ScheduledUtc passes, and CampaignService.StartSendingAsync hands it to the engine as an outreach run (Campaign.OutreachRunId): the MarketingSegment audience source pages the segment 50 customers at a time from the cursor (skipping customers who are not Active, do not accept marketing or have no email), the engine checks consent (Email, as a Customer) before each email so a mid-run unsubscribe stops it, the MarketingCampaign renderer adds the unsubscribe link, and the Email sender sends HTML plus a text part. The run's counts and cursor are copied back; the campaign is Sent when the run completes, or Canceled when a batch keeps failing (for example the Base URL was removed). Canceling a campaign stops its run, and a campaign half sent before the engine resumes at its cursor. Until a default email provider is configured, CanSendAsync is false and the editor says so instead of queuing. The campaign editor's test send renders the message as the segment's first customer would get it.

Recipes and deployment

The Marketing segments and campaigns deployment step (Commerce) writes a MarketingSegments step, then a MarketingCampaigns step. Both match by ItemId and are validated like their editors. A recipe never sends email: a campaign is exported without its delivery state, a new campaign always imports as a draft, and a campaign scheduled or sending on the site is left alone.

{
  "steps": [
    {
      "name": "MarketingSegments",
      "Segments": [
        { "ItemId": "4sg00000000000000000000001", "Name": "Lapsed buyers", "Rules": { "MinOrders": 1, "LastOrderAtLeastDaysAgo": 180 } }
      ]
    },
    {
      "name": "MarketingCampaigns",
      "Campaigns": [
        { "ItemId": "4cp00000000000000000000001", "Name": "Win back", "SegmentId": "4sg00000000000000000000001", "Subject": "We miss you", "Body": "Come back for 10% off." }
      ]
    }
  ]
}

Unsubscribing

UnsubscribeController serves marketing/unsubscribe?token=. The token is the customer id protected by a time-limited data protector (400 days). A POST turns AcceptsMarketing off and needs no antiforgery token, so mail apps' one-click unsubscribe works.

Coupons and Discounts for Campaigns

Discount codes come from Checkout's coupon catalog (orchardcore-checkout), which applies discounts before tax and spreads them across item lines so each line is taxed on what the buyer pays. Useful pairings with a campaign:

Ship coupons between sites with Checkout's Coupons recipe step:

{
  "steps": [
    {
      "name": "Coupons",
      "Coupons": [
        { "Code": "COMEBACK15", "Description": "Lapsed buyer campaign", "Kind": "Percentage", "Percentage": 15, "MaxRedemptionsPerCustomer": 1, "EndsUtc": "2027-03-01T00:00:00Z", "IsEnabled": true }
      ]
    }
  ]
}

Related Modules

Monitoring

MarketingBackgroundTask reports on the shared crestapps.background_task.* instruments (CrestApps.OrchardCore.Platform meter): items started and not_started per campaign, and skipped when the site has no base URL. The sends themselves run through Outreach (orchardcore-outreach).

Troubleshooting

| Symptom | Check |

|---|---|

| Campaign cannot be sent, or ends Canceled | Configure a default Orchard Core email provider and the site Base URL; check the outreach run |

| Segment counts zero | Purchases are still backfilling (200 orders a minute), or no customer matches every rule |

| Many customers skipped | They are not Active, do not accept marketing, or have no email |

| Unsubscribe link fails | The token is older than 400 days, or the link was altered |

| A code in the campaign is refused | Check the coupon's dates, limits, scope and currency in Commerce > Coupons |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.