Marketing: product feeds and the newsletter
The Marketing module builds product feeds (PLAN › Product feeds) and keeps the newsletter's consent.
Product feeds
feeds(Models\Feed): name,preset(Data\FeedPreset: google, meta, tiktok, compari, csv, json), a random 40-charactertoken,locale,currency,category_ids(null: everything),in_stock_only,utm_source,is_active, and what the last build left:generated_at,items,skipped(countsby reason, up to 100examples),bytes,error.Feeds\BuildFeedreadsCatalog\Contracts\FeedCatalog::after(afterId, limit, locale, categoryIds)200 products at a time (active,CatalogViewer::public(), plain-text descriptions cut at 5,000 characters, large image URLs, category path), prices each variant withPricing\Contracts\PricesinPriceContext::retail(currency), asksPromotions\Contracts\Offersfor running price cuts, andInventory\Contracts\Stock::available()for physical variants. The item's price is the list price; a lower public price list or price cut becomes the sale price (with the cut's dates). Gate: GTIN, or brand and MPN; an image; a description; a price (reasonsidentifier,image,description,price, plusout_of_stockfor in-stock-only feeds). Items stream through aFeeds\FeedWriter(GoogleWriter, which also serves Meta and TikTok with "in stock" spelling;CompariWriter;CsvWriterwith the formula guard;JsonWriter;ChatGptWriter, OpenAI's product feed schema as JSON Lines:is_eligible_searchtrue,is_eligible_checkoutfalse,target_countries/store_countryRO,seller_namefromShopCompany, policy URLs fromPages::legal(),group_idprefixedproduct-so it never equals anitem_id) tofeeds/{id}.{ext}.tmpon the local disk, renamed over the old file when complete. A failure keeps the old file and recordserror.- Links:
store.{locale}.productwithvarianta(several variants),utm_source(feed's or the preset's) andutm_medium=feed. marketing:feedsbuilds every active feed (04:00);--changed(every 15 minutes) only feeds built before the last change:Listeners\MarkFeedsStalestores the time ofCatalogPageChanged(products) andVariantPriceChangedin the cache, andInventory\Contracts\Stock::lastChange()gives the neweststock_levels.updated_at.- Admin:
Http\Controllers\FeedController(admin.feeds.*,feeds.manage); saving, editing and rebuild now dispatchFeeds\BuildFeedJob(unique per feed). Changing the preset deletes the old file. - Public:
GET /feeds/{token}.{xml|csv|json}(marketing.feed,Http\Controllers\PublicFeedController), outside thewebgroup (no session or cookies), throttled,X-Robots-Tag: noindex,Cache-Control: public, max-age=900.
Not built yet: pushing deltas through the Merchant Center Content API (needs the shop's Google credentials) and Meta's Conversions API.
Newsletter
newsletter_subscribers(Models\Subscriber: e-mail unique case-insensitively,locale,statusData\SubscriberStatuspending | subscribed | unsubscribed,source,customer_id, a UUIDtokenrenewed with each request,requested_at,confirmed_at,unsubscribed_at,synced_at,sync_error) andnewsletter_events(Models\SubscriberEvent: requested | confirmed | unsubscribed, source, HMAC of the IP with the app key, thewordingagreed to; append-only by trigger).Contracts\Newsletter(Newsletter\DatabaseNewsletter):subscribe(email, locale, source, ip, customerId, proven)(a proven address, a signed-in shopper's own verified one, is subscribed at once; otherwise pending andSubscriptionRequested),confirm(token, ip)(pending, within 7 days),unsubscribe(token, ip),unsubscribeEmail(email, source),find*. Confirming and leaving raiseSubscriberChanged; erasure raises it with only the address.Contracts\NewsletterDriver(subscribe(email, locale, name, consentedAt),unsubscribe(email)), driver familynewsletter:Drivers\Newsman\NewsmanDriver(API 1.2 REST, user id and key in the path, form posts tosubscriber.saveSubscribe.json/subscriber.saveUnsubscribe.json,{err, message}errors,list.allfor the connection test),Drivers\Klaviyo\KlaviyoDriver(revision2024-10-15, bulk subscribe job withhistorical_importandconsented_at, bulk delete job to unsubscribe,GET /lists/{id}to test),DemoNewsletterDriver(registered, counts in the cache) andFakeNewsletterDriver(tests). Neither log keeps the address or the key.Listeners\SyncChangedSubscriberqueuesJobs\SyncSubscriber(5 tries) for every enabled service.- Storefront:
StoreContext::newsletter()(a service on) shows the footer form (newsletter.store), the checkout box (newsletterin the checkout input,CheckoutController::joinNewsletter()after placing) and the account switch (account.newsletter);newsletter/{token}(NewsletterController) shows the page and confirms or unsubscribes only by POST.Listeners\SendNewsletterConfirmationsendsNewsletterMail, at most three a day per address (RateLimiter, keyed by a hash of it). Impersonating staff cannot subscribe or unsubscribe for the customer. - Admin:
Http\Controllers\NewsletterController(admin.newsletter.*,newsletter.manage): list with counts, subscriber page with the events, unsubscribe on request and CSV export (both in the activity log). Privacy\NewsletterPersonalData(by customer id or the account's address) andPrivacy\NewsletterRetention(pending after 30 days, unsubscribed 3 years after).
Not built: reading unsubscriptions made in the newsletter service back into the shop (the service stops writing to them on its own).
Tests: tests/Feature/Marketing/FeedsTest.php, tests/Feature/Marketing/NewsletterTest.php.