How custom discount works
Checkout flow for discount apps
0. Merchant installs your app
Merchant will need to install your app in order for your custom discounts and settings to be shown.
Make sure you have a registered app with Ecwid with access to add a new shipping method. Get started with your app here: Begin development
1. Ecwid sends cart data to app request URL
The request to your app URL can be triggered by a customer in storefront or by an API request to order details calculation endpoint.
To apply new discounts for a cart in storefront, Ecwid will send a POST request to your endpoint with cart details: items, customer address, merchant app settings, etc.
For all of the cases below, your application should provide correct discount calculations for the total of cart information available to the application.
Customer in storefront
The request will be sent when the customer’s cart changes - a new product is added to cart, shipping address is changed, cart initialized, a product was added to a cart, a product removed from cart, the product’s options changed on cart page, cart was cleared, a discount coupon applied, selected shipping method changed, cart contents are synced, if there are a few browser tabs with the store are opened, etc.
Calculate order details API сall
The products and cart information itself can be different from what the store actually has. For example, some other application can create a custom storefront where it requests order calculation with items that are not present in the store.
2. Application returns discounts in a specific format
Ecwid will expect a response to its request from your service within 5 second interval to display additional discounts for an order. In the response, provide discount value, type of discount (percent or absolute) and discount description. See the response format in the Request and response section.
3. Ecwid displays discounts at checkout
Based on the response from your app, Ecwid will display the discounts for customers on the cart page. Customer can view the amount and the reason for a discount that your solution sent to Ecwid. All the discount details will be saved for that order and they will be displayed in related order information.
Custom discounts FAQ
Q: In what order does Ecwid calculate the order total?
Ecwid calculates the order total in this order:
- Order subtotal
- Coupon discount
- Handling fee
- Discounts (app discounts too)
Please keep this in mind when creating an app for Ecwid.
Q: What happens, if my URL responds with an error?
In case if your app responds with an error or in an incorrect format, then the discounts from your app will not be shown to customer at checkout stage and they will be able to shop in the store as usual. If your store has applicable discounts methods set up using the default means of creating discounts in Ecwid, then they will be shown to customer and applied to order.
Q: Does Ecwid cache the requests in any way?
Yes. Ecwid will not make a request to your URL on these conditions:
- previous request happened less than 5 minutes ago
- request details are exactly the same as in previous request
In other cases, Ecwid will make a new request to your endpoint.
For example, a new product was added to cart, shipping/payment method was changed, customer address was changed, etc.
Any event that changes the order details will reset the cache and Ecwid will make a new request to your endpoint.
Q: Can I create a user interface for user to select and set different duscount rules?
After the installation, your app can add a page where they can configure it: provide their account details, set up discount rules, enable/disable rules, etc. We recommend using Native apps feature and the Application storage feature to provide this functionality. To manage and store those settings, see the Advanced setup section.