From e764748aa11c4502b1a2b4bc8afea0da43686d47 Mon Sep 17 00:00:00 2001 From: quansenB Date: Sun, 3 Nov 2019 21:18:58 +0100 Subject: [PATCH] add ecommerce order products functionality --- .../ActiveCampaign/ActiveCampaign.node.ts | 53 ++++++++++++++++++- .../EcomOrderProductsDescription.ts | 15 +++--- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts b/packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts index 67153c18aa..2c2f03a2a7 100644 --- a/packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts +++ b/packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts @@ -34,6 +34,7 @@ import { ecomCustomerOperations, ecomCustomerFields } from './EcomCustomerDescription'; +import { ecomOrderProductsOperations, ecomOrderProductsFields } from './EcomOrderProductsDescription'; interface CustomProperty { name: string; @@ -107,7 +108,7 @@ export class ActiveCampaign implements INodeType { }, { name: 'E-commerce Order Products', - value: 'ecomerceOrderProducts' + value: 'ecommerceOrderProducts' } ], default: 'contact', @@ -121,6 +122,7 @@ export class ActiveCampaign implements INodeType { ...dealOperations, ...ecomOrderOperations, ...ecomCustomerOperations, + ...ecomOrderProductsOperations, // ---------------------------------- // contact @@ -142,6 +144,11 @@ export class ActiveCampaign implements INodeType { // ---------------------------------- ...ecomCustomerFields, + // ---------------------------------- + // ecommerceOrderProducts + // ---------------------------------- + ...ecomOrderProductsFields, + ], }; @@ -478,7 +485,7 @@ export class ActiveCampaign implements INodeType { } else { additionalFields.acceptsMarketing = '0'; } - } + } addAdditionalFields(body.ecomCustomer as IDataObject, additionalFields); } else if (operation === 'update') { @@ -540,6 +547,48 @@ export class ActiveCampaign implements INodeType { } else { throw new Error(`The operation "${operation}" is not known`); } + } else if (resource === 'ecommerceOrderProducts') { + if (operation === 'getByProductId') { + // ---------------------------------- + // ecommerceOrderProducts:getByProductId + // ---------------------------------- + + requestMethod = 'GET'; + + const procuctId = this.getNodeParameter('procuctId', i) as number; + endpoint = `/api/3/ecomOrderProducts/${procuctId}`; + + + } else if (operation === 'getByOrderId') { + // ---------------------------------- + // ecommerceOrderProducts:getByOrderId + // ---------------------------------- + + requestMethod = 'GET'; + + const orderId = this.getNodeParameter('orderId', i) as number; + endpoint = `/api/3/ecomOrders/${orderId}/orderProducts`; + + } else if (operation === 'getAll') { + // ---------------------------------- + // ecommerceOrderProductss:getAll + // ---------------------------------- + + requestMethod = 'GET'; + + returnAll = this.getNodeParameter('returnAll', i) as boolean; + if (returnAll === false) { + qs.limit = this.getNodeParameter('limit', i) as number; + } + + endpoint = `/api/3/ecomOrderProducts`; + + } else { + throw new Error(`The operation "${operation}" is not known`); + } + + console.log(endpoint); + console.log(body) } else { throw new Error(`The resource "${resource}" is not known!`); diff --git a/packages/nodes-base/nodes/ActiveCampaign/EcomOrderProductsDescription.ts b/packages/nodes-base/nodes/ActiveCampaign/EcomOrderProductsDescription.ts index ec28fafe8a..fbff8787d9 100644 --- a/packages/nodes-base/nodes/ActiveCampaign/EcomOrderProductsDescription.ts +++ b/packages/nodes-base/nodes/ActiveCampaign/EcomOrderProductsDescription.ts @@ -1,7 +1,5 @@ import { INodeProperties } from "n8n-workflow"; -import { allCurrencies } from './currencies'; - export const ecomOrderProductsOperations = [ { displayName: 'Operation', @@ -18,21 +16,20 @@ export const ecomOrderProductsOperations = [ { name: 'Get All', value: 'getAll', - description: 'Get data of all orders', + description: 'Get data of all order products', }, { name: 'Get by Product ID', value: 'getByProductId', - description: 'Get data of a order', + description: 'Get data of a ordered product', }, { name: 'Get by Order ID', value: 'getByOrderId', - description: 'Get data of a order', + description: 'Get data of an order\'s products', }, - ], - default: 'create', + default: 'getAll', description: 'The operation to perform.', }, ] as INodeProperties[] @@ -56,7 +53,7 @@ export const ecomOrderProductsFields = [ ], }, }, - description: 'The id of the e-commerce order.', + description: 'The ID of the order whose products you\'d like returned.', }, // ---------------------------------- @@ -77,7 +74,7 @@ export const ecomOrderProductsFields = [ ], }, }, - description: 'The id of the e-commerce order.', + description: 'The ID of the product you\'d like returned.', }, // ----------------------------------