Skip to content

Commit

Permalink
Merge pull request #4930 from reactioncommerce/refactor-kieckhafer-re…
Browse files Browse the repository at this point in the history
…nameInventoryQuantity

refactor: Update `inventoryQuantity` field to be `inventoryInStock`
  • Loading branch information
aldeed committed Jan 23, 2019
2 parents 96eacb6 + e039447 commit 831c381
Show file tree
Hide file tree
Showing 73 changed files with 191 additions and 162 deletions.
4 changes: 2 additions & 2 deletions imports/collections/schemas/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const SocialMetadata = new SimpleSchema({
* @property {Number} height optional, default value: `0`
* @property {Number} index required
* @property {Boolean} inventoryAvailableToSell required, The quantity of this item currently available to sell. This number does not include reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator). If this is a variant, this number is created by summing all child option inventory numbers. This is most likely the quantity to display in the storefront UI.
* @property {Boolean} inventoryInStock required, The quantity of this item currently in stock. This number is updated when an order is processed by the operator. This number includes all inventory, including reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator). If this is a variant, this number is created by summing all child option inventory numbers. This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI. Called `inventoryQuantity` in the Product Schema, and `inventoryInStock` in the Catalog schema.
* @property {Boolean} inventoryInStock required, The quantity of this item currently in stock. This number is updated when an order is processed by the operator. This number includes all inventory, including reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator). If this is a variant, this number is created by summing all child option inventory numbers. This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI.
* @property {Boolean} inventoryManagement required, True if inventory management is enabled for this variant
* @property {Boolean} inventoryPolicy required, True if inventory policy is enabled for this variant
* @property {Boolean} isBackorder required, Indicates when a product is currently backordered
Expand Down Expand Up @@ -336,7 +336,7 @@ export const CatalogVariantSchema = VariantBaseSchema.clone().extend({
* @property {String} description optional
* @property {Number} height optional, default value: `0`
* @property {Boolean} inventoryAvailableToSell required, The quantity of this item currently available to sell. This number does not include reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator). If this is a variant, this number is created by summing all child option inventory numbers. This is most likely the quantity to display in the storefront UI.
* @property {Boolean} inventoryInStock required, The quantity of this item currently in stock. This number is updated when an order is processed by the operator. This number includes all inventory, including reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator). If this is a variant, this number is created by summing all child option inventory numbers. This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI. Called `inventoryQuantity` in the Product Schema, and `inventoryInStock` in the Catalog schema.
* @property {Boolean} inventoryInStock required, The quantity of this item currently in stock. This number is updated when an order is processed by the operator. This number includes all inventory, including reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator). If this is a variant, this number is created by summing all child option inventory numbers. This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI.
* @property {Boolean} isBackorder required, Indicates when a product is currently backordered
* @property {Boolean} isLowQuantity required, Indicates that the product quantity is too low
* @property {Boolean} isSoldOut required, Indicates when the product quantity is zero
Expand Down
16 changes: 7 additions & 9 deletions imports/collections/schemas/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ registerSchema("VariantMedia", VariantMedia);
* @property {Boolean} inventoryInStock required
* @property {Boolean} inventoryManagement, default value: `true`
* @property {Boolean} inventoryPolicy, default value: `false`, If disabled, item can be sold even if it not in stock.
* @property {Number} inventoryQuantity, default value: `0`
* @property {Number} inventoryInStock, default value: `0`
* @property {Boolean} isBackorder denormalized, `true` if product not in stock, but customers anyway could order it
* @property {Boolean} isDeleted, default value: `false`
* @property {Boolean} isLowQuantity optional, true when at least 1 variant is below `lowInventoryWarningThreshold`
* @property {Boolean} isSoldOut optional, denormalized field, indicates when all variants `inventoryQuantity` is 0
* @property {Boolean} isSoldOut optional, denormalized field, indicates when all variants `inventoryInStock` is 0
* @property {Boolean} isVisible, default value: `false`
* @property {Number} length optional, default value: `0`
* @property {Number} lowInventoryWarningThreshold, default value: `0`, Warn of low inventory at this number
Expand Down Expand Up @@ -180,14 +180,13 @@ export const ProductVariant = new SimpleSchema({
optional: true,
defaultValue: 0
},
"inventoryQuantity": {
"inventoryInStock": {
type: SimpleSchema.Integer,
label: "The quantity of this item currently in stock." +
"This number is updated when an order is processed by the operator." +
"This number includes all inventory, including reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator)." +
"If this is a variant, this number is created by summing all child option inventory numbers." +
"This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI." +
"Called `inventoryQuantity` in the Product Schema, and `inventoryInStock` in the Catalog schema.",
"This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI.",
optional: true,
defaultValue: 0
},
Expand Down Expand Up @@ -360,7 +359,7 @@ registerSchema("PriceRange", PriceRange);
* @property {Boolean} isBackorder denormalized, `true` if product not in stock, but customers anyway could order it
* @property {Boolean} isDeleted, default value: `false`
* @property {Boolean} isLowQuantity denormalized, true when at least 1 variant is below `lowInventoryWarningThreshold`
* @property {Boolean} isSoldOut denormalized, Indicates when all variants `inventoryQuantity` is zero
* @property {Boolean} isSoldOut denormalized, Indicates when all variants `inventoryInStock` is zero
* @property {Boolean} isVisible, default value: `false`
* @property {String} metaDescription optional
* @property {Metafield[]} metafields optional
Expand Down Expand Up @@ -442,14 +441,13 @@ export const Product = new SimpleSchema({
optional: true,
defaultValue: 0
},
"inventoryQuantity": {
"inventoryInStock": {
type: SimpleSchema.Integer,
label: "The quantity of this item currently in stock." +
"This number is updated when an order is processed by the operator." +
"This number includes all inventory, including reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator)." +
"If this is a variant, this number is created by summing all child option inventory numbers." +
"This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI." +
"Called `inventoryQuantity` in the Product Schema, and `inventoryInStock` in the Catalog schema.",
"This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI.",
optional: true,
defaultValue: 0
},
Expand Down
20 changes: 10 additions & 10 deletions imports/plugins/core/catalog/server/methods/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function updateVariantProductField(variants, field, value) {
*/
const toDenormalize = [
"price",
"inventoryQuantity",
"inventoryInStock",
"lowInventoryWarningThreshold",
"inventoryPolicy",
"inventoryManagement"
Expand Down Expand Up @@ -221,7 +221,7 @@ function copyMedia(newId, variantOldId, variantNewId) {
* @param {String} id - product _id
* @param {String} field - type of field. Could be:
* "price",
* "inventoryQuantity",
* "inventoryInStock",
* "inventoryManagement",
* "inventoryPolicy",
* "lowInventoryWarningThreshold"
Expand All @@ -240,7 +240,7 @@ function denormalize(id, field) {

switch (field) {
case "inventoryPolicy":
case "inventoryQuantity":
case "inventoryInStock":
case "inventoryManagement":
Object.assign(update, {
isSoldOut: Promise.await(isSoldOut(variants, rawCollections)),
Expand Down Expand Up @@ -278,18 +278,18 @@ function denormalize(id, field) {
/**
* flushQuantity
* @private
* @summary if variant `inventoryQuantity` not zero, function update it to
* zero. This needed in case then option with it's own `inventoryQuantity`
* @summary if variant `inventoryInStock` not zero, function update it to
* zero. This needed in case then option with it's own `inventoryInStock`
* creates to top-level variant. In that case top-level variant should display
* sum of his options `inventoryQuantity` fields.
* sum of his options `inventoryInStock` fields.
* @param {String} id - variant _id
* @return {Number} - collection update results
*/
function flushQuantity(id) {
const variant = Products.findOne(id);
// if variant already have descendants, quantity should be 0, and we don't
// need to do all next actions
if (variant.inventoryQuantity === 0) {
if (variant.inventoryInStock === 0) {
return 1; // let them think that we have one successful operation here
}

Expand All @@ -299,7 +299,7 @@ function flushQuantity(id) {
},
{
$set: {
inventoryQuantity: 0
inventoryInStock: 0
}
},
{
Expand Down Expand Up @@ -485,7 +485,7 @@ Meteor.methods({
}
delete clone.updatedAt;
delete clone.createdAt;
delete clone.inventoryQuantity;
delete clone.inventoryInStock;
delete clone.lowInventoryWarningThreshold;

copyMedia(productId, oldId, clone._id);
Expand Down Expand Up @@ -965,7 +965,7 @@ Meteor.methods({
throw new ReactionError("access-denied", "Access Denied");
}

if (field === "inventoryQuantity" && value === "") {
if (field === "inventoryInStock" && value === "") {
if (!Promise.await(hasChildVariant(_id, rawCollections))) {
throw new ReactionError("invalid", "Inventory Quantity is required when no child variants");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const variantFieldsThatNeedPublishing = [
"index",
"inventoryManagement",
"inventoryPolicy",
"inventoryQuantity",
"inventoryInStock",
"isDeleted",
"isLowQuantity",
"isSoldOut",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ type CatalogProduct implements CatalogProductOrVariant & Node {
This number includes all inventory, including reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator).
This number is calculated by summing all child variant inventory numbers.
This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI.
Called `inventoryQuantity` in the Product Schema, and `inventoryInStock` in the Catalog schema.
"""
inventoryInStock: Int

Expand Down Expand Up @@ -293,7 +292,6 @@ type CatalogProductVariant implements CatalogProductOrVariant & Node {
This number includes all inventory, including reserved inventory (i.e. inventory that has been ordered, but not yet processed by the operator).
If this is a variant, this number is created by summing all child option inventory numbers.
This is most likely just used as a reference in the operator UI, and not displayed in the storefront UI.
Called `inventoryQuantity` in the Product Schema, and `inventoryInStock` in the Catalog schema.
"""
inventoryInStock: Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function xformProduct({ collections, product, shop, variants }) {
variantInventory = {
canBackorder: canBackorder(variantOptions),
inventoryAvailableToSell: variant.inventoryAvailableToSell || 0,
inventoryInStock: variant.inventoryQuantity || 0,
inventoryInStock: variant.inventoryInStock || 0,
isBackorder: isBackorder(variantOptions),
isLowQuantity: isLowQuantity(variantOptions),
isSoldOut: isSoldOut(variantOptions)
Expand All @@ -118,7 +118,7 @@ export async function xformProduct({ collections, product, shop, variants }) {
variantInventory = {
canBackorder: canBackorder([variant]),
inventoryAvailableToSell: variant.inventoryAvailableToSell || 0,
inventoryInStock: variant.inventoryQuantity || 0,
inventoryInStock: variant.inventoryInStock || 0,
isBackorder: isBackorder([variant]),
isLowQuantity: isLowQuantity([variant]),
isSoldOut: isSoldOut([variant])
Expand All @@ -136,7 +136,7 @@ export async function xformProduct({ collections, product, shop, variants }) {
const optionInventory = {
canBackorder: canBackorder([option]),
inventoryAvailableToSell: option.inventoryAvailableToSell,
inventoryInStock: option.inventoryQuantity,
inventoryInStock: option.inventoryInStock,
isBackorder: isBackorder([option]),
isLowQuantity: isLowQuantity([option]),
isSoldOut: isSoldOut([option])
Expand All @@ -157,7 +157,7 @@ export async function xformProduct({ collections, product, shop, variants }) {
description: product.description,
height: product.height,
inventoryAvailableToSell: product.inventoryAvailableToSell || 0,
inventoryInStock: product.inventoryQuantity || 0,
inventoryInStock: product.inventoryInStock || 0,
isBackorder: isBackorder(variants),
isDeleted: !!product.isDeleted,
isLowQuantity: isLowQuantity(variants),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default async function updateCatalogProductInventoryStatus(productId, col

const modifier = {
"product.inventoryAvailableToSell": product.inventoryAvailableToSell,
"product.inventoryInStock": product.inventoryQuantity,
"product.inventoryInStock": product.inventoryInStock,
"product.isSoldOut": isSoldOut(variants),
"product.isBackorder": isBackorder(variants),
"product.isLowQuantity": isLowQuantity(variants)
Expand Down Expand Up @@ -80,22 +80,22 @@ export default async function updateCatalogProductInventoryStatus(productId, col
modifier[`${baseKey}.variants.${topVariantIndex}.isLowQuantity`] = isLowQuantity(variantOptions);
modifier[`${baseKey}.variants.${topVariantIndex}.isBackorder`] = isBackorder(variantOptions);
modifier[`${baseKey}.variants.${topVariantIndex}.inventoryAvailableToSell`] = topVariantFromProductsCollection.inventoryAvailableToSell;
modifier[`${baseKey}.variants.${topVariantIndex}.inventoryInStock`] = topVariantFromProductsCollection.inventoryQuantity;
modifier[`${baseKey}.variants.${topVariantIndex}.inventoryInStock`] = topVariantFromProductsCollection.inventoryInStock;

variantOptions.forEach((option, optionIndex) => {
modifier[`${baseKey}.variants.${topVariantIndex}.options.${optionIndex}.isSoldOut`] = isSoldOut([option]);
modifier[`${baseKey}.variants.${topVariantIndex}.options.${optionIndex}.isLowQuantity`] = isLowQuantity([option]);
modifier[`${baseKey}.variants.${topVariantIndex}.options.${optionIndex}.isBackorder`] = isBackorder([option]);
modifier[`${baseKey}.variants.${topVariantIndex}.options.${optionIndex}.inventoryAvailableToSell`] = option.inventoryAvailableToSell;
modifier[`${baseKey}.variants.${topVariantIndex}.options.${optionIndex}.inventoryInStock`] = option.inventoryQuantity;
modifier[`${baseKey}.variants.${topVariantIndex}.options.${optionIndex}.inventoryInStock`] = option.inventoryInStock;
});
} else {
// Create a modifier for a top level variant only
modifier[`${baseKey}.variants.${topVariantIndex}.isSoldOut`] = isSoldOut([topVariantFromProductsCollection]);
modifier[`${baseKey}.variants.${topVariantIndex}.isLowQuantity`] = isLowQuantity([topVariantFromProductsCollection]);
modifier[`${baseKey}.variants.${topVariantIndex}.isBackorder`] = isBackorder([topVariantFromProductsCollection]);
modifier[`${baseKey}.variants.${topVariantIndex}.inventoryAvailableToSell`] = topVariantFromProductsCollection.inventoryAvailableToSell;
modifier[`${baseKey}.variants.${topVariantIndex}.inventoryInStock`] = topVariantFromProductsCollection.inventoryQuantity;
modifier[`${baseKey}.variants.${topVariantIndex}.inventoryInStock`] = topVariantFromProductsCollection.inventoryInStock;
}
});

Expand Down
2 changes: 1 addition & 1 deletion imports/plugins/core/checkout/client/helpers/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Template.registerHelper("cart", () => {
showItemLowInventoryWarning(variant) {
if (variant && variant.inventoryPolicy &&
variant.lowInventoryWarningThreshold) {
return variant.inventoryQuantity <=
return variant.inventoryInStock <=
variant.lowInventoryWarningThreshold;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions imports/plugins/core/core/server/fixtures/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function getCartItem(options = {}) {
]
}).fetch();
const selectedOption = Random.choice(childVariants);
const quantity = _.random(1, selectedOption.inventoryQuantity);
const quantity = _.random(1, selectedOption.inventoryInStock);
const defaults = {
_id: Random.id(),
addedAt: new Date(),
Expand Down Expand Up @@ -98,7 +98,7 @@ export function createCart(productId, variantId) {
const variant = Products.findOne(variantId);
const user = Factory.create("user");
const account = Factory.create("account", { userId: user._id });
const quantity = _.random(1, variant.inventoryQuantity);
const quantity = _.random(1, variant.inventoryInStock);
const cartItem = {
_id: Random.id(),
addedAt: new Date(),
Expand Down
6 changes: 3 additions & 3 deletions imports/plugins/core/core/server/fixtures/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function metaField(options = {}) {
* @param {String} [options.inventoryManagement] - Track inventory for this product?
* @param {String} [options.inventoryPolicy] - Allow overselling of this product?
* @param {String} [options.lowInventoryWarningThreshold] - Qty left of inventory that sets off warning
* @param {String} [options.inventoryQuantity] - Inventory Quantity
* @param {String} [options.inventoryInStock] - Inventory Quantity
* @param {String} [options.price] - productVariant price
* @param {String} [options.title] - productVariant title
* @param {String} [options.optionTitle] - productVariant option title
Expand All @@ -51,7 +51,7 @@ export function productVariant(options = {}) {
inventoryManagement: faker.random.boolean(),
inventoryPolicy: faker.random.boolean(),
lowInventoryWarningThreshold: _.random(1, 5),
inventoryQuantity: _.random(0, 100),
inventoryInStock: _.random(0, 100),
isTaxable: faker.random.boolean(),
isVisible: true,
price: _.random(10, 1000),
Expand Down Expand Up @@ -87,7 +87,7 @@ export function productVariant(options = {}) {
* @param {String} [options.inventoryManagement] - Track inventory for this product?
* @param {String} [options.inventoryPolicy] - Allow overselling of this product?
* @param {String} [options.lowInventoryWarningThreshold] - Qty left of inventory that sets off warning
* @param {String} [options.inventoryQuantity] - Inventory Quantity
* @param {String} [options.inventoryInStock] - Inventory Quantity
* @param {String} [options.price] - productVariant price
* @param {String} [options.title] - productVariant title
* @param {String} [options.optionTitle] - productVariant option title
Expand Down
6 changes: 3 additions & 3 deletions imports/plugins/core/graphql/server/no-meteor/xforms/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ function xformCartItem(context, catalogItems, products, cartItem) {

return {
...cartItem,
currentQuantity: variantSourceProduct && variantSourceProduct.inventoryQuantity,
currentQuantity: variantSourceProduct && variantSourceProduct.inventoryInStock,
imageURLs: media && media.URLs,
inventoryAvailableToSell: variantSourceProduct && variantSourceProduct.inventoryQuantity,
inventoryInStock: variantSourceProduct && variantSourceProduct.inventoryQuantity,
inventoryAvailableToSell: variantSourceProduct && variantSourceProduct.inventoryInStock,
inventoryInStock: variantSourceProduct && variantSourceProduct.inventoryInStock,
isBackorder: variant.isBackorder || false,
isLowQuantity: variant.isLowQuantity || false,
isSoldOut: variant.isSoldOut || false,
Expand Down
Loading

0 comments on commit 831c381

Please sign in to comment.