-
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
325adc9
Show Sidebar shipping in checkout
impactmass b9c4f47
Set actionView after payment checkout step
impactmass 071dffa
Hide sidebar on entry to profile page
impactmass 4700cd0
Merge origin development
joykare cb54270
Merge branch 'development' of github.com:reactioncommerce/reaction in…
joykare 4287301
Merge branch 'development' of github.com:reactioncommerce/reaction in…
joykare 77e81c1
Add alert and checkout message when item quantities have been adjusted
joykare 357d509
Update errors to include when cart is already full
joykare 8c840fc
Actually deny when out of stock
joykare 07dc11b
Add more descriptive error messages
joykare 51c1473
Merge branch 'development' of github.com:reactioncommerce/reaction in…
joykare 4d797a7
Merge branch 'development' into joykare-inventory-tracking-1928
joykare b1ca5b5
Fix console error on Quantity
joykare e4339cf
Fix PR arising issue on quantity
joykare e271555
Merge branch 'development' into joykare-inventory-tracking-1928
896a3d3
Merge branch 'development' into joykare-inventory-tracking-1928
3a33c26
Merge branch 'development' into joykare-inventory-tracking-1928
brent-hoover 6efe0c8
Clean up a few edge cases
joykare 60e6891
Add i18n translations
joykare 6d6e665
Merge branch 'joykare-inventory-tracking-1928' of github.com:reaction…
joykare 9f109e6
Remove file changes different from development
joykare 85ed068
Merge branch 'development' into joykare-inventory-tracking-1928
d15edf5
Remove all references to addressbook.js
joykare 634975e
Merge branch 'development' into joykare-inventory-tracking-1928
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,9 @@ class ProductDetailContainer extends Component { | |
handleAddToCart = () => { | ||
let productId; | ||
let quantity; | ||
let maxQuantity; | ||
let totalQuantity; | ||
let storedQuantity = 0; | ||
const currentVariant = ReactionProduct.selectedVariant(); | ||
const currentProduct = ReactionProduct.selectedProduct(); | ||
|
||
|
@@ -56,12 +59,51 @@ class ProductDetailContainer extends Component { | |
return []; | ||
} | ||
|
||
if (this.props.storedCart && 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; | ||
maxQuantity = currentVariant.inventoryQuantity; | ||
|
||
if (quantity < 1) { | ||
quantity = 1; | ||
} | ||
|
||
if (currentVariant.inventoryPolicy && quantity > maxQuantity && storedQuantity < maxQuantity) { | ||
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", | ||
i18nKey: "admin.inventoryAlerts.adjustedQuantity", | ||
autoHide: 10000 | ||
}); | ||
quantity = maxQuantity - storedQuantity; | ||
totalQuantity = maxQuantity; | ||
} | ||
|
||
if (currentVariant.inventoryPolicy && totalQuantity > maxQuantity && storedQuantity < maxQuantity && quantity < maxQuantity) { | ||
Alerts.inline("Your product quantity has been adjusted to the max quantity in stock", "warning", { | ||
placement: "productDetail", | ||
i18nKey: "admin.inventoryAlerts.adjustedQuantity", | ||
autoHide: 10000 | ||
}); | ||
quantity = maxQuantity - storedQuantity; | ||
totalQuantity = maxQuantity; | ||
} | ||
|
||
if (currentVariant.inventoryPolicy && totalQuantity > maxQuantity) { | ||
Alerts.inline("Sorry, this item is out of stock!", "error", { | ||
placement: "productDetail", | ||
i18nKey: "productDetail.outOfStock", | ||
autoHide: 10000 | ||
}); | ||
return []; | ||
} | ||
|
||
if (!currentProduct.isVisible) { | ||
Alerts.inline("Publish product before adding to cart.", "error", { | ||
placement: "productDetail", | ||
|
@@ -182,7 +224,8 @@ class ProductDetailContainer extends Component { | |
|
||
ProductDetailContainer.propTypes = { | ||
media: PropTypes.arrayOf(PropTypes.object), | ||
product: PropTypes.object | ||
product: PropTypes.object, | ||
storedCart: PropTypes.object | ||
}; | ||
|
||
function composer(props, onData) { | ||
|
@@ -198,7 +241,7 @@ function composer(props, onData) { | |
productSub = Meteor.subscribe("Product", productId); | ||
} | ||
|
||
if (productSub && productSub.ready() && tagSub.ready()) { | ||
if (productSub && productSub.ready() && tagSub.ready() && Reaction.Subscriptions.Cart.ready()) { | ||
// Get the product | ||
const product = ReactionProduct.setProduct(productId, variantId); | ||
|
||
|
@@ -282,6 +325,8 @@ function composer(props, onData) { | |
|
||
const topVariants = ReactionProduct.getTopVariants(); | ||
|
||
const storedCart = Cart.findOne(); | ||
|
||
onData(null, { | ||
variants: topVariants, | ||
layout: product.template || "productDetailSimple", | ||
|
@@ -291,7 +336,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. | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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