Created
January 15, 2018 09:59
-
-
Save prinzdezibel/5762013b2210e84d532aa2f937537581 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getSchemas } from "@reactioncommerce/reaction-collections"; | |
// Validate the subscription filter against our extended filter schema. | |
const Schemas = getSchemas(); | |
const filters = Schemas.filters; | |
/* Replace stock publication with our custom publication that knows how to filter | |
* featured products as well. | |
*/ | |
Meteor.startup(() => { | |
Meteor.default_server.publish_handlers.Products = publishFeaturedSwagProducts; | |
}); | |
/** | |
* Swag shop products publication. Knows how to filter for featured products. | |
* @param {Number} [productScrollLimit] - optional, defaults to 24 | |
* @param {Array} shops - array of shopId to retrieve product from. | |
* @return {Object} return product cursor | |
*/ | |
function publishFeaturedSwagProducts(productScrollLimit = 24, productFilters, sort = {}, editMode = true) { | |
check(productScrollLimit, Number); | |
check(productFilters, Match.OneOf(undefined, Object)); | |
check(sort, Match.OneOf(undefined, Object)); | |
check(editMode, Match.Maybe(Boolean)); | |
// -------------- %< -------------------- | |
// more stuff | |
// -------------- %< -------------------- | |
// BOF: swag shop featuredProduct filter | |
if (productFilters.hasOwnProperty("featuredProductLabel")) { | |
if (productFilters.featuredProductLabel !== "") { | |
_.extend(selector, { | |
// Return only featured products that match the label exactly | |
featuredProductLabel: productFilters.featuredProductLabel | |
}); | |
} else { | |
// Return all featured products, regardless of label | |
_.extend(selector, { | |
featuredProductLabel: { | |
$exists: true | |
} | |
}); | |
} | |
} | |
// EOF: swag shop featuredProduct filter | |
} // end if productFilters | |
// -------------- %< -------------------- | |
// more stuff | |
// -------------- %< -------------------- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment