Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: v2 api #46

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# misc
/coverage/
!.*
.*/
.eslintcache

# ember-try
/.node_modules.ember-try/
Expand Down
48 changes: 26 additions & 22 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"use strict";
'use strict';

module.exports = {
root: true,
parser: "babel-eslint",
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
plugins: ["ember"],
extends: ["eslint:recommended", "plugin:ember/recommended"],
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true,
},
Expand All @@ -20,30 +24,30 @@ module.exports = {
// node files
{
files: [
".eslintrc.js",
".template-lintrc.js",
"ember-cli-build.js",
"index.js",
"testem.js",
"blueprints/*/index.js",
"config/**/*.js",
"tests/dummy/config/**/*.js",
],
excludedFiles: [
"addon/**",
"addon-test-support/**",
"app/**",
"tests/dummy/app/**",
'./.eslintrc.js',
'./.prettierrc.js',
'./.template-lintrc.js',
'./ember-cli-build.js',
'./index.js',
'./testem.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./tests/dummy/config/**/*.js',
],
parserOptions: {
sourceType: "script",
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
plugins: ["node"],
// extends: ['plugin:node/recommended']
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
{
// Test files:
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
Expand Down
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
/.editorconfig
/.ember-cli
/.env*
/.eslintcache
/.eslintignore
/.eslintrc.js
/.git/
/.gitignore
/.prettierignore
/.prettierrc.js
/.template-lintrc.js
/.travis.yml
/.watchmanconfig
Expand All @@ -23,6 +26,7 @@
/ember-cli-build.js
/testem.js
/tests/
/yarn-error.log
/yarn.lock
.gitkeep

Expand Down
21 changes: 21 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
singleQuote: true,
};
2 changes: 1 addition & 1 deletion .template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: 'octane'
extends: 'recommended',
};
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "10"
- "12"

dist: xenial

Expand Down Expand Up @@ -46,13 +46,15 @@ jobs:

# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- env: EMBER_TRY_SCENARIO=ember-lts-3.12
- env: EMBER_TRY_SCENARIO=ember-lts-3.16
- env: EMBER_TRY_SCENARIO=ember-lts-3.20
- env: EMBER_TRY_SCENARIO=ember-lts-3.24
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=ember-classic
- env: EMBER_TRY_SCENARIO=embroider-safe
- env: EMBER_TRY_SCENARIO=embroider-optimized

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
Expand Down
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

## Linting

* `npm run lint:hbs`
* `npm run lint:js`
* `npm run lint:js -- --fix`
* `yarn lint`
* `yarn lint:fix`

## Running tests

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ This addon provides an adapter to use with the Goods platform (https://www.goods

## Compatibility

- Ember.js v3.12 or above
- Ember CLI v2.13 or above
- Node.js v10 or above

## Installation
* Ember.js v3.20 or above
* Ember CLI v3.20 or above
* Node.js v12 or above

```
ember install ember-goods
Expand Down
31 changes: 0 additions & 31 deletions addon/adapters/goods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,6 @@ export default class ApplicationAdapter extends JSONAPIAdapter.extend(
coalesceFindRequests = true;
host = config.APP.goods.host;

modelWhitelist = [
"basket",
"basket-item",
"basket-rule-validation",
"brand",
"category",
"country",
"content-entry-operation",
"order",
"order-line",
"order-payment-method",
"payment",
"payment-method",
"price",
"product-category",
"product-field",
"product-image",
"product",
"promotion",
"shop-member",
"shop-password-change",
"shop-payment-method",
"shop-reset-token",
"shop-role",
"state",
"sku-field",
"sku-image",
"sku",
"user",
];

@inject declare session: any;

@computed("session.data.authenticated.access_token")
Expand Down
87 changes: 87 additions & 0 deletions addon/components/goods/metrics/track-sale/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import Component from '@glimmer/component';
import Order from 'ember-goods/models/order';
import config from 'ember-get-config';
import { isPresent } from '@ember/utils';
import { inject } from '@ember/service';
import moment from 'moment';
import GoodsCommerce from 'ember-goods/services/goods-commerce';

interface GoodsMetricsTrackSaleArgs {
metrics: any;
order: Order;
}

export default class GoodsMetricsTrackSale extends Component<GoodsMetricsTrackSaleArgs> {
/**
*
*/
@inject declare commerce: GoodsCommerce;

/**
*
*/
trackSale() {
let metrics = config.APP.goods.commerce.metrics;

if (metrics.includes('gtm')) {
this.gtmTrackSale(this.args.order);
}
}

/**
*
* @param order
*/
gtmTrackSale(order: Order) {
//@ts-ignore
let dataLayer = window['dataLayer'] || [];

let products: Array<any> = [];
this.args.order.get('orderLines').forEach((orderLine) => {
let sku = orderLine.get('sku');
let skuName = this.commerce.getSkuName(
sku.get('attrs'),
sku.get('product').get('skuName')
);
let bookableDate = '';
if (isPresent(sku.get('attrs').bookableDate)) {
bookableDate = moment(sku.get('attrs').bookableDate).format(
'YYYY-MM-DD'
);
}
products.push({
name: sku.get('product').get('name'),
id: sku.get('id'),
price: orderLine.get('price') / 100,
brand: sku.get('product').get('brand').get('name'),
category: 'Ticket',
quantity: orderLine.get('quantity'),
variant: skuName,
dimension1: bookableDate,
dimension2: sku.get('attrs').sessionStartTime,
});
});

dataLayer.push({ ecommerce: null });
dataLayer.push({
event: 'ecommerce',
ecommerce: {
purchase: {
actionField: {
id: order.get('id'),
affiliation: 'Online Store',
revenue: order.get('total') / 100,
tax: '0',
shipping: '0',
},
products,
},
},
});
}

constructor(owner: any, args: any) {
super(owner, args);
this.trackSale();
}
}
1 change: 1 addition & 0 deletions addon/components/goods/metrics/track-sale/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
32 changes: 16 additions & 16 deletions addon/components/payment-challenge/component.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import Component from "@ember/component";
import Component from '@ember/component';
// @ts-ignore: Ignore import of compiled template
import template from "./template";
import { notEmpty } from "@ember/object/computed";
import { computed } from "@ember/object";
import { get } from "@ember/object";
import { scheduleOnce } from "@ember/runloop";
import { isNone } from "@ember/utils";
import { layout } from "@ember-decorators/component";
import template from './template';
import { notEmpty } from '@ember/object/computed';
import { computed } from '@ember/object';
import { get } from '@ember/object';
import { scheduleOnce } from '@ember/runloop';
import { isNone } from '@ember/utils';
import { layout } from '@ember-decorators/component';

@layout(template)
export default class PaymentChallenge extends Component {
payment!: any;

@notEmpty("payment.challengeUrl") isChallengingPayment!: boolean;
@computed("payment.challengeRequest")
@notEmpty('payment.challengeUrl') isChallengingPayment!: boolean;
@computed('payment.challengeRequest')
get challengeRequest() {
return Object.entries(get(this.payment, "challengeRequest"));
return Object.entries(get(this.payment, 'challengeRequest'));
}

renderIframeContent() {
scheduleOnce("afterRender", this, () => {
scheduleOnce('afterRender', this, () => {
let iframeEl: any = document.getElementById(
"goods-payment-challenge-frame"
'goods-payment-challenge-frame'
);
scheduleOnce("afterRender", this, () => {
scheduleOnce('afterRender', this, () => {
if (!isNone(iframeEl)) {
let doc = iframeEl.contentWindow.document;

let formHtml = `<form action=${this.payment.challengeUrl} method="post">`;
this.challengeRequest.forEach(param => {
this.challengeRequest.forEach((param) => {
formHtml += `<input type="hidden" name=${param[0]} value=${param[1]} >`;
});
formHtml += `
Expand All @@ -39,7 +39,7 @@ export default class PaymentChallenge extends Component {
doc.write(formHtml);
doc.close();

doc.getElementById("challenge-frame-trigger").click();
doc.getElementById('challenge-frame-trigger').click();
}
});
});
Expand Down
Loading