-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3020 from reactioncommerce/seun-migration-updates-2
Migration updates to fix Localization, uol, and paymentMethod errors on 1.0 > 1.5
- Loading branch information
Showing
10 changed files
with
148 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
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
59 changes: 59 additions & 0 deletions
59
imports/plugins/core/versions/server/migrations/16_update_billing_paymentMethod.js
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
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 } | ||
}); | ||
}); | ||
} | ||
}); |
39 changes: 39 additions & 0 deletions
39
imports/plugins/core/versions/server/migrations/17_set_shop_uols.js
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
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 }); | ||
} | ||
}); |
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
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
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
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