Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

ecomplus/discounts

Repository files navigation

Discounts

CodeFactor License Apache-2.0

Default E-Com Plus app for complex discount rules

CHANGELOG

About

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:

Apply discount module endpoint

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`
        // ...
      ]
    }
  }
}

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']
    }
  }
}

Environment variables sample

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

Production server

Published at https://discounts.ecomplus.biz

Continuous deployment

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.