dont crash for undefined categories

This commit is contained in:
Barış Soner Uşaklı
2018-11-29 07:55:56 -05:00
parent 6330d51446
commit 29e9310aa5

View File

@@ -335,12 +335,14 @@ Categories.flattenCategories = function (allCategories, categoryData) {
*/ */
Categories.getTree = function (categories, parentCid) { Categories.getTree = function (categories, parentCid) {
parentCid = parentCid || 0; parentCid = parentCid || 0;
const cids = categories.map(category => category.cid); const cids = categories.map(category => category && category.cid);
const cidToCategory = {}; const cidToCategory = {};
const parents = {}; const parents = {};
cids.forEach((cid, index) => { cids.forEach((cid, index) => {
if (cid) {
cidToCategory[cid] = categories[index]; cidToCategory[cid] = categories[index];
parents[cid] = _.clone(categories[index]); parents[cid] = _.clone(categories[index]);
}
}); });
const tree = []; const tree = [];