diff --git a/ghost/admin/package.json b/ghost/admin/package.json index 89f78a7299..6f6a12e20e 100644 --- a/ghost/admin/package.json +++ b/ghost/admin/package.json @@ -1,6 +1,6 @@ { "name": "ghost-admin", - "version": "5.22.4", + "version": "5.22.5", "description": "Ember.js admin client for Ghost", "author": "Ghost Foundation", "homepage": "http://ghost.org", diff --git a/ghost/core/core/server/data/importer/importers/data/products.js b/ghost/core/core/server/data/importer/importers/data/products.js index b0466f180c..f753cb6b65 100644 --- a/ghost/core/core/server/data/importer/importers/data/products.js +++ b/ghost/core/core/server/data/importer/importers/data/products.js @@ -46,14 +46,10 @@ class ProductsImporter extends BaseImporter { this.requiredExistingData.stripe_prices, {id: row.monthly_price_id} ); - if (!monthlyStripePrice) { - invalidRows.push(row.id); - return; - } - row.monthly_price = row.monthly_price || monthlyStripePrice.amount; - row.currency = monthlyStripePrice.currency; + row.monthly_price = row.monthly_price || monthlyStripePrice?.amount; + row.currency = monthlyStripePrice?.currency; } - if (!row.yearly_price) { + if (!row.yearly_price || !row.currency) { const yearlyStripePrice = _.find( this.requiredFromFile.stripe_prices, {id: row.yearly_price_id} @@ -61,11 +57,11 @@ class ProductsImporter extends BaseImporter { this.requiredExistingData.stripe_prices, {id: row.yearly_price_id} ); - if (!yearlyStripePrice) { - invalidRows.push(row.id); - return; - } - row.yearly_price = row.yearly_price || yearlyStripePrice.amount; + row.yearly_price = row.yearly_price || yearlyStripePrice?.amount; + row.currency = yearlyStripePrice?.currency; + } + if (!row.yearly_price || !row.currency || !row.monthly_price) { + invalidRows.push(row.id); } }); this.dataToImport = this.dataToImport.filter(item => !invalidRows.includes(item.id)); diff --git a/ghost/core/package.json b/ghost/core/package.json index 67c8f23cb9..a63b7877b4 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -1,6 +1,6 @@ { "name": "ghost", - "version": "5.22.4", + "version": "5.22.5", "description": "The professional publishing platform", "author": "Ghost Foundation", "homepage": "https://ghost.org", diff --git a/ghost/core/test/unit/server/data/importer/importers/data/products.test.js b/ghost/core/test/unit/server/data/importer/importers/data/products.test.js index 028c412bc4..a78ccf95e0 100644 --- a/ghost/core/test/unit/server/data/importer/importers/data/products.test.js +++ b/ghost/core/test/unit/server/data/importer/importers/data/products.test.js @@ -15,6 +15,20 @@ const fakeProducts = [{ updated_at: '2022-10-21T04:47:42.000Z', monthly_price_id: 'price_1', yearly_price_id: 'price_2' +},{ + id: 'product_2', + name: 'New One', + slug: 'new-one', + active: 1, + welcome_page_url: null, + visibility: 'public', + trial_days: 0, + description: null, + type: 'paid', + created_at: '2022-10-20T11:11:32.000Z', + updated_at: '2022-10-21T04:47:42.000Z', + monthly_price_id: 'invalid_price_1', + yearly_price_id: 'invalid_price_2' }]; const fakePrices = [{ @@ -44,11 +58,39 @@ const fakePrices = [{ description: null, created_at: '2022-10-27T02:51:28.000Z', updated_at: '2022-10-27T02:51:28.000Z' +}, +{ + id: 'invalid_price_2', + stripe_price_id: 'price_XXXXXXXXXXXXXXXXXXXXXXXX', + stripe_product_id: 'prod_XXXXXXXXXXXXXX', + active: 1, + nickname: 'Yearly', + currency: 'usd', + amount: 0, + type: 'recurring', + interval: 'year', + description: null, + created_at: '2022-10-27T02:51:28.000Z', + updated_at: '2022-10-27T02:51:28.000Z' +}, +{ + id: 'invalid_price_2', + stripe_price_id: 'price_XXXXXXXXXXXXXXXXXXXXXXXX', + stripe_product_id: 'prod_XXXXXXXXXXXXXX', + active: 1, + nickname: 'Yearly', + currency: 'usd', + amount: 0, + type: 'recurring', + interval: 'year', + description: null, + created_at: '2022-10-27T02:51:28.000Z', + updated_at: '2022-10-27T02:51:28.000Z' }]; describe('ProductsImporter', function () { describe('#beforeImport', function () { - it('Removes the sender_email column', function () { + it('Uses the stripe_prices to populate pricing data', function () { const importer = new ProductsImporter({products: fakeProducts, stripe_prices: fakePrices}); importer.beforeImport(); @@ -60,5 +102,12 @@ describe('ProductsImporter', function () { assert(product.monthly_price === 500); assert(product.yearly_price === 5000); }); + + it('Does not import products with invalid price data', function () { + const importer = new ProductsImporter({products: fakeProducts, stripe_prices: fakePrices}); + + importer.beforeImport(); + assert(importer.dataToImport.length === 1); + }); }); });