diff --git a/server/publications/collections/product-publications.app-test.js b/server/publications/collections/product-publications.app-test.js index 209d08e3b2a..7049ef16e77 100644 --- a/server/publications/collections/product-publications.app-test.js +++ b/server/publications/collections/product-publications.app-test.js @@ -38,7 +38,7 @@ describe("Publication", function () { max: 19.99 }; - before(function () { + beforeEach(function () { Collections.Products.direct.remove({}); // a product with price range A, and not visible diff --git a/server/publications/collections/products.js b/server/publications/collections/products.js index eee32a7c33b..55231b46bd9 100644 --- a/server/publications/collections/products.js +++ b/server/publications/collections/products.js @@ -2,7 +2,7 @@ import _ from "lodash"; import { Meteor } from "meteor/meteor"; import { check, Match } from "meteor/check"; import { SimpleSchema } from "meteor/aldeed:simple-schema"; -import { Products, Revisions } from "/lib/collections"; +import { Products, Shops, Revisions } from "/lib/collections"; import { Reaction, Logger } from "/server/api"; import { RevisionApi } from "/imports/plugins/core/revisions/lib/api/revisions"; import { findProductMedia } from "./product"; @@ -101,6 +101,30 @@ Meteor.publish("Products", function (productScrollLimit = 24, productFilters, so return this.ready(); } + const shopIdsOrSlugs = productFilters && productFilters.shops; + + if (shopIdsOrSlugs) { + // Get all shopIds associated with the slug or Id + const shopIds = Shops.find({ + $or: [{ + _id: { + $in: shopIdsOrSlugs + } + }, { + slug: { + $in: shopIdsOrSlugs + } + }] + }).map((shop) => shop._id); + + // If we found shops, update the productFilters + if (shopIds) { + productFilters.shops = shopIds; + } else { + return this.ready(); + } + } + // Init default selector - Everyone can see products that fit this selector const selector = { ancestors: [], // Lookup top-level products