diff --git a/core/server/models/product.js b/core/server/models/product.js index d17e8ae3e4..d6048d69b0 100644 --- a/core/server/models/product.js +++ b/core/server/models/product.js @@ -10,6 +10,12 @@ const Product = ghostBookshelf.Model.extend({ benefits: 'benefits' }, + applyCustomQuery() { + this.query((qb) => { + qb.leftJoin('stripe_prices', 'products.monthly_price_id', 'stripe_prices.id'); + }); + }, + async onSaving(model, _attr, options) { ghostBookshelf.Model.prototype.onSaving.apply(this, arguments); @@ -121,6 +127,10 @@ const Product = ghostBookshelf.Model.extend({ members() { return this.belongsToMany('Member', 'members_products', 'product_id', 'member_id'); } +}, { + orderDefaultRaw() { + return 'stripe_prices.amount asc'; + } }); const Products = ghostBookshelf.Collection.extend({ diff --git a/test/utils/fixture-utils.js b/test/utils/fixture-utils.js index 454357e068..49920d7cc2 100644 --- a/test/utils/fixture-utils.js +++ b/test/utils/fixture-utils.js @@ -462,7 +462,12 @@ const fixtures = { return models.Label.add(label, context.internal); }).then(function () { let productsToInsert = fixtureUtils.findModelFixtures('Product').entries; - return Promise.map(productsToInsert, product => models.Product.add(product, context.internal)); + return Promise.map(productsToInsert, async (product) => { + const found = await models.Product.findOne(product, context.internal); + if (!found) { + await models.Product.add(product, context.internal); + } + }); }).then(function () { return models.Product.findOne({}, context.internal); }).then(function (product) {