-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
"Deny when out of stock" behavior improvements 1928 #2034
Changes from 25 commits
325adc9
b9c4f47
071dffa
4700cd0
cb54270
4287301
77e81c1
357d509
8c840fc
07dc11b
51c1473
4d797a7
b1ca5b5
e4339cf
e271555
896a3d3
3a33c26
6efe0c8
60e6891
6d6e665
9f109e6
85ed068
d15edf5
634975e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Template } from "meteor/templating"; | ||
import { Reaction } from "/client/api"; | ||
|
||
Template.checkoutAddressBook.onCreated(function () { | ||
Reaction.showActionView({ | ||
provides: "settings", | ||
name: "settings/shipping", | ||
template: "shippingSettings" | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import { composeWithTracker } from "/lib/api/compose"; | |
import { Meteor } from "meteor/meteor"; | ||
import { ReactionProduct } from "/lib/api"; | ||
import { Reaction, i18next, Logger } from "/client/api"; | ||
import { Tags, Media } from "/lib/collections"; | ||
import { Tags, Media, Cart } from "/lib/collections"; | ||
import { Loading } from "/imports/plugins/core/ui/client/components"; | ||
import { ProductDetail, ProductNotFound } from "../components"; | ||
import { SocialContainer, VariantListContainer } from "./"; | ||
|
@@ -30,6 +30,8 @@ class ProductDetailContainer extends Component { | |
handleAddToCart = () => { | ||
let productId; | ||
let quantity; | ||
let totalQuantity; | ||
let storedQuantity = 0; | ||
const currentVariant = ReactionProduct.selectedVariant(); | ||
const currentProduct = ReactionProduct.selectedProduct(); | ||
|
||
|
@@ -56,12 +58,38 @@ class ProductDetailContainer extends Component { | |
return []; | ||
} | ||
|
||
if (this.props.storedCart.items && this.props.storedCart.items) { | ||
this.props.storedCart.items.forEach((item) => { | ||
if (item.variants._id === currentVariant._id) { | ||
storedQuantity = item.quantity; | ||
} | ||
}); | ||
} | ||
|
||
quantity = parseInt(this.state.cartQuantity, 10); | ||
totalQuantity = quantity + storedQuantity; | ||
|
||
if (quantity < 1) { | ||
quantity = 1; | ||
} | ||
|
||
if (currentVariant.inventoryPolicy && quantity > currentVariant.inventoryQuantity && storedQuantity < currentVariant.inventoryQuantity) { | ||
Alerts.inline("Your product quantity has been adjusted to the max quantity in stock", "warning", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have a i18n translation. |
||
placement: "productDetail", | ||
autoHide: 10000 | ||
}); | ||
quantity = currentVariant.inventoryQuantity; | ||
totalQuantity = totalQuantity - currentVariant.inventoryQuantity; | ||
} | ||
|
||
if (currentVariant.inventoryPolicy && totalQuantity > currentVariant.inventoryQuantity) { | ||
Alerts.inline(`Sorry, cart contains maximum quantity of ${currentVariant.title}. Failed to add to cart.`, "error", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also needs i18n translation (and the alerts that follow). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the message is confusing. How does my cart contain the maximum quantity? We are denying because it's out of stock right? The message should reflect that somehow. |
||
placement: "productDetail", | ||
autoHide: 10000 | ||
}); | ||
return []; | ||
} | ||
|
||
if (!currentProduct.isVisible) { | ||
Alerts.inline("Publish product before adding to cart.", "error", { | ||
placement: "productDetail", | ||
|
@@ -182,11 +210,13 @@ class ProductDetailContainer extends Component { | |
|
||
ProductDetailContainer.propTypes = { | ||
media: PropTypes.arrayOf(PropTypes.object), | ||
product: PropTypes.object | ||
product: PropTypes.object, | ||
storedCart: PropTypes.object | ||
}; | ||
|
||
function composer(props, onData) { | ||
const tagSub = Meteor.subscribe("Tags"); | ||
const cartSub = Meteor.subscribe("Cart", Meteor.sessionId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is |
||
const productId = Reaction.Router.getParam("handle"); | ||
const variantId = Reaction.Router.getParam("variantId"); | ||
const revisionType = Reaction.Router.getQueryParam("revision"); | ||
|
@@ -198,7 +228,7 @@ function composer(props, onData) { | |
productSub = Meteor.subscribe("Product", productId); | ||
} | ||
|
||
if (productSub && productSub.ready() && tagSub.ready()) { | ||
if (productSub && productSub.ready() && tagSub.ready() && cartSub.ready()) { | ||
// Get the product | ||
const product = ReactionProduct.setProduct(productId, variantId); | ||
|
||
|
@@ -282,6 +312,8 @@ function composer(props, onData) { | |
|
||
const topVariants = ReactionProduct.getTopVariants(); | ||
|
||
const storedCart = Cart.findOne(); | ||
|
||
onData(null, { | ||
variants: topVariants, | ||
layout: product.template || "productDetailSimple", | ||
|
@@ -291,7 +323,8 @@ function composer(props, onData) { | |
media: mediaArray, | ||
editable, | ||
viewAs: viewProductAs, | ||
hasAdminPermission: Reaction.hasPermission(["createProduct"]) | ||
hasAdminPermission: Reaction.hasPermission(["createProduct"]), | ||
storedCart | ||
}); | ||
} else { | ||
// onData must be called with composeWithTracker, or else the loading icon will show forever. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Browser console error:
BlazeLayout warning: unknown template "coreLayout"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pulled this branch again and am not seeing that error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What can I say, I've
reaction reset
, et al, branch is up-to-date, and I'm pointing at the cause of the error right here... ¯_(ツ)_/¯There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, now I do