Skip to content

Commit

Permalink
Update cart schema to include all product data (#2610)
Browse files Browse the repository at this point in the history
* update cart schema with Product data

* add product data to cart update

* test fixes

* fixing tests

Suggested here: Meteor-Community-Packages/meteor-collection2#245

* lint fixes

* comment some code
  • Loading branch information
kieckhafer authored and Aaron Judd committed Aug 2, 2017
1 parent b6e18a4 commit 4f236cc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions imports/plugins/included/inventory/server/hooks/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function markInventoryShipped(doc) {
shopId: orderItem.shopId,
quantity: orderItem.quantity,
productId: orderItem.productId,
product: orderItem.product,
variants: orderItem.variants,
title: orderItem.title
};
Expand All @@ -120,6 +121,7 @@ function markInventorySold(doc) {
shopId: orderItem.shopId,
quantity: orderItem.quantity,
productId: orderItem.productId,
product: orderItem.product,
variants: orderItem.variants,
title: orderItem.title
};
Expand Down
5 changes: 4 additions & 1 deletion lib/collections/schemas/cart.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SimpleSchema } from "meteor/aldeed:simple-schema";
import { shopIdAutoValue } from "./helpers";
import { Payment } from "./payments";
import { ProductVariant } from "./products";
import { Product, ProductVariant } from "./products";
import { Shipment, ShippingParcel } from "./shipping";
import { Workflow } from "./workflow";

Expand Down Expand Up @@ -29,6 +29,9 @@ export const CartItem = new SimpleSchema({
type: Number,
min: 0
},
product: {
type: Product
},
variants: {
type: ProductVariant
},
Expand Down
2 changes: 2 additions & 0 deletions server/imports/fixtures/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function getCartItem(options = {}) {
productId: product._id,
shopId: getShop()._id,
quantity: _.random(1, selectedOption.inventoryQuantity),
product: product,
variants: selectedOption,
title: product.title
};
Expand All @@ -53,6 +54,7 @@ export function createCart(productId, variantId) {
productId: product._id,
shopId: getShop()._id,
quantity: 1,
product: product,
variants: variant,
title: product.title
};
Expand Down
2 changes: 2 additions & 0 deletions server/imports/fixtures/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default function () {
shopId: product.shopId,
productId: product._id,
quantity: 1,
product: product,
variants: selectedOption,
workflow: {
status: "new"
Expand All @@ -119,6 +120,7 @@ export default function () {
shopId: product2.shopId,
productId: product2._id,
quantity: 1,
product: product2,
variants: selectedOption2,
workflow: {
status: "new"
Expand Down
4 changes: 4 additions & 0 deletions server/methods/core/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ Meteor.methods({
if (cartVariantExists) {
return Collections.Cart.update({
"_id": cart._id,
"items.product._id": productId,
"items.variants._id": variantId
}, {
$inc: {
Expand Down Expand Up @@ -402,6 +403,7 @@ Meteor.methods({
shopId: product.shopId,
productId: productId,
quantity: quantity,
product: product,
variants: variant,
title: product.title,
type: product.type,
Expand Down Expand Up @@ -477,6 +479,8 @@ Meteor.methods({
_id: itemId
}
}
}, {
getAutoValues: false // See https://github.com/aldeed/meteor-collection2/issues/245
}, (error, result) => {
if (error) {
Logger.error(error);
Expand Down

0 comments on commit 4f236cc

Please sign in to comment.