Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration updates to fix Localization, uol, and paymentMethod errors on 1.0 > 1.5 #3020

Merged
merged 11 commits into from
Oct 9, 2017
24 changes: 14 additions & 10 deletions imports/plugins/core/i18n/client/containers/localizationSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion imports/plugins/core/orders/client/components/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Invoice extends Component {
</div>
}

{refunds && refunds.map((refund) => (
{Array.isArray(refunds) && refunds.map((refund) => (
<div className="order-summary-form-group text-danger" key={refund.created} style={{ marginBottom: 15 }}>
<strong>Refunded on: {this.formatDate(refund.created, "MM/D/YYYY")}</strong>
<div className="invoice-details"><strong>{formatPriceString(refund.amount)}</strong></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@ 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"
];
}

if (currentShipping.delivered) {
currentShipping.workflow.status = "coreOrderWorkflow/delivered";
currentShipping.workflow.workflow = [
"coreOrderWorkflow/notStarted",
"coreOrderWorkflow/picked",
"coreOrderWorkflow/packed",
"coreOrderWorkflow/labeled",
"coreOrderWorkflow/shipped",
"coreOrderWorkflow/delivered"
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Migrations } from "meteor/percolate:migrations";
import { 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) => {
const newBilling = order.billing.map((billing) => {
const packageData = Packages.findOne({
name: paymentNameDict[billing.paymentMethod.processor],
shopId: billing.shopId
});
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;
return billing;
});

Orders.update({ _id: order._id }, {
$set: { billing: newBilling }
});
});
},
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 }
});
});
}
});
Original file line number Diff line number Diff line change
@@ -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 });
}
});
2 changes: 2 additions & 0 deletions imports/plugins/core/versions/server/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ 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";
import "./17_set_shop_uols";
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand All @@ -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;
},
Expand Down
2 changes: 0 additions & 2 deletions lib/collections/schemas/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/collections/schemas/shops.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,22 @@ export const Shop = new SimpleSchema({
label: "Base Unit of Length"
},
"unitsOfLength": {
type: [Object]
type: [Object],
optional: true
},
"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": {
Expand Down