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

Fix Setting product visibility is not reflected in the Product Grid reactively #2561

Merged
merged 13 commits into from
Jul 25, 2017
Merged
72 changes: 61 additions & 11 deletions server/publications/collections/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,30 +423,80 @@ Meteor.publish("Products", function (productScrollLimit = 24, productFilters, so
let newSelector = selector;

// Remove hashtag filter from selector (hashtags are not applied to variants, we need to get variants)
if (productFilters && productFilters.tags) {
newSelector = _.omit(selector, ["hashtags"]);
if (productFilters) {
newSelector = _.omit(selector, ["hashtags", "ancestors"]);

if (productFilters.tags) {
// Re-configure selector to pick either Variants of one of the top-level products, or the top-level products in the filter
_.extend(newSelector, {
$or: [
{
ancestors: {
$in: productIds
}
},
{ $and: [
{
hashtags: {
$in: productFilters.tags
}
}, {
_id: {
$in: productIds
}
}
]
}
]
});
}
// filter by query
if (productFilters.query) {
const cond = {
$regex: productFilters.query,
$options: "i"
};
_.extend(newSelector, {
$or: [{
title: cond
}, {
pageTitle: cond
}, {
description: cond
}, {
ancestors: {
$in: productIds
}
},
{
_id: {
$in: productIds
}
}]
});
}
} else {
newSelector = _.omit(selector, ["hashtags", "ancestors"]);

// Re-configure selector to pick either Variants of one of the top-level products, or the top-level products in the filter
_.extend(newSelector, {
$or: [
{
ancestors: {
$in: productIds
}
}, {
hashtags: {
$in: productFilters.tags
},
{
_id: {
$in: productIds
}
}
]
});
}
// Returning Complete product tree for top level products to avoid sold out warning.
const productCursor = Products.find({
$or: [
{ _id: { $in: productIds } },
{ ancestors: { $in: productIds } }
]
const productCursor = Products.find(newSelector, {
sort: sort,
limit: productScrollLimit
});

const mediaProductIds = productCursor.fetch().map((p) => p._id);
Expand Down