@@ -69,14 +69,14 @@ class LineItems extends Component {
- {formatPriceString(shippingRate)}
+ {formatPriceString(uniqueItem.shipping.rate)}
Item tax
- {uniqueItem.taxDetail ? formatPriceString(uniqueItem.taxDetail.tax / quantity) : formatPriceString(0)}
+ {uniqueItem.taxDetail ? formatPriceString(uniqueItem.taxDetail.tax / uniqueItem.quantity) : formatPriceString(0)}
@@ -92,10 +92,10 @@ class LineItems extends Component {
{uniqueItem.taxDetail ?
- {this.calculateTotal(uniqueItem.variants.price, shippingRate, uniqueItem.taxDetail.tax)}
+ {this.calculateTotal(uniqueItem.variants.price, uniqueItem.shipping.rate, uniqueItem.taxDetail.tax)}
:
- {this.calculateTotal(uniqueItem.variants.price, shippingRate, 0)}
+ {this.calculateTotal(uniqueItem.variants.price, uniqueItem.shipping.rate, 0)}
}
@@ -107,22 +107,21 @@ class LineItems extends Component {
render() {
const { uniqueItems, isExpanded, onClose } = this.props;
-
return (
{uniqueItems.map((uniqueItem) => {
- if (!isExpanded(uniqueItem.cartItemId)) {
+ if (!isExpanded(uniqueItem._id)) {
return (
-
{ this.renderLineItem(uniqueItem.items[0], uniqueItem.items.length) }
+
{ this.renderLineItem(uniqueItem) }
);
}
return (
-
+
-
diff --git a/imports/plugins/core/orders/client/containers/lineItemsContainer.js b/imports/plugins/core/orders/client/containers/lineItemsContainer.js
index 0e6f39d6bed..bf55df9f552 100644
--- a/imports/plugins/core/orders/client/containers/lineItemsContainer.js
+++ b/imports/plugins/core/orders/client/containers/lineItemsContainer.js
@@ -73,7 +73,6 @@ class LineItemsContainer extends Component {
render() {
const { invoice, uniqueItems } = this.props;
-
return (
o.quantity)
});
return invoice;
},
@@ -479,12 +476,10 @@ Template.coreOrderShippingInvoice.helpers({
const currentData = Template.currentData();
const shipment = currentData.fulfillment;
- // returns array of individual items that have been checked out
- const returnItems = _.map(shipment.items, (item) => {
- const originalItem = _.find(order.items, {
- _id: item._id
- });
- return _.extend(originalItem, item);
+ // returns order items with shipping detail
+ const returnItems = _.map(order.items, (item) => {
+ const shipping = shipment.shipmentMethod;
+ return _.extend(item, { shipping });
});
let items;
@@ -495,43 +490,13 @@ Template.coreOrderShippingInvoice.helpers({
items = _.map(returnItems, (item) => {
const taxDetail = _.find(taxes, {
- lineNumber: item.cartItemId
+ lineNumber: item._id
});
return _.extend(item, { taxDetail });
});
} else {
items = returnItems;
}
-
- /**
- * It goes through individual items and groups similar items using the cartItemId.
- * The output is an object whose keys are cartItemId and every item with the same
- * cartItemId is added as a value
- */
- let uniqueItems = items.reduce((carts, item) => {
- let cart;
-
- if (carts[item.cartItemId]) {
- cart = carts[item.cartItemId];
- cart = Object.assign({}, cart, {
- items: [...cart.items, item]
- });
- } else {
- cart = {
- cartItemId: item.cartItemId,
- productId: item.productId,
- shippingRate: shipment.shipmentMethod.rate,
- items: [item]
- };
- }
-
- carts[item.cartItemId] = cart;
- return carts;
- }, {});
-
- // Converts the uniqueItems object to an array
- uniqueItems = Object.keys(uniqueItems).map(k => uniqueItems[k]);
-
- return uniqueItems;
+ return items;
}
});
diff --git a/imports/plugins/included/inventory/server/hooks/hooks.js b/imports/plugins/included/inventory/server/hooks/hooks.js
index 07288de4c57..924e61f4a89 100644
--- a/imports/plugins/included/inventory/server/hooks/hooks.js
+++ b/imports/plugins/included/inventory/server/hooks/hooks.js
@@ -97,7 +97,7 @@ function markInventoryShipped(doc) {
const cartItems = [];
for (const orderItem of orderItems) {
const cartItem = {
- _id: orderItem.cartItemId,
+ _id: orderItem.cartItemId || orderItem._id,
shopId: orderItem.shopId,
quantity: orderItem.quantity,
productId: orderItem.productId,
@@ -112,9 +112,10 @@ function markInventoryShipped(doc) {
function markInventorySold(doc) {
const orderItems = doc.items;
const cartItems = [];
+ // If a cartItemId exists it's a legacy order and we use that
for (const orderItem of orderItems) {
const cartItem = {
- _id: orderItem.cartItemId,
+ _id: orderItem.cartItemId || orderItem._id,
shopId: orderItem.shopId,
quantity: orderItem.quantity,
productId: orderItem.productId,
diff --git a/imports/plugins/included/payments-stripe/server/methods/stripeapi.js b/imports/plugins/included/payments-stripe/server/methods/stripeapi.js
index 4490e98454a..5fbd338ceb4 100644
--- a/imports/plugins/included/payments-stripe/server/methods/stripeapi.js
+++ b/imports/plugins/included/payments-stripe/server/methods/stripeapi.js
@@ -1,4 +1,5 @@
/* eslint camelcase: 0 */
+import _ from "lodash";
import { Meteor } from "meteor/meteor";
import { SimpleSchema } from "meteor/aldeed:simple-schema";
import { Packages } from "/lib/collections";
diff --git a/server/methods/core/cart-create.app-test.js b/server/methods/core/cart-create.app-test.js
index 8dfc79f05fb..f7a4219e931 100644
--- a/server/methods/core/cart-create.app-test.js
+++ b/server/methods/core/cart-create.app-test.js
@@ -185,7 +185,7 @@ describe("Add/Create cart methods", function () {
return done();
});
- it("should throw an error if order creation has failed", function (done) {
+ it("should throw an error if order creation has failed", function () {
const cart = Factory.create("cartToOrder");
spyOnMethod("copyCartToOrder", cart.userId);
// The main moment of test. We are spy on `insert` operation but do not
@@ -196,7 +196,6 @@ describe("Add/Create cart methods", function () {
}
expect(copyCartFunc).to.throw(Meteor.Error, /Invalid request/);
expect(insertStub).to.have.been.called;
- return done();
});
it("should create an order", function (done) {
diff --git a/server/methods/core/cart.js b/server/methods/core/cart.js
index 0f67fc4ed64..e595cf6a612 100644
--- a/server/methods/core/cart.js
+++ b/server/methods/core/cart.js
@@ -515,6 +515,12 @@ Meteor.methods({
const order = Object.assign({}, cart);
const sessionId = cart.sessionId;
+ if (!order.items || order.items.length === 0) {
+ const msg = "An error occurred saving the order. Missing cart items.";
+ Logger.error(msg);
+ throw new Meteor.Error("no-cart-items", msg);
+ }
+
Logger.debug("cart/copyCartToOrder", cartId);
// reassign the id, we'll get a new orderId
order.cartId = cart._id;
@@ -590,58 +596,27 @@ Meteor.methods({
};
}
- order.billing[0].currency.exchangeRate = exchangeRate;
-
-
- const expandedItems = [];
-
- // init item level workflow
- _.each(order.items, function (item) {
- // Split items based on their quantity
- for (let i = 0; i < item.quantity; i++) {
- // Clone Item
- const itemClone = _.clone(item);
-
- // Remove the quantity since we'll be expanding each item as
- // it's own record
- itemClone.quantity = 1;
-
- itemClone._id = Random.id();
- itemClone.cartItemId = item._id; // used for transitioning inventry
- itemClone.workflow = {
- status: "new"
- };
-
- expandedItems.push(itemClone);
-
- // Add each item clone to the first shipment
- if (order.shipping[0].items) {
- order.shipping[0].items.push({
- _id: itemClone._id,
- productId: itemClone.productId,
- shopId: itemClone.shopId,
- variantId: itemClone.variants._id
- });
- }
+ _.each(order.items, (item) => {
+ if (order.shipping[0].items) {
+ order.shipping[0].items.push({
+ _id: item._id,
+ productId: item.productId,
+ shopId: item.shopId,
+ variantId: item.variants._id
+ });
}
});
- // Replace the items with the expanded array of items
- order.items = expandedItems;
+ order.shipping[0].items.packed = false;
+ order.shipping[0].items.shipped = false;
+ order.shipping[0].items.delivered = false;
- if (!order.items || order.items.length === 0) {
- const msg = "An error occurred saving the order. Missing cart items.";
- Logger.error(msg);
- throw new Meteor.Error("no-cart-items", msg);
- }
-
- // set new workflow status
+ order.billing[0].currency.exchangeRate = exchangeRate;
order.workflow.status = "new";
order.workflow.workflow = ["coreOrderWorkflow/created"];
// insert new reaction order
const orderId = Collections.Orders.insert(order);
- Logger.info("Created orderId", orderId);
if (orderId) {
Collections.Cart.remove({