Skip to content

Commit

Permalink
Merge pull request #487 from evershopcommerce/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
treoden authored Mar 27, 2024
2 parents 6df7332 + 86f6e87 commit 262fe5c
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Github build

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '18', '20']
name: Node ${{ matrix.node }}

# env:
# php-ini-values: post_max_size=256M
# wp-bp-directory: src/wp-content/plugins/buddypress
# DB_DATABASE: db_test
# DB_USER: root
# DB_PASSWORD: 'root'
# DB_HOST: localhost

steps:
# - run: |
# sudo /etc/init.d/mysql start
# mysql -e 'CREATE DATABASE db_test;' -uroot -proot
# mysql -e 'SHOW DATABASES;' -uroot -proot
- uses: actions/checkout@v2
- name: Setup node js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- run: npm install -g npm@9
- run: npm install
- run: npm run test
8 changes: 7 additions & 1 deletion packages/sendgrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ npm install @evershop/sendgrid
{
...,
"sendgrid": {
"apiKey": "<Your sendGrid API Key>",
"from": "Customer Service <Your email>",
"fromName": "Evershop",
"events": {
Expand All @@ -60,6 +59,13 @@ npm install @evershop/sendgrid
}
```

### Step 4: Add the API key to the environment variables

```javascript
// .env
SENDGRID_API_KEY=your_api_key
```

This extension now supports 3 events:
1. order_placed: This event is fired when a customer places an order. Send an email to confirm the order.
2. reset_password: This event is fired when a customer requests to reset password. Send an email with a link to reset password.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
} = require('@evershop/evershop/src/modules/graphql/services/contextHelper');
const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');
const sgMail = require('@sendgrid/mail');
const { getEnv } = require('@evershop/evershop/src/lib/util/getEnv');

// eslint-disable-next-line no-unused-vars
module.exports = async (request, response, delegate, next) => {
Expand All @@ -17,7 +18,7 @@ module.exports = async (request, response, delegate, next) => {
} = response;

// Check if the API key is set
const apiKey = getConfig('sendgrid.apiKey', '');
const apiKey = getEnv('SENDGRID_API_KEY', '');
const from = getConfig('sendgrid.from', '');

if (!apiKey || !from) {
Expand Down
1 change: 0 additions & 1 deletion packages/sendgrid/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const config = require('config');

module.exports = () => {
const sendgridConfig = {
apiKey: '',
from: 'Customer Service <hello@evershop.io>',
fromName: 'Evershop',
events: {
Expand Down
2 changes: 1 addition & 1 deletion packages/sendgrid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@evershop/sendgrid",
"version": "1.0.0",
"version": "1.0.1",
"description": "A SendGrid extension for EverShop.",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');
const sgMail = require('@sendgrid/mail');
const { select } = require('@evershop/postgres-query-builder');
const { error } = require('@evershop/evershop/src/lib/log/debuger');
const { getEnv } = require('@evershop/evershop/src/lib/util/getEnv');
const { getValue } = require('@evershop/evershop/src/lib/util/registry');

module.exports = async function sendOrderConfirmationEmail(data) {
try {
// Check if the API key is set
const apiKey = getConfig('sendgrid.apiKey', '');
const apiKey = getEnv('SENDGRID_API_KEY', '');
const from = getConfig('sendgrid.from', '');

if (!apiKey || !from) {
Expand Down Expand Up @@ -43,14 +45,19 @@ module.exports = async function sendOrderConfirmationEmail(data) {
// Remove the password
delete customer.password;

const emailDataFinal = await getValue(
'sendgrid_customer_welcome_email_data',
customer,
{}
);
// Send the email
const msg = {
to: customer.email,
to: emailDataFinal.email,
subject: customerRegistered.subject || `Welcome to Evershop`,
from,
templateId: customerRegistered.templateId,
dynamicTemplateData: {
...customer,
...emailDataFinal,
home_url: getConfig('shop.homeUrl', '')
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ const { select } = require('@evershop/postgres-query-builder');
const { contries } = require('@evershop/evershop/src/lib/locale/countries');
const { provinces } = require('@evershop/evershop/src/lib/locale/provinces');
const { error } = require('@evershop/evershop/src/lib/log/debuger');
const { getEnv } = require('@evershop/evershop/src/lib/util/getEnv');
const { getValue } = require('@evershop/evershop/src/lib/util/registry');

module.exports = async function sendOrderConfirmationEmail(data) {
try {
// Check if the API key is set
const apiKey = getConfig('sendgrid.apiKey', '');
const apiKey = getEnv('SENDGRID_API_KEY', '');
const from = getConfig('sendgrid.from', '');

if (!apiKey || !from) {
Expand Down Expand Up @@ -71,13 +73,19 @@ module.exports = async function sendOrderConfirmationEmail(data) {
provinces.find((p) => p.code === emailData.billing_address.province)
?.name || '';

const finalEmailData = await getValue(
'sendgrid_order_confirmation_email_data',
emailData,
{}
);

// Send the email
const msg = {
to: order.customer_email,
subject: orderPlaced.subject || 'Order Confirmation',
from,
templateId: orderPlaced.templateId,
dynamicTemplateData: emailData
dynamicTemplateData: finalEmailData
};

await sgMail.send(msg);
Expand Down

0 comments on commit 262fe5c

Please sign in to comment.