Custom Add-to-cart Implementation


When adding a subscription item to the cart, the Subscribe Pro extension adds two fields to the form data in the POST request to https://yourstore.com/checkout/cart/add/uenc/{encoded_url}/product/{product_id}/.

Using a standard Magento 2 implementation and Subscribe Pro's extension, this works out-of-the-box. However, when using a headless approach (such as the Hyva theme), some additional effort is required to include these fields.

Default Behavior

By default, Magento adds the following fields when clicking the "Add to Cart" button on the PDP of a simple product:

FieldType
productint
selected_configurable_optionint
related_productint
itemint
form_keystring
qtyint

Example:

Form data for non-subscription item

Subscribe Pro Fields

The Subscribe Pro Magento 2 extension adds the following two fields to the above form data:

FieldTypeDescription
subscription_option[option]stringEither subscription or onetime_purchase, depending on what the customer selects on the PDP.
subscription_option[interval]stringOne of the subscription frequency intervals configured in the Merchant App under System > Subscription Intervals (e.g. 2 Weeks) that the customer selects on the PDP.

Example:

Form data for subscription-enabled item