Skip to content

Product Alerts

Module: Magenx_ProductAlertGraphQl · no settings of its own

Magento’s stock Product Alerts feature emails customers when a product’s price drops or it comes back in stock. Stock Magento offers it only to its own theme. This module brings it to the headless storefront: Notify me buttons on the product page, and a list of subscriptions in the customer account.

Alerts page in the customer account: price drop alerts and back-in-stock alerts, one card per watched product
Price and stock alerts in the customer account.
  • Only signed-in customers can subscribe.
  • Subscriptions are per website.
  • Emails are still sent by Magento’s own product alert cron. Nothing about the emails changes.
  • In the account, each alert shows Active until the email is sent, then Sent with the date. Price alerts also show the price at subscription and the current price.

Product alerts use Magento’s stock settings in Stores > Configuration > Catalog > Catalog > Product Alerts:

  • Allow Alert When Product Price Changes
  • Allow Alert When Product Comes Back in Stock

When a type is off, the storefront hides its button, and subscribing to it is refused.

Subscribe on the product page

  1. The storefront shows only alert types that are on.
  2. It reads the customer's state for the product.
  3. The customer subscribes; the response returns the new state; subscribing again changes nothing.

Unsubscribe

  1. The customer unsubscribes from the product page or the account list.
  2. The alert is removed for the current website; removing a missing alert is not an error.

Account list

  1. The account shows price and stock alerts with product details, date added, status and, for price alerts, recorded price, current price and difference.
  2. Products no longer available show as empty.

Notification

  1. The store's alert job sends the email and records when; the status becomes Sent.

These always hold:

  • At most one alert per customer, product, type and website.
  • Customers only read and change their own alerts; identity from the session.
  • Alerts created here are identical to alerts created any other way, so the existing job and admin keep working.
  • Price difference = recorded price − current price.
  • Status = Sent when a send date exists, else Active.
SituationWhat happens
Guest subscribes.Not authorised.
Subscribe twice.One alert.
Unsubscribe without an alert.No error.
Price alerts off.Subscribe refused; flag off.
Product deleted after subscribing.Item with empty product and empty current price.
Same customer, two websites.Alerts kept and listed per website.
  • Signed-in customers; products sold on the request's website.
  • Guest alerts by email address.
  • Alerts for a target price chosen by the customer.
  • Other channels (SMS, push).
  • Changes to alert emails or their schedule.
Terminal window
composer require magenxcommerce/module-product-alert-graph-ql
bin/magento module:enable Magenx_ProductAlertGraphQl
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.

No database changes: it uses Magento’s own product alert tables.

productAlertStatus gives the subscription state for one product, for the product page buttons. Only select product_alerts on the subscribe output when you need the whole list: it loads every subscribed product.

Queries

productAlertStatus(product_sku: String!): ProductAlertStatusOutput

Whether the logged-in customer is subscribed to price-drop and back-in-stock alerts for a product. Customer token required.

ArgumentTypeDescription
product_skuString!The SKU of the product to check.

Mutations

productAlertSubscribe(input: ProductAlertSubscriptionInput!): ProductAlertSubscriptionOutput

Subscribe the logged-in customer to a price-drop or back-in-stock alert for a product.

ArgumentTypeDescription
inputProductAlertSubscriptionInput!The product and alert type to subscribe to.
productAlertUnsubscribe(input: ProductAlertSubscriptionInput!): ProductAlertSubscriptionOutput

Remove a price-drop or back-in-stock alert subscription for the logged-in customer.

ArgumentTypeDescription
inputProductAlertSubscriptionInput!The product and alert type to unsubscribe from.

Fields added to Magento types

FieldTypeDescription
Customer.product_alertsProductAlertsThe logged-in customer's price and stock product alert subscriptions.
StoreConfig.product_alert_allow_priceBooleanWhether price-drop alerts are enabled for the store (Catalog > Product Alerts).
StoreConfig.product_alert_allow_stockBooleanWhether back-in-stock alerts are enabled for the store (Catalog > Product Alerts).

Types

type ProductAlertStatusOutput - The logged-in customer's alert subscriptions for one product.
FieldTypeDescription
product_skuString!The SKU that was checked.
is_price_alert_subscribedBoolean!Whether the customer is subscribed to a price-drop alert for the product in the current website.
is_stock_alert_subscribedBoolean!Whether the customer is subscribed to a back-in-stock alert for the product in the current website.
input ProductAlertSubscriptionInput - Identifies the product and the kind of alert.
FieldTypeDescription
product_skuString!The SKU of the product the alert is for.
alert_typeProductAlertType!Whether the alert is for price drops or back-in-stock notifications.
enum ProductAlertType - The kind of product alert.
ValueDescription
PRICE
STOCK
type ProductAlertSubscriptionOutput - The result of a product alert subscription change.
FieldTypeDescription
product_skuString!The SKU of the product the change applied to.
alert_typeProductAlertType!The kind of alert that was changed.
is_subscribedBoolean!Whether the customer is now subscribed to this alert. Cheap; prefer it over product_alerts when only this product's state is needed.
product_alertsProductAlerts!The logged-in customer's full product alert subscription list after the change. Loads every subscribed product, so only select it when the whole list is needed.
type ProductAlerts - A customer's price-drop and back-in-stock product alert subscriptions.
FieldTypeDescription
price_alerts[ProductAlertEntry!]!Active price-drop alert subscriptions.
stock_alerts[ProductAlertEntry!]!Active back-in-stock alert subscriptions.
type ProductAlertEntry - A single product alert subscription.
FieldTypeDescription
idInt!The unique ID of the alert subscription.
alert_typeProductAlertType!Whether this is a price-drop or back-in-stock alert.
productProductInterfaceThe product the alert is for. Null if the product is no longer available.
priceFloatFor price alerts, the product price recorded when the subscription was created.
current_priceFloatFor price alerts, the product's current price. Null for stock alerts or if the product is no longer available.
price_diffFloatFor price alerts, the recorded price minus the current price. Positive when the price has dropped since subscribing. Null for stock alerts or if the product is no longer available.
add_dateString!The date the subscription was created.
statusProductAlertStatus!Whether the alert notification has already been sent to the customer.
status_changed_atStringThe date the alert notification was last sent, i.e. when the status changed to SENT. Null while the alert is still ACTIVE.
enum ProductAlertStatus - The state of a product alert subscription.
ValueDescription
ACTIVE
SENT
TermMeaning
Price alertNotifies when the price drops below the price recorded at subscription.
Stock alertNotifies when the product is back in stock.
StatusActive until the notification is sent, then Sent.
Recorded pricePrice stored when subscribing.
Price differenceRecorded price − current price; positive once the price dropped.
Website scopeAlerts are kept per website; the request's store view decides which.