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

Magento1 vsbridge client. #190

Merged
merged 1 commit into from
Feb 28, 2019
Merged
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
15 changes: 15 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@
"accessTokenSecret": "7qunl3p505rubmr7u1ijt7odyialnih9"
}
},
"magento1": {
"url": "http://magento-demo.local",
"imgUrl": "http://magento-demo.local/media/catalog/product",
"magentoUserName": "",
"magentoUserPassword": "",
"httpUserName": "",
"httpUserPassword": "",
"api": {
"url": "http://magento-demo.local/vsbridge",
"consumerKey": "",
"consumerSecret": "",
"accessToken": "",
"accessTokenSecret": ""
}
},
"imageable": {
"namespace": "",
"maxListeners": 512,
Expand Down
21 changes: 21 additions & 0 deletions src/platform/abstract/address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class AbstractAddressProxy {
constructor(config, req) {
this._config = config
this._request = req
}

list (customerToken) {
throw new Error('AbstractAddressProxy::list must be implemented for specific platform')
}
update (customerToken, addressData) {
throw new Error('AbstractAddressProxy::update must be implemented for specific platform')
}
get (customerToken, addressId) {
throw new Error('AbstractAddressProxy::get must be implemented for specific platform')
}
delete (customerToken, addressData) {
throw new Error('AbstractAddressProxy::delete must be implemented for specific platform')
}
}

export default AbstractAddressProxy
7 changes: 7 additions & 0 deletions src/platform/abstract/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AbstractContactProxy {
submit (formData) {
throw new Error('AbstractContactProxy::check must be implemented for specific platform')
}
}

module.exports = AbstractContactProxy
9 changes: 9 additions & 0 deletions src/platform/abstract/newsletter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AbstractNewsletterProxy {
subscribe (emailAddress) {
}

unsubscribe (customerToken) {
}
}

module.exports = AbstractNewsletterProxy
11 changes: 11 additions & 0 deletions src/platform/abstract/stock_alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AbstractStockAlertProxy {
constructor(config, req) {
this._config = config
this._request = req
}
subscribe (customerToken, productId, emailAddress) {
throw new Error('AbstractContactProxy::subscribe must be implemented for specific platform')
}
}

export default AbstractStockAlertProxy
13 changes: 13 additions & 0 deletions src/platform/abstract/wishlist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AbstractWishlistProxy {
pull (customerToken) {
throw new Error('AbstractWishlistProxy::pull must be implemented for specific platform')
}
update (customerToken, wishListItem) {
throw new Error('AbstractWishlistProxy::update must be implemented for specific platform')
}
delete (customerToken, wishListItem) {
throw new Error('AbstractWishlistProxy::delete must be implemented for specific platform')
}
}

module.exports = AbstractWishlistProxy
24 changes: 24 additions & 0 deletions src/platform/magento1/address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import AbstractAddressProxy from '../abstract/address'
import {multiStoreConfig} from "./util";
import {Magento1Client} from "./module";

class AddressProxy extends AbstractAddressProxy {
constructor (config, req){
super(config, req)
this.api = Magento1Client(multiStoreConfig(config.magento1.api, req));
}
list (customerToken) {
return this.api.address.list(customerToken)
}
update (customerToken, addressData) {
return this.api.address.update(customerToken, addressData);
}
get (customerToken, addressId) {
return this.api.address.get(customerToken, addressId)
}
delete (customerToken, addressData) {
return this.api.address.delete(customerToken, addressData)
}
}

module.exports = AddressProxy
48 changes: 48 additions & 0 deletions src/platform/magento1/cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import AbstractCartProxy from '../abstract/cart';
import { multiStoreConfig } from './util';
import { Magento1Client } from './module/index';

class CartProxy extends AbstractCartProxy {
constructor (config, req){
super(config, req)
this.api = Magento1Client(multiStoreConfig(config.magento1.api, req));
}
create (customerToken) {
return this.api.cart.create(customerToken);
}
update (customerToken, cartId, cartItem) {
return this.api.cart.update(customerToken, cartId, cartItem);
}
delete (customerToken, cartId, cartItem) {
return this.api.cart.delete(customerToken, cartId, cartItem);
}
pull (customerToken, cartId, params) {
return this.api.cart.pull(customerToken, cartId, params);
}
totals (customerToken, cartId, params) {
return this.api.cart.totals(customerToken, cartId, params);
}
getShippingMethods (customerToken, cartId, address) {
return this.api.cart.shippingMethods(customerToken, cartId, address);
}
getPaymentMethods (customerToken, cartId) {
return this.api.cart.paymentMethods(customerToken, cartId);
}
setShippingInformation (customerToken, cartId, address) {
return this.api.cart.shippingInformation(customerToken, cartId, address);
}
collectTotals (customerToken, cartId, shippingMethod) {
return this.api.cart.collectTotals(customerToken, cartId, shippingMethod);
}
applyCoupon (customerToken, cartId, coupon) {
return this.api.cart.applyCoupon(customerToken, cartId, coupon);
}
deleteCoupon (customerToken, cartId) {
return this.api.cart.deleteCoupon(customerToken, cartId);
}
getCoupon (customerToken, cartId) {
return this.api.cart.getCoupon(customerToken, cartId);
}
}

module.exports = CartProxy;
15 changes: 15 additions & 0 deletions src/platform/magento1/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import AbstractContactProxy from '../abstract/contact';
import { multiStoreConfig } from './util';
import { Magento1Client } from './module/index';

class ContactProxy extends AbstractContactProxy {
constructor (config, req){
super(config, req)
this.api = Magento1Client(multiStoreConfig(config.magento1.api, req));
}
submit (form) {
return this.api.contact.submit(form);
}
}

module.exports = ContactProxy;
40 changes: 40 additions & 0 deletions src/platform/magento1/module/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const RestClient = require('./lib/rest_client').RestClient;
const user = require('./lib/user');
const cart = require('./lib/cart');
const stock = require('./lib/stock');
const contact = require('./lib/contact');
const wishlist = require('./lib/wishlist');
const stockAlert = require('./lib/stock_alert');
const newsletter = require('./lib/newsletter');
const address = require('./lib/address');

const MAGENTO_API_VERSION = 'V1';

module.exports.Magento1Client = function (options) {
let instance = {
addMethods (key, module) {
let client = RestClient(options);
if (module) {
if (this[key])
this[key] = Object.assign(this[key], module(client));
else
this[key] = module(client);
}
}
};

options.version = MAGENTO_API_VERSION;

let client = RestClient(options);

instance.user = user(client);
instance.cart = cart(client);
instance.stock = stock(client);
instance.contact = contact(client);
instance.wishlist = wishlist(client);
instance.stockAlert = stockAlert(client);
instance.newsletter = newsletter(client);
instance.address = address(client);

return instance;
};
36 changes: 36 additions & 0 deletions src/platform/magento1/module/lib/address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = function (restClient) {
let module = {};
let url = 'address/';
function getResponse(data){
if (data.code === 200){
return data.result;
}

return false;
}
module.list = function (customerToken) {
url += `list?token=${customerToken}`
return restClient.get(url).then((data)=> {
return getResponse(data);
});
},
module.update = function (customerToken, addressData) {
url += `update?token=${customerToken}`
return restClient.post(url, {address: addressData}).then((data)=> {
return getResponse(data);
});
}
module.get = function (customerToken, addressId) {
url += `get?token=${customerToken}&addressId=${addressId}`
return restClient.get(url).then((data)=> {
return getResponse(data);
});
}
module.delete = function (customerToken, addressData) {
url += `delete?token=${customerToken}`
return restClient.post(url, {address: addressData}).then((data)=> {
return getResponse(data);
});
}
return module;
}
82 changes: 82 additions & 0 deletions src/platform/magento1/module/lib/cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
function isNumeric(val) {
return Number(parseFloat(val)).toString() === val;
}

module.exports = function (restClient) {
let module = {};
const urlPrefix = 'cart/';
let url = urlPrefix;
function getResponse(data){
if(data.code === 200){
return data.result;
}
return false;
}
module.create = (customerToken) => {
url += `create?token=${customerToken}`;
return restClient.post(url).then((data)=> {
return getResponse(data);
});
}
module.update = (customerToken, cartId, cartItem) => {
url += `update?token=${customerToken}&cartId=${cartId}`;
return restClient.post(url, { cartItem: cartItem }).then((data)=> {
return getResponse(data);
});
}
module.applyCoupon = (customerToken, cartId, coupon) => {
url += `applyCoupon?token=${customerToken}&cartId=${cartId}&coupon=${coupon}`;
return restClient.post(url).then((data)=> {
return getResponse(data);
});
}
module.deleteCoupon = (customerToken, cartId) => {
url += `deleteCoupon?token=${customerToken}&cartId=${cartId}`;
return restClient.post(url).then((data)=> {
return getResponse(data);
});
}
module.delete = (customerToken, cartId, cartItem) => {
url += `delete?token=${customerToken}&cartId=${cartId}`;
return restClient.post(url, { cartItem: cartItem }).then((data)=> {
return getResponse(data);
});
}
module.pull = (customerToken, cartId) => {
url += `pull?token=${customerToken}&cartId=${cartId}`;
return restClient.get(url).then((data)=> {
return getResponse(data);
});
}
module.totals = (customerToken, cartId) => {
url += `totals?token=${customerToken}&cartId=${cartId}`;
return restClient.get(url).then((data)=> {
return getResponse(data);
});
}
module.shippingInformation = (customerToken, cartId, body) => {
url += `totals?token=${customerToken}&cartId=${cartId}`;
return restClient.post(url, body).then((data)=> {
return getResponse(data);
});
}
module.shippingMethods = (customerToken, cartId, address) => {
url += `shippingMethods?token=${customerToken}&cartId=${cartId}`;
return restClient.post(url, { address: address }).then((data)=> {
return getResponse(data);
});
}
module.paymentMethods = (customerToken, cartId) => {
url += `paymentMethods?token=${customerToken}&cartId=${cartId}`;
return restClient.get(url).then((data)=> {
return getResponse(data);
});
}
module.getCoupon = (customerToken, cartId) => {
url += `coupon?token=${customerToken}&cartId=${cartId}`;
return restClient.get(url).then((data)=> {
return getResponse(data);
});
}
return module;
}
18 changes: 18 additions & 0 deletions src/platform/magento1/module/lib/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = function (restClient) {
let module = {};
const urlPrefix = 'contact/';
let url = urlPrefix;
function getResponse(data){
if(data.code === 200){
return data.result;
}
return false;
}
module.submit = (form) => {
url += `submit`;
return restClient.post(url, {form}).then((data)=> {
return getResponse(data);
});
};
return module;
};
19 changes: 19 additions & 0 deletions src/platform/magento1/module/lib/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var winston = require('winston');

winston.emitErrs = true;

var logger = new winston.Logger({
transports: [
new winston.transports.Console({
level: 'debug',
handleExceptions: true,
json: false,
colorize: true
})
],
exitOnError: false
});

logger.info('Winston logging library initialized.');

module.exports = logger;
Loading