Default E-Com Plus app for complex discount rules
This application will add discount extra discount to order by integrating Modules API (Apply discount).
App hidden_data
will store discount rules (promotions) defined by merchant,
with filters (optionals) by date range AND
discount coupon, UTM campaign OR customer IDs.
hidden_data
expected object model is defined (JSON Schema) on
app admin_settings
.
It's based on E-Com Plus Express App Boilerplate, application installation and authentication was kept as is with original endpoints from boilerplate source:
/bin/web.js
: Express web server setup);/routes/ecom/auth-callback.js
: Endpoint for E-Com Plus Authentication Callback;
Additional endpoint was created to handle apply_discount
(/ecom/modules/apply-discount.js
)
module, it receives requests from Modules API on stores with this app installed.
It'll receive POST with body like:
const body = {
params: {
discount_coupon: 'SAMPLE',
amount: {
total: 100,
subtotal: 90,
freight: 10,
discount: 0
},
utm: {
campaign: 'my_promo'
},
customer: {
_id: 'a12345678901234567891234'
}
// ...
},
application: {
// configured by merchant
data: {},
hidden_data: {
discount_rules: [
// discount rules objects with model defined by `admin_settings`
// ...
]
}
}
}
- Full
params
object reference from Modules API docs; hidden_data.discount_rules
object reference on application.jsonadmin_settings.discount_rules.schema
property.
And will respond like:
// no promotion match
// returns empty JSON object
const response = {}
// discount match but can't apply (generally non-cumulative)
const response = {
invalid_coupon_message: 'Message to customer'
}
// we have a discount to apply \o/
const response = {
discount_rule: {
label: 'MY_SAMPLE_COUPON',
description: 'Maybe we have a description configured by merchant',
extra_discount: {
value: 20,
flags: ['COUPON']
}
}
}
- Full
response
object reference from Modules API docs;
Variable | Value |
---|---|
LOGGER_OUTPUT |
~/app/log/logger.out |
LOGGER_ERRORS |
~/app/log/logger.err |
LOGGER_FATAL_ERRORS |
~/app/log/_stderr |
PORT |
3000 |
APP_BASE_URI |
https://discounts.ecomplus.biz |
DB_PATH |
~/app/db.sqlite |
ECOM_AUTH_DB |
~/app/db.sqlite |
ECOM_AUTH_UPDATE |
enabled |
Published at https://discounts.ecomplus.biz
When new version is production ready,
create a new release
(or npm run release
) to run automatic deploy from master branch
and (re)publish the app.