Skip to content

Commit

Permalink
Merge pull request #3022 from reactioncommerce/spencer-fix-2890-shop-…
Browse files Browse the repository at this point in the history
…products-grid

Fix 2890 shop products grid
  • Loading branch information
mikemurray authored Oct 5, 2017
2 parents 9a29868 + 0abd951 commit 16c35a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion server/publications/collections/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 16c35a2

Please sign in to comment.