Skip to content

Commit 48de04a

Browse files
committed
Move props to single file
1 parent 608c9ae commit 48de04a

48 files changed

Lines changed: 694 additions & 455 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config/admin.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1+
// config used by dashboard client side only
12
module.exports = {
3+
// dashboard UI language
24
language: 'en',
3-
apiBaseUrl: 'http://localhost:3000/api/v1',
4-
editor: {
5-
language: 'en',
6-
inline: true,
7-
themes: 'inlite',
8-
plugins: [
9-
'autolink lists link image charmap preview anchor', 'searchreplace visualblocks code fullscreen', 'media table paste code textcolor directionality'
10-
],
11-
toolbar1: 'image media | styleselect | bold italic bullist numlist link alignleft aligncenter alignright alignjustify',
12-
toolbar2: 'undo redo | forecolor paste removeformat table | outdent indent | preview code'
13-
}
5+
apiBaseUrl: 'http://localhost:3000/api/v1'
146
}

config/server.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
const baseUrl = 'http://localhost:3000';
22
const uploadRootDir = '/var/www/cezerin/public/static';
33

4+
// config used by server side only
45
module.exports = {
6+
// used by API to build full url
57
storeBaseUrl: baseUrl,
8+
9+
// used in sign-in email
610
adminLoginUrl: `${baseUrl}/admin/login`,
11+
12+
// used by store server (render and ajax)
713
apiBaseUrl: `${baseUrl}/api/v1`,
814

915
nodeServerPort: 3000,
1016
nodeServerHost: '127.0.0.1',
17+
18+
// used by API only
1119
mongodbServerUrl: 'mongodb://<user>:<pass>@<ip>:<port>/<db>',
20+
1221
orderStartNumber: 1000,
1322

1423
cartCookieOptions: {
@@ -28,17 +37,22 @@ module.exports = {
2837
},
2938

3039
security: {
31-
jwtSecret: '---',
32-
cookieKey: '---',
40+
// key to sign tokens
41+
jwtSecret: 'NyDlK17iuWP9k5IjXZOilSVdMvFylG',
42+
// key to sign store cookies
43+
cookieKey: '4BsUetCikZKSIYkJ6Si2Zkkox8B5Kl',
44+
// token to access API from store
3345
token: '---'
3446
},
3547

48+
// path to upload files
3649
path: {
3750
categories: `${uploadRootDir}/categories`,
3851
products: `${uploadRootDir}/products`,
3952
files: `${uploadRootDir}/files`
4053
},
4154

55+
// url to access uploaded files
4256
url: {
4357
categories: `${baseUrl}/static/categories`,
4458
products: `${baseUrl}/static/products`,

config/store.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// config used by store client side only
12
module.exports = {
3+
// store UI language
24
language: 'en',
35
ajaxBaseUrl: 'http://localhost:3000/ajax'
46
}

locales/store/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"paymentMethod": "Payment options",
77
"shippingAddress": "Shipping Address",
88
"billingAddress": "Billing Address",
9-
"orderSubmit": "Place Order EN",
10-
"emptyCheckout": "Cart is empty",
9+
"orderSubmit": "Place Order",
10+
"emptyCheckout": "Your cart is empty",
1111
"email": "Email",
1212
"mobile": "Mobile",
1313
"country": "Country",

src/admin/client/modules/shared/editor/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@ import React from 'react'
22
import TinyMCE from 'react-tinymce';
33
import settings from 'lib/settings'
44

5+
const config = {
6+
inline: true,
7+
themes: 'inlite',
8+
plugins: [
9+
'autolink lists link image charmap preview anchor', 'searchreplace visualblocks code fullscreen', 'media table paste code textcolor directionality'
10+
],
11+
toolbar1: 'image media | styleselect | bold italic bullist numlist link alignleft aligncenter alignright alignjustify',
12+
toolbar2: 'undo redo | forecolor paste removeformat table | outdent indent | preview code'
13+
}
14+
515
const Editor = ({ input: { onChange, value } }) =>
616
<TinyMCE
717
content={value}
818
config={{
9-
language: settings.editor.language,
10-
themes: settings.editor.themes,
11-
inline: settings.editor.inline,
12-
plugins: settings.editor.plugins,
13-
toolbar1: settings.editor.toolbar1,
14-
toolbar2: settings.editor.toolbar2,
19+
language: settings.language,
20+
themes: config.themes,
21+
inline: config.inline,
22+
plugins: config.plugins,
23+
toolbar1: config.toolbar1,
24+
toolbar2: config.toolbar2,
1525
menubar: false
1626
}}
1727
onChange={e => {onChange(e.target.getContent())}}

src/api/server/services/orders/order_items.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ class OrderItemsService {
5656
let itemObjectID = new ObjectID(item_id);
5757
const item = this.getValidDocumentForUpdate(data);
5858

59-
return mongo.db.collection('orders').updateOne({
60-
_id: orderObjectID,
61-
'items.id': itemObjectID
62-
}, {$set: item}).then(() => this.calculateAndUpdateItem(order_id, item_id)).then(() => OrdersService.getSingleOrder(order_id));
59+
if(parse.getNumberIfPositive(data.quantity) === 0) {
60+
// delete item
61+
return this.deleteItem(order_id, item_id);
62+
} else {
63+
// update
64+
return mongo.db.collection('orders').updateOne({
65+
_id: orderObjectID,
66+
'items.id': itemObjectID
67+
}, {$set: item}).then(() => this.calculateAndUpdateItem(order_id, item_id)).then(() => OrdersService.getSingleOrder(order_id));
68+
}
6369
}
6470

6571
calculateAndUpdateItem(order_id, item_id) {

src/api/server/services/products/products.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class ProductsService {
193193
}
194194

195195
getMatchTextQuery({search }) {
196-
return (search && search.length > 0) ? { $text: { $search: search } } : null;
196+
return (search && search.length > 0 && search !== 'null' && search !== 'undefined') ? { $text: { $search: search } } : null;
197197
}
198198

199199
getMatchQuery({
@@ -245,13 +245,13 @@ class ProductsService {
245245
});
246246
}
247247

248-
if(price_from !== null) {
248+
if(price_from !== null && price_from > 0) {
249249
queries.push({
250250
price: { $gte: price_from }
251251
});
252252
}
253253

254-
if(price_to !== null) {
254+
if(price_to !== null && price_to > 0) {
255255
queries.push({
256256
price: { $lte: price_to }
257257
});

src/store/server/ajax.js

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ api.init(serverSettings.apiBaseUrl, serverSettings.security.token);
77
const DEFAULT_CACHE_CONTROL = 'public, max-age=600';
88
const PRODUCTS_CACHE_CONTROL = 'public, max-age=60';
99

10+
const fillCartItemWithProductData = (products, cartItem) => {
11+
const product = products.find(p => p.id === cartItem.product_id);
12+
if(product) {
13+
cartItem.image_url = product.images.length > 0 ? product.images[0].url : null;
14+
cartItem.stock_quantity = product.stock_quantity;
15+
}
16+
return cartItem;
17+
}
18+
19+
const fillCartItems = (cartResponse) => {
20+
let cart = cartResponse.json;
21+
if(cart && cart.items && cart.items.length > 0) {
22+
const productIds = cart.items.map(item => item.product_id);
23+
return api.products.list({ ids: productIds, fields: 'images,enabled,stock_quantity' }).then(({status, json}) => {
24+
const newCartItem = cart.items.map(cartItem => fillCartItemWithProductData(json, cartItem))
25+
cartResponse.json.items = newCartItem;
26+
return cartResponse;
27+
})
28+
} else {
29+
return Promise.resolve(cartResponse)
30+
}
31+
}
32+
1033
ajaxRouter.get('/products', (req, res, next) => {
1134
const filter = req.query;
1235
filter.enabled = true;
@@ -24,7 +47,7 @@ ajaxRouter.get('/products/:id', (req, res, next) => {
2447
ajaxRouter.get('/cart', (req, res, next) => {
2548
const order_id = req.signedCookies.order_id;
2649
if (order_id) {
27-
api.orders.retrieve(order_id).then(({status, json}) => {
50+
api.orders.retrieve(order_id).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
2851
res.status(status).send(json);
2952
})
3053
} else {
@@ -36,7 +59,7 @@ ajaxRouter.post('/cart/items', (req, res, next) => {
3659
const order_id = req.signedCookies.order_id;
3760
const item = req.body;
3861
if (order_id) {
39-
api.orders.addItem(order_id, item).then(({status, json}) => {
62+
api.orders.addItem(order_id, item).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
4063
res.status(status).send(json);
4164
})
4265
} else {
@@ -61,7 +84,7 @@ ajaxRouter.post('/cart/items', (req, res, next) => {
6184
}
6285
}).then(({status, json}) => {
6386
res.cookie('order_id', json.id, serverSettings.cartCookieOptions);
64-
api.orders.addItem(json.id, item).then(({status, json}) => {
87+
api.orders.addItem(json.id, item).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
6588
res.status(status).send(json);
6689
})
6790
})
@@ -72,7 +95,7 @@ ajaxRouter.delete('/cart/items/:item_id', (req, res, next) => {
7295
const order_id = req.signedCookies.order_id;
7396
const item_id = req.params.item_id;
7497
if (order_id && item_id) {
75-
api.orders.deleteItem(order_id, item_id).then(({status, json}) => {
98+
api.orders.deleteItem(order_id, item_id).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
7699
res.status(status).send(json);
77100
})
78101
} else {
@@ -85,7 +108,7 @@ ajaxRouter.put('/cart/items/:item_id', (req, res, next) => {
85108
const item_id = req.params.item_id;
86109
const item = req.body;
87110
if (order_id && item_id) {
88-
api.orders.updateItem(order_id, item_id, item).then(({status, json}) => {
111+
api.orders.updateItem(order_id, item_id, item).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
89112
res.status(status).send(json);
90113
})
91114
} else {
@@ -96,7 +119,7 @@ ajaxRouter.put('/cart/items/:item_id', (req, res, next) => {
96119
ajaxRouter.put('/cart/checkout', (req, res, next) => {
97120
const order_id = req.signedCookies.order_id;
98121
if (order_id) {
99-
api.orders.checkout(order_id).then(({status, json}) => {
122+
api.orders.checkout(order_id).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
100123
res.clearCookie('order_id');
101124
res.status(status).send(json);
102125
})
@@ -108,7 +131,7 @@ ajaxRouter.put('/cart/checkout', (req, res, next) => {
108131
ajaxRouter.put('/cart', (req, res, next) => {
109132
const order_id = req.signedCookies.order_id;
110133
if (order_id) {
111-
api.orders.update(order_id, req.body).then(({status, json}) => {
134+
api.orders.update(order_id, req.body).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
112135
res.status(status).send(json);
113136
})
114137
} else {
@@ -119,7 +142,7 @@ ajaxRouter.put('/cart', (req, res, next) => {
119142
ajaxRouter.put('/cart/shipping_address', (req, res, next) => {
120143
const order_id = req.signedCookies.order_id;
121144
if (order_id) {
122-
api.orders.updateShippingAddress(order_id, req.body).then(({status, json}) => {
145+
api.orders.updateShippingAddress(order_id, req.body).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
123146
res.status(status).send(json);
124147
})
125148
} else {
@@ -130,7 +153,7 @@ ajaxRouter.put('/cart/shipping_address', (req, res, next) => {
130153
ajaxRouter.put('/cart/billing_address', (req, res, next) => {
131154
const order_id = req.signedCookies.order_id;
132155
if (order_id) {
133-
api.orders.updateBillingAddress(order_id, req.body).then(({status, json}) => {
156+
api.orders.updateBillingAddress(order_id, req.body).then(cartResponse => fillCartItems(cartResponse)).then(({status, json}) => {
134157
res.status(status).send(json);
135158
})
136159
} else {
@@ -144,11 +167,11 @@ ajaxRouter.get('/product_categories', (req, res, next) => {
144167
})
145168
})
146169

147-
ajaxRouter.get('/product_categories/:id', (req, res, next) => {
148-
api.product_categories.retrieve(req.params.id).then(({status, json}) => {
149-
res.status(status).header('Cache-Control', DEFAULT_CACHE_CONTROL).send(json);
150-
})
151-
})
170+
// ajaxRouter.get('/product_categories/:id', (req, res, next) => {
171+
// api.product_categories.retrieve(req.params.id).then(({status, json}) => {
172+
// res.status(status).header('Cache-Control', DEFAULT_CACHE_CONTROL).send(json);
173+
// })
174+
// })
152175

153176
ajaxRouter.get('/pages/:id', (req, res, next) => {
154177
api.pages.retrieve(req.params.id).then(({status, json}) => {
@@ -182,11 +205,11 @@ ajaxRouter.get('/shipping_methods', (req, res, next) => {
182205
})
183206
})
184207

185-
ajaxRouter.get('/countries', (req, res, next) => {
186-
api.countries.list().then(({status, json}) => {
187-
res.status(status).header('Cache-Control', DEFAULT_CACHE_CONTROL).send(json);
188-
})
189-
})
208+
// ajaxRouter.get('/countries', (req, res, next) => {
209+
// api.countries.list().then(({status, json}) => {
210+
// res.status(status).header('Cache-Control', DEFAULT_CACHE_CONTROL).send(json);
211+
// })
212+
// })
190213

191214
ajaxRouter.all('*', (req, res, next) => {
192215
res.status(405).send({'error': 'Method Not Allowed'});

src/store/server/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ storeRouter.get('*', (req, res, next) => {
7474
api.sitemap.retrieve({ path: req.path, enabled: true }),
7575
api.checkout_fields.list(),
7676
api.settings.retrieve()
77-
]).then(([templateHtml, sitemapDetails, checkout_fields, settings]) => {
77+
]).then(([templateHtml, sitemapDetails, checkoutFields, settings]) => {
7878
if (sitemapDetails.status === 200 || sitemapDetails.status === 404) {
7979
let currentPage = sitemapDetails.json;
8080
if(sitemapDetails.status === 404) {
@@ -84,7 +84,7 @@ storeRouter.get('*', (req, res, next) => {
8484
}
8585
}
8686

87-
getInitialState(req, checkout_fields.json, currentPage, settings.json).then(initialState => {
87+
getInitialState(req, checkoutFields.json, currentPage, settings.json).then(initialState => {
8888
const store = createStore(reducers, initialState, applyMiddleware(thunkMiddleware));
8989
const routes = createRoutes(store);
9090

src/store/shared/actions.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,19 +359,18 @@ const getCommonData = (req, currentPage, productsFilter) => {
359359
});
360360
}
361361

362-
export const getInitialState = (req, checkout_fields, currentPage, settings) => {
362+
export const getInitialState = (req, checkoutFields, currentPage, settings) => {
363363
let initialState = {
364364
app: {
365-
settings: settings,
366-
location: null,
367365
currentPage: currentPage,
366+
pageData: {},
367+
settings: settings,
368368
currentCategory: null,
369369
currentProduct: null,
370370
categories: [],
371371
products: [],
372-
payment_methods: [],
373-
shipping_methods: [],
374-
page: {},
372+
paymentMethods: [],
373+
shippingMethods: [],
375374
loadingProducts: false,
376375
loadingMoreProducts: false,
377376
loadingShippingMethods: false,
@@ -383,7 +382,7 @@ export const getInitialState = (req, checkout_fields, currentPage, settings) =>
383382
limit: 30,
384383
fields: 'path,id,name,category_id,category_name,sku,images,enabled,discontinued,stock_status,stock_quantity,price,on_sale,regular_price'
385384
},
386-
checkout_fields: checkout_fields
385+
checkoutFields: checkoutFields
387386
}
388387
}
389388

@@ -397,7 +396,7 @@ export const getInitialState = (req, checkout_fields, currentPage, settings) =>
397396
initialState.app.products = commonData.products;
398397
initialState.app.currentCategory = commonData.currentCategory;
399398
initialState.app.cart = commonData.cart;
400-
initialState.app.page = commonData.page;
399+
initialState.app.pageData = commonData.page;
401400
return initialState;
402401
})
403402

0 commit comments

Comments
 (0)