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

Conversation

joykare
Copy link
Contributor

@joykare joykare commented Mar 23, 2017

Resolves #1928

Description Part 1

If I have 5 in stock and I add 10 of something to my cart my quantity is reduced to 5 (which makes sense) but I don't receive any sort of alert that my quantity has been changed and the "Added to Cart" alert shows the original quantity, not the adjusted quantity. This could lead to user confusion. I feel like at one time there was an alert that said "Your quantity has been adjusted".

Test Steps

  1. Set product variant quantity to 5
  2. Add 10 products of the variant onto cart
  3. Expect an alert showing that the original quantity has been adjusted.

Description Part 2

If I have 5 in stock and I add 10 to my cart my quantity is reduced to 5. If I add another 20, the total quantity is now 10. So the "Deny when out of stock" is only the affecting the quantity I can add to cart, not the quantity in my cart. So I could have 10 in my cart even though there are only 5 in-stock, which I would think is exactly what "Deny when out of stock" is trying to avoid.

Test Steps

  1. Set product variant quantity to 5
  2. Add 10 products of the variant onto cart
  3. Expect that quantity has been reduced to 5 (An alert pops up for the adjustment)
  4. Add another 10 products onto cart
  5. Expect an error alert stating that your cart is full

@joykare joykare added the review label Mar 23, 2017
@brent-hoover
Copy link
Collaborator

When follow the instructions in Test 1 I get the following error in the server console:

=> App running at: http://localhost:3000/
02:46:25.552Z ERROR Reaction: Quantity must be a number
  Error: Quantity must be a number
      at getErrorObject (packages/aldeed_collection2-core.js:480:15)
      at [object Object].doValidate (packages/aldeed_collection2-core.js:462:13)
      at [object Object].Mongo.Collection.(anonymous function) (packages/aldeed_collection2-core.js:214:25)
      at [object Object].Mongo.Collection.(anonymous function) [as update] (packages/dispatch_run-as-user.js:325:19)
      at [object Object].Meteor.methods.cart/addToCart (server/methods/core/cart.js:379:29)
      at packages/check.js:130:16
      at [object Object]._.extend.withValue (packages/meteor.js:1122:17)
      at Object.exports.Match._failIfArgumentsAreNotAllChecked (packages/check.js:129:41)
      at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1734:18)
      at packages/ddp-server/livedata_server.js:719:19
      at [object Object]._.extend.withValue (packages/meteor.js:1122:17)
      at packages/ddp-server/livedata_server.js:717:40
      at [object Object]._.extend.withValue (packages/meteor.js:1122:17)
      at packages/ddp-server/livedata_server.js:715:46
      at [object Object]._.extend.protocol_handlers.method (packages/ddp-server/livedata_server.js:689:23)
      at packages/ddp-server/livedata_server.js:559:43
02:46:25.554Z ERROR Reaction: [ { name: 'items.0.quantity', type: 'expectedNumber', value: NaN } ] 'Invalid keys. Error adding to cart.'

@joykare
Copy link
Contributor Author

joykare commented Mar 24, 2017

@zenweasel It should work now


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", {
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.

}

if (currentVariant.inventoryPolicy && totalQuantity > currentVariant.inventoryQuantity) {
Alerts.inline(`Sorry, cart contains maximum quantity of ${currentVariant.title}. Failed to add to cart.`, "error", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also needs i18n translation (and the alerts that follow).

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

};

function composer(props, onData) {
const tagSub = Meteor.subscribe("Tags");
const cartSub = Meteor.subscribe("Cart", Meteor.sessionId);
Copy link
Contributor

@aaronjudd aaronjudd Mar 28, 2017

Choose a reason for hiding this comment

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

Where is Meteor.sessionId coming from? (sessionId is a Reaction thing..fyi) Also the cart subscription is available, (for better or worse) as Reaction.Subscriptions.Cart, so you can just say if Reaction.Subscriptions.Cart.ready()

@brent-hoover
Copy link
Collaborator

So if my quantity is 10 and I add 8 I get the message "Your quantity has been reduced" that's great. However if I try to add an additional 3 (which I should be able to add two as there is 2 left) it just gives me the "Sorry you have the maximum amount in your cart" message which it shouldn't.

I also sort of wish this message was where the add to cart message was as I think people will get overwhelmed reading messages from different parts of the screen at the same time.

Copy link
Collaborator

@brent-hoover brent-hoover left a comment

Choose a reason for hiding this comment

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

Need a few more changes

}

if (currentVariant.inventoryPolicy && totalQuantity > currentVariant.inventoryQuantity) {
Alerts.inline(`Sorry, cart contains maximum quantity of ${currentVariant.title}. Failed to add to cart.`, "error", {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

@brent-hoover brent-hoover removed the request for review from mikemurray March 28, 2017 08:12
@joykare
Copy link
Contributor Author

joykare commented Mar 28, 2017

@zenweasel @aaronjudd changes made

@@ -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

@aaronjudd aaronjudd merged commit fad6051 into development Mar 29, 2017
@aaronjudd aaronjudd removed the review label Mar 29, 2017
@aaronjudd aaronjudd deleted the joykare-inventory-tracking-1928 branch March 29, 2017 15:38
@spencern spencern mentioned this pull request Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants