From cce3ca8e14f44e3ce6f0aad9c236303eec7690fb Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Tue, 3 Oct 2017 18:48:50 +0100 Subject: [PATCH 1/9] Set unitsOfLength to optional on shop schema to allow shop creation when no UOL value passed --- lib/collections/schemas/shops.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/collections/schemas/shops.js b/lib/collections/schemas/shops.js index b7f8cd62488..cbb1a0130c1 100644 --- a/lib/collections/schemas/shops.js +++ b/lib/collections/schemas/shops.js @@ -252,7 +252,8 @@ export const Shop = new SimpleSchema({ label: "Base Unit of Length" }, "unitsOfLength": { - type: [Object] + type: [Object], + optional: true }, "unitsOfLength.$.uol": { type: String, From 9f83dbd44de8797c6c0040b40c5cfd62e03002ef Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Tue, 3 Oct 2017 19:22:38 +0100 Subject: [PATCH 2/9] Check if array of values exist before trying to loop --- .../client/containers/localizationSettings.js | 24 +++++++++++-------- .../templates/settings/sellerShopSettings.js | 24 +++++++++++-------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/imports/plugins/core/i18n/client/containers/localizationSettings.js b/imports/plugins/core/i18n/client/containers/localizationSettings.js index f033fec6ad3..292ffed81b6 100644 --- a/imports/plugins/core/i18n/client/containers/localizationSettings.js +++ b/imports/plugins/core/i18n/client/containers/localizationSettings.js @@ -109,20 +109,24 @@ function composer(props, onData) { const unitsOfMeasure = Shops.findOne().unitsOfMeasure; const uomOptions = []; - for (const measure of unitsOfMeasure) { - uomOptions.push({ - label: i18next.t(`uom.${measure.uom}`, { defaultValue: measure.uom }), - value: measure.uom - }); + if (Array.isArray(unitsOfMeasure)) { + for (const measure of unitsOfMeasure) { + uomOptions.push({ + label: i18next.t(`uom.${measure.uom}`, { defaultValue: measure.uom }), + value: measure.uom + }); + } } const unitsOfLength = Shops.findOne().unitsOfLength; const uolOptions = []; - for (const length of unitsOfLength) { - uolOptions.push({ - label: i18next.t(`uol.${length.uol}`, { defaultValue: length.uol }), - value: length.uol - }); + if (Array.isArray(unitsOfLength)) { + for (const length of unitsOfLength) { + uolOptions.push({ + label: i18next.t(`uol.${length.uol}`, { defaultValue: length.uol }), + value: length.uol + }); + } } const label = i18next.t("app.timezoneOptions", "Choose timezone"); diff --git a/imports/plugins/included/marketplace/client/templates/settings/sellerShopSettings.js b/imports/plugins/included/marketplace/client/templates/settings/sellerShopSettings.js index 80d417373a0..bb788d0e9c7 100644 --- a/imports/plugins/included/marketplace/client/templates/settings/sellerShopSettings.js +++ b/imports/plugins/included/marketplace/client/templates/settings/sellerShopSettings.js @@ -120,11 +120,13 @@ Template.sellerShopSettings.helpers({ const unitsOfLength = sellerShop.unitsOfLength; const uolOptions = []; - for (const length of unitsOfLength) { - uolOptions.push({ - label: i18next.t(`uol.${length.uol}`, { defaultValue: length.uol }), - value: length.uol - }); + if (Array.isArray(unitsOfLength)) { + for (const length of unitsOfLength) { + uolOptions.push({ + label: i18next.t(`uol.${length.uol}`, { defaultValue: length.uol }), + value: length.uol + }); + } } return uolOptions; }, @@ -138,11 +140,13 @@ Template.sellerShopSettings.helpers({ const unitsOfMeasure = sellerShop.unitsOfMeasure; const uomOptions = []; - for (const measure of unitsOfMeasure) { - uomOptions.push({ - label: i18next.t(`uom.${measure.uom}`, { defaultValue: measure.uom }), - value: measure.uom - }); + if (Array.isArray(unitsOfMeasure)) { + for (const measure of unitsOfMeasure) { + uomOptions.push({ + label: i18next.t(`uom.${measure.uom}`, { defaultValue: measure.uom }), + value: measure.uom + }); + } } return uomOptions; }, From 308dcbdbafd660fd1d08680139210457dad0a64f Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Tue, 3 Oct 2017 22:23:42 +0100 Subject: [PATCH 3/9] Add the new picked and packed statues on shipment workflow --- .../15_update_shipping_status_to_workflow.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/15_update_shipping_status_to_workflow.js b/imports/plugins/core/versions/server/migrations/15_update_shipping_status_to_workflow.js index 474f2110af9..495112f7007 100644 --- a/imports/plugins/core/versions/server/migrations/15_update_shipping_status_to_workflow.js +++ b/imports/plugins/core/versions/server/migrations/15_update_shipping_status_to_workflow.js @@ -12,13 +12,21 @@ Migrations.add({ if (currentShipping.packed) { currentShipping.workflow.status = "coreOrderWorkflow/packed"; - currentShipping.workflow.workflow = ["coreOrderWorkflow/notStarted", "coreOrderWorkflow/packed"]; + currentShipping.workflow.workflow = [ + "coreOrderWorkflow/notStarted", + "coreOrderWorkflow/picked", + "coreOrderWorkflow/packed" + ]; } if (currentShipping.shipped) { currentShipping.workflow.status = "coreOrderWorkflow/shipped"; currentShipping.workflow.workflow = [ - "coreOrderWorkflow/notStarted", "coreOrderWorkflow/packed", "coreOrderWorkflow/shipped" + "coreOrderWorkflow/notStarted", + "coreOrderWorkflow/picked", + "coreOrderWorkflow/packed", + "coreOrderWorkflow/labeled", + "coreOrderWorkflow/shipped" ]; } @@ -26,7 +34,9 @@ Migrations.add({ currentShipping.workflow.status = "coreOrderWorkflow/delivered"; currentShipping.workflow.workflow = [ "coreOrderWorkflow/notStarted", + "coreOrderWorkflow/picked", "coreOrderWorkflow/packed", + "coreOrderWorkflow/labeled", "coreOrderWorkflow/shipped", "coreOrderWorkflow/delivered" ]; From 5f47060665c09dcb1b3447ad6b9f17cdf7439fad Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Fri, 6 Oct 2017 20:50:22 +0100 Subject: [PATCH 4/9] Add up migration for paymentMethod new fields --- .../core/orders/client/components/invoice.js | 2 +- .../16_update_billing_paymentMethod.js | 37 +++++++++++++++++++ .../core/versions/server/migrations/index.js | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js diff --git a/imports/plugins/core/orders/client/components/invoice.js b/imports/plugins/core/orders/client/components/invoice.js index 58bb9491565..5136e0e042b 100644 --- a/imports/plugins/core/orders/client/components/invoice.js +++ b/imports/plugins/core/orders/client/components/invoice.js @@ -97,7 +97,7 @@ class Invoice extends Component { } - {refunds && refunds.map((refund) => ( + {Array.isArray(refunds) && refunds.map((refund) => (
Refunded on: {this.formatDate(refund.created, "MM/D/YYYY")}
{formatPriceString(refund.amount)}
diff --git a/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js b/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js new file mode 100644 index 00000000000..aa8ab3e3092 --- /dev/null +++ b/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js @@ -0,0 +1,37 @@ +import { Migrations } from "meteor/percolate:migrations"; +import { Cart, Orders, Packages } from "/lib/collections"; + +const paymentNameDict = { + Example: "example-paymentmethod", + Braintree: "reaction-braintree", + AuthNet: "reaction-auth-net", + PaypalExpress: "reaction-paypal", + PayflowPro: "reaction-paypal", + Stripe: "reaction-stripe" +}; + +Migrations.add({ + version: 16, + up() { + Orders.find().forEach((order) => { + order.billing.forEach((billing) => { + const packageData = Packages.findOne({ + name: paymentNameDict[billing.paymentMethod.processor], + shopId: billing.shopId + }); + const settingsKey = packageData && Array.isArray(packageData.registry) + && packageData.registry[0] && packageData.registry[0].settingsKey; + + billing.paymentMethod.paymentPackageId = packageData && packageData._id; + billing.paymentMethod.paymentSettingsKey = settingsKey; + }); + + Orders.update({ _id: order._id }, { + $set: { billing: order.billing } + }); + }); + }, + down() { + + } +}); diff --git a/imports/plugins/core/versions/server/migrations/index.js b/imports/plugins/core/versions/server/migrations/index.js index eaadcf982bb..9bbd0c804d2 100644 --- a/imports/plugins/core/versions/server/migrations/index.js +++ b/imports/plugins/core/versions/server/migrations/index.js @@ -13,3 +13,4 @@ import "./12_add_shopId_on_billing"; import "./13_add_shopId_on_shipping"; import "./14_rebuild_order_search_collection"; import "./15_update_shipping_status_to_workflow"; +import "./16_update_billing_paymentMethod"; From 54e9948f53897e0314d395e0ac9318f5b28c62fa Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Fri, 6 Oct 2017 22:56:16 +0100 Subject: [PATCH 5/9] Migrate cartItems and set proper settingsKey --- .../client/containers/invoiceContainer.js | 3 ++- .../16_update_billing_paymentMethod.js | 18 +++++++++++++++--- lib/collections/schemas/payments.js | 2 -- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/imports/plugins/core/orders/client/containers/invoiceContainer.js b/imports/plugins/core/orders/client/containers/invoiceContainer.js index f94e06c18aa..781ab06c5fc 100644 --- a/imports/plugins/core/orders/client/containers/invoiceContainer.js +++ b/imports/plugins/core/orders/client/containers/invoiceContainer.js @@ -223,7 +223,8 @@ class InvoiceContainer extends Component { const paymentMethodId = orderBillingInfo.paymentMethod && orderBillingInfo.paymentMethod.paymentPackageId; const paymentMethodName = orderBillingInfo.paymentMethod && orderBillingInfo.paymentMethod.paymentSettingsKey; const paymentMethod = Packages.findOne({ _id: paymentMethodId }); - const isRefundable = paymentMethod && paymentMethod.settings[paymentMethodName].support.includes("Refund"); + const isRefundable = paymentMethod && paymentMethod.settings && paymentMethod.settings[paymentMethodName] + && paymentMethod.settings[paymentMethodName].support.includes("Refund"); return isRefundable; } diff --git a/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js b/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js index aa8ab3e3092..2963f6ee9f0 100644 --- a/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js +++ b/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js @@ -19,11 +19,22 @@ Migrations.add({ name: paymentNameDict[billing.paymentMethod.processor], shopId: billing.shopId }); - const settingsKey = packageData && Array.isArray(packageData.registry) - && packageData.registry[0] && packageData.registry[0].settingsKey; + const registry = packageData && Array.isArray(packageData.registry) + && packageData.registry[0] && packageData.registry[0]; + // create key in similar pattern created in Packages pub transform + const settingsKey = (registry.name || packageData.name).split("/").splice(-1)[0]; + const cartItems = order.items.map((item) => ({ + _id: item._id, + productId: item.productId, + variantId: item.variants._id, + shopId: item.shopId, + quantity: item.quantity + })); billing.paymentMethod.paymentPackageId = packageData && packageData._id; billing.paymentMethod.paymentSettingsKey = settingsKey; + billing.paymentMethod.shopId = billing.shopId; + billing.paymentMethod.items = cartItems; }); Orders.update({ _id: order._id }, { @@ -32,6 +43,7 @@ Migrations.add({ }); }, down() { - + // + // } }); diff --git a/lib/collections/schemas/payments.js b/lib/collections/schemas/payments.js index dd7b165361d..f04d584f1e8 100644 --- a/lib/collections/schemas/payments.js +++ b/lib/collections/schemas/payments.js @@ -118,12 +118,10 @@ export const PaymentMethod = new SimpleSchema({ optional: true, blackbox: true }, - // TODO: Build a migration to add payment items to payment methods items: { type: [PaymentItem], optional: true }, - // TODO: Build migration to add shopIds to payment methods shopId: { type: String, optional: true From 6248d1eb6a9ba04d19f73ee0dbcf72c42fe950f7 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Fri, 6 Oct 2017 23:04:40 +0100 Subject: [PATCH 6/9] Add down migration 16 on paymentMethod --- .../migrations/16_update_billing_paymentMethod.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js b/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js index 2963f6ee9f0..4ca35769149 100644 --- a/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js +++ b/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js @@ -43,7 +43,16 @@ Migrations.add({ }); }, down() { - // - // + Orders.find().forEach((order) => { + order.billing.forEach((billing) => { + delete billing.paymentMethod.paymentPackageId; + delete billing.paymentMethod.paymentSettingsKey; + delete billing.paymentMethod.shopId; + delete billing.paymentMethod.items; + }); + Orders._collection.update({ _id: order._id }, { + $set: { items: order.billing } + }); + }); } }); From 901325c502699bcc60bbe2700be86ec9780c07ee Mon Sep 17 00:00:00 2001 From: Spencer Norman Date: Fri, 6 Oct 2017 22:45:46 -0600 Subject: [PATCH 7/9] Fix unitsOfLength schema --- lib/collections/schemas/shops.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/collections/schemas/shops.js b/lib/collections/schemas/shops.js index 2c149ba9d50..11530115ed7 100644 --- a/lib/collections/schemas/shops.js +++ b/lib/collections/schemas/shops.js @@ -258,14 +258,17 @@ export const Shop = new SimpleSchema({ }, "unitsOfLength.$.uol": { type: String, + optional: true, defaultValue: "in" }, "unitsOfLength.$.label": { type: String, + optional: true, defaultValue: "Inches" }, "unitsOfLength.$.default": { type: Boolean, + optional: true, defaultValue: false }, "baseUOM": { From fedf54cd0e30d7f419830ae89ed057a27a91a8d5 Mon Sep 17 00:00:00 2001 From: Spencer Norman Date: Fri, 6 Oct 2017 22:47:02 -0600 Subject: [PATCH 8/9] unitsOfLength migration --- .../server/migrations/17_set_shop_uols.js | 39 +++++++++++++++++++ .../core/versions/server/migrations/index.js | 1 + 2 files changed, 40 insertions(+) create mode 100644 imports/plugins/core/versions/server/migrations/17_set_shop_uols.js diff --git a/imports/plugins/core/versions/server/migrations/17_set_shop_uols.js b/imports/plugins/core/versions/server/migrations/17_set_shop_uols.js new file mode 100644 index 00000000000..0f2ca03c75a --- /dev/null +++ b/imports/plugins/core/versions/server/migrations/17_set_shop_uols.js @@ -0,0 +1,39 @@ +import { Migrations } from "meteor/percolate:migrations"; +import { Shops } from "/lib/collections"; + +Migrations.add({ + // Initializes shops without a baseUOL and without unitsOfLength to our default + version: 17, + up() { + Shops.update({ + baseUOL: { $exists: false }, + unitsOfLength: { $exists: false } + }, { + $set: { + baseUOL: "in", + unitsOfLength: [{ + uol: "in", + label: "Inches", + default: true + }, { + uol: "cm", + label: "Centimeters" + }, { + uol: "ft", + label: "Feet" + }] + } + }, { multi: true }); + }, + down() { + Shops.update({ + baseUOL: { $exists: true }, + unitsOfLength: { $exists: true } + }, { + $unset: { + baseUOL: "", + unitsOfLength: "" + } + }, { multi: true }); + } +}); diff --git a/imports/plugins/core/versions/server/migrations/index.js b/imports/plugins/core/versions/server/migrations/index.js index 9bbd0c804d2..5298528e16a 100644 --- a/imports/plugins/core/versions/server/migrations/index.js +++ b/imports/plugins/core/versions/server/migrations/index.js @@ -14,3 +14,4 @@ import "./13_add_shopId_on_shipping"; import "./14_rebuild_order_search_collection"; import "./15_update_shipping_status_to_workflow"; import "./16_update_billing_paymentMethod"; +import "./17_set_shop_uols"; From 76a03de02f441e804bc52b4668b8fc1c11059bea Mon Sep 17 00:00:00 2001 From: Spencer Norman Date: Fri, 6 Oct 2017 22:47:29 -0600 Subject: [PATCH 9/9] billing migration tweaks --- .../server/migrations/16_update_billing_paymentMethod.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js b/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js index 4ca35769149..b01644a4d6c 100644 --- a/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js +++ b/imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js @@ -1,5 +1,5 @@ import { Migrations } from "meteor/percolate:migrations"; -import { Cart, Orders, Packages } from "/lib/collections"; +import { Orders, Packages } from "/lib/collections"; const paymentNameDict = { Example: "example-paymentmethod", @@ -14,7 +14,7 @@ Migrations.add({ version: 16, up() { Orders.find().forEach((order) => { - order.billing.forEach((billing) => { + const newBilling = order.billing.map((billing) => { const packageData = Packages.findOne({ name: paymentNameDict[billing.paymentMethod.processor], shopId: billing.shopId @@ -35,10 +35,11 @@ Migrations.add({ billing.paymentMethod.paymentSettingsKey = settingsKey; billing.paymentMethod.shopId = billing.shopId; billing.paymentMethod.items = cartItems; + return billing; }); Orders.update({ _id: order._id }, { - $set: { billing: order.billing } + $set: { billing: newBilling } }); }); },