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

"Deny when out of stock" behavior improvements 1928 #2034

Merged
merged 24 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
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 Mar 1, 2017
b9c4f47
Set actionView after payment checkout step
impactmass Mar 1, 2017
071dffa
Hide sidebar on entry to profile page
impactmass Mar 2, 2017
4700cd0
Merge origin development
joykare Mar 13, 2017
cb54270
Merge branch 'development' of github.com:reactioncommerce/reaction in…
joykare Mar 15, 2017
4287301
Merge branch 'development' of github.com:reactioncommerce/reaction in…
joykare Mar 16, 2017
77e81c1
Add alert and checkout message when item quantities have been adjusted
joykare Mar 21, 2017
357d509
Update errors to include when cart is already full
joykare Mar 22, 2017
8c840fc
Actually deny when out of stock
joykare Mar 23, 2017
07dc11b
Add more descriptive error messages
joykare Mar 23, 2017
51c1473
Merge branch 'development' of github.com:reactioncommerce/reaction in…
joykare Mar 23, 2017
4d797a7
Merge branch 'development' into joykare-inventory-tracking-1928
joykare Mar 23, 2017
b1ca5b5
Fix console error on Quantity
joykare Mar 24, 2017
e4339cf
Fix PR arising issue on quantity
joykare Mar 24, 2017
e271555
Merge branch 'development' into joykare-inventory-tracking-1928
Mar 28, 2017
896a3d3
Merge branch 'development' into joykare-inventory-tracking-1928
Mar 28, 2017
3a33c26
Merge branch 'development' into joykare-inventory-tracking-1928
brent-hoover Mar 28, 2017
6efe0c8
Clean up a few edge cases
joykare Mar 28, 2017
60e6891
Add i18n translations
joykare Mar 28, 2017
6d6e665
Merge branch 'joykare-inventory-tracking-1928' of github.com:reaction…
joykare Mar 28, 2017
9f109e6
Remove file changes different from development
joykare Mar 28, 2017
85ed068
Merge branch 'development' into joykare-inventory-tracking-1928
Mar 29, 2017
d15edf5
Remove all references to addressbook.js
joykare Mar 29, 2017
634975e
Merge branch 'development' into joykare-inventory-tracking-1928
Mar 29, 2017
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
1 change: 1 addition & 0 deletions imports/plugins/core/checkout/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "./templates/cartPanel/cartPanel.html";
import "./templates/cartPanel/cartPanel.js";

import "./templates/checkout/addressBook/addressBook.html";
import "./templates/checkout/addressBook/addressBook.js";
Copy link
Contributor

@aaronjudd aaronjudd Mar 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Browser console error:

Uncaught Error: Cannot find module './templates/checkout/addressBook/addressBook.js'

BlazeLayout warning: unknown template "coreLayout"

Copy link
Collaborator

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

Copy link
Contributor

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... ¯_(ツ)_/¯

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, now I do

import "./templates/checkout/completed/completed.html";
import "./templates/checkout/completed/completed.js";
import "./templates/checkout/header/header.html";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "./";
Expand All @@ -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();

Expand All @@ -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", {
Copy link
Contributor

Choose a reason for hiding this comment

The 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",
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -282,6 +325,8 @@ function composer(props, onData) {

const topVariants = ReactionProduct.getTopVariants();

const storedCart = Cart.findOne();

onData(null, {
variants: topVariants,
layout: product.template || "productDetailSimple",
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"admin": {
"settings": {
"productDetailsLabel": "Product Details"
},
"inventoryAlerts": {
"adjustedQuantity": "Your product quantity has been adjusted to the max quantity in stock"
}
}
}
Expand Down