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

Inconsistent Product Image of Cart Item #2171

Merged
merged 5 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,19 @@ function composer(props, onData) {
const userId = Meteor.userId();
const shopId = Reaction.getShopId();
let productItems = Cart.findOne({ userId, shopId }).items;
let defaultImage;

productItems = productItems.map((item) => {
const defaultImage = Media.findOne({
Meteor.subscribe("CartItemImage", item);
defaultImage = Media.findOne({
"metadata.variantId": item.variants._id
});
if (defaultImage) {
return Object.assign({}, item, { defaultImage });
}
defaultImage = Media.findOne({
"metadata.productId": item.productId
});
return Object.assign({}, item, { defaultImage });
});
onData(null, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class ProductField extends Component {
this.setState({
value: nextProps.product[this.fieldName]
}, () => {
const input = this._input.refs.input;

Velocity.RunSequence([
{ e: input, p: { backgroundColor: "#e2f2e2" }, o: { duration: 200 } },
{ e: input, p: { backgroundColor: "#fff" }, o: { duration: 100 } }
]);
if (this._input && this._input.refs.input) {
const input = this._input.refs.input;

Velocity.RunSequence([
{ e: input, p: { backgroundColor: "#e2f2e2" }, o: { duration: 200 } },
{ e: input, p: { backgroundColor: "#fff" }, o: { duration: 100 } }
]);
}
});
} else {
this.setState({
Expand Down
12 changes: 11 additions & 1 deletion server/publications/collections/cart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cart } from "/lib/collections";
import { Cart, Media } from "/lib/collections";
import { Reaction } from "/server/api";

/**
Expand Down Expand Up @@ -59,3 +59,13 @@ Meteor.publish("Cart", function (sessionId, userId) {

return Cart.find(cartId);
});

Meteor.publish("CartItemImage", function (cartItem) {
check(cartItem, Match.Optional(Object));
const productId = cartItem.productId;

return Media.find({
"metadata.productId": productId,
"metadata.workflow": { $nin: ["archived"] }
});
});