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:
Field | Type |
---|---|
product | int |
selected_configurable_option | int |
related_product | int |
item | int |
form_key | string |
qty | int |
Example:
Subscribe Pro Fields
The Subscribe Pro Magento 2 extension adds the following two fields to the above form data:
Field | Type | Description |
---|---|---|
subscription_option[option] | string | Either subscription or onetime_purchase , depending on what the customer selects on the PDP. |
subscription_option[interval] | string | One 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: