Skip to content

Commit

Permalink
v0.12.3
Browse files Browse the repository at this point in the history
  • Loading branch information
brent-hoover committed Apr 7, 2016
2 parents 73eccf8 + f3e5711 commit 1445ede
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 40 deletions.
21 changes: 15 additions & 6 deletions packages/reaction-catalog/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Meteor.methods({
* cloning
* @param {String} variantId - the variantId that we're cloning
* @todo rewrite @description
* @return {String} - cloned variant _id
* @return {Array} - list with cloned variants _ids
*/
"products/cloneVariant": function (productId, variantId) {
check(productId, String);
Expand Down Expand Up @@ -333,7 +333,7 @@ Meteor.methods({
// @link http://underscorejs.org/#sortBy
const sortedVariants = _.sortBy(variants, doc => doc.ancestors.length);

sortedVariants.map(variant => {
return sortedVariants.map(variant => {
const oldId = variant._id;
let type = "child";
let clone = {};
Expand Down Expand Up @@ -1178,12 +1178,21 @@ Meteor.methods({

if (typeof product === "object" && product.title.length > 1) {
if (variants.length > 0) {
variants.map(variant => {
if (!(typeof variant.price === "number" && variant.price > 0 &&
typeof variant.title === "string" && variant.title.length > 1)) {
variants.forEach(variant => {
// if this is a top variant with children, we avoid it to check price
// because we using price of its children
if (variant.ancestors.length === 1 &&
!ReactionCore.getVariants(variant._id, "variant").length ||
variant.ancestors.length !== 1) {
if (!(typeof variant.price === "number" && variant.price > 0)) {
variantValidator = false;
}
}
// if variant has no title
if (typeof variant.title === "string" && !variant.title.length) {
variantValidator = false;
}
if (typeof optionTitle === "string" && !(optionTitle.length > 0)) {
if (typeof optionTitle === "string" && !optionTitle.length) {
variantValidator = false;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ describe("core product methods", function () {
);

it(
"should not publish product when missing even one variant price",
"should not publish product when missing even one of child variant price",
function (done) {
let product = faker.reaction.products.add();
const isVisible = product.isVisible;
Expand Down Expand Up @@ -991,6 +991,11 @@ describe("core product methods", function () {
}
);

it(
"should not publish product when top variant has no children and no price",
function (done) { return done(); }
);

it(
"should not publish product when missing variant",
function (done) {
Expand Down
2 changes: 1 addition & 1 deletion packages/reaction-core/server/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ ReactionImport.identify = function (document) {
/**
* @summary Commit the buffer for a given collection to the database.
* @param {Mongo.Collection} collection The target collection to be flushed to disk
* @param {function} callback Function to execute after flush succeeded
* @returns {undefined}
*/
ReactionImport.flush = function (collection) {
check(collection, Match.Optional(Mongo.Collection));

if (!collection) {
for (let name of Object.keys(this._buffers)) {
this.flush(ReactionCore.Collections[name]);
Expand Down
11 changes: 6 additions & 5 deletions packages/reaction-core/server/methods/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ Meteor.methods({
},

/**
* orders/shipmentShipped
* orders/sendNotification
*
* @summary trigger shipmentShipped status and workflow update
* @summary send order notification email
* @param {Object} order - order object
* @return {Object} return workflow result
* @return {Boolean} email sent or not
*/
"orders/sendNotification": function (order) {
check(order, Object);
Expand Down Expand Up @@ -273,7 +273,8 @@ Meteor.methods({
})
});
} catch (error) {
throw new Meteor.Error(403, "Unable to send shipment notification email.", error);
ReactionCore.Log.fatal("Unable to send notification email: " + error);
throw new Meteor.Error("error-sending-email", "Unable to send order notification email.", error);
}
}
},
Expand Down Expand Up @@ -344,7 +345,7 @@ Meteor.methods({
"shipping._id": shipment._id
}, {
$set: {
[`shipping.$.tracking`]: tracking
["shipping.$.tracking"]: tracking
}
});
},
Expand Down
9 changes: 8 additions & 1 deletion packages/reaction-core/server/registry/defaultAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
* @returns {String} return userId
*/
ReactionRegistry.createDefaultAdminUser = function () {
ReactionCore.Log.info("Starting createDefaultAdminUser");
let options = {};
const domain = ReactionRegistry.getRegistryDomain();
const defaultAdminRoles = ["owner", "admin", "guest", "account/profile"];
const shopId = ReactionCore.getShopId();
let accountId;

while (!ReactionCore.getShopId()) {
ReactionCore.Log.info("No shopId, waiting one second...");
Meteor._sleepForMs(1000);
}
const shopId = ReactionCore.getShopId();

// if an admin user has already been created, we'll exit
if (Roles.getUsersInRole(defaultAdminRoles, shopId).count() !== 0) {
ReactionCore.Log.info("Not creating default admin user, already exists");
return ""; // this default admin has already been created for this shop.
}

Expand Down
9 changes: 8 additions & 1 deletion packages/reaction-i18n/private/data/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
"createTag": "Create Tag"
},
"productDetailEdit": {
"editOption": "Edit option",
"productSettings": "Product Settings",
"product": "Product",
"size": "Size",
Expand All @@ -234,6 +235,9 @@
"duplicateVariant": "Duplicate",
"addVariantOption": "Add Option",
"removeVariant": "Remove",
"removeVariantConfirm": "Are you sure you want to delete {{title}}",
"thisVariant": "this variant",
"thisOption": "this option",
"duplicateProduct": "Duplicate Product",
"pinProduct": "Pin Product",
"toggleSize": "Toggle Size",
Expand All @@ -256,8 +260,11 @@
"weight": "Weight",
"taxable": "Taxable",
"inventoryManagement": "Inventory tracking",
"inventoryManagementLabel": "Register product in inventory system and track its status",
"inventoryPolicy": "Deny when out of stock",
"lowInventoryWarningThreshold": "Warn @"
"inventoryPolicyLabel": "Do not sell the product variant when it is not in stock",
"lowInventoryWarningThreshold": "Warn @",
"lowInventoryWarningThresholdLabel": "Warn customers that the product will be close to sold out when the quantity reaches the next threshold"
},
"variantList": {
"moreOptions": "There are more options available for this selection.",
Expand Down
19 changes: 13 additions & 6 deletions packages/reaction-i18n/private/data/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"hideBarcodes": "Скрыть штрих-коды",
"options": "Варианты",
"addToCart": "Добавить в корзину",
"chooseOptions": "Пожалуйста выберите вариант прежде чем добавить товар в корзину",
"chooseOptions": "Пожалуйста, выберите вариант прежде чем добавить товар в корзину",
"outOfStock": "Извините, этого товара нет в наличии",
"productDeleteError": "Произошла ошибка во время удаления {{product}}.",
"deleteErrorTheProduct": "товара",
Expand Down Expand Up @@ -213,23 +213,27 @@
"createTag": "Create Tag"
},
"productDetailEdit": {
"editOption": "Редактировать вариант",
"productSettings": "Настройки товара",
"product": "Товар",
"size": "Размер",
"title": "Название товара",
"pageTitle": "Название страницы товара",
"vendor": "Производитель",
"vendor": "Изготовитель",
"description": "Добавьте описание товара",
"facebookMsg": "Сообщение Facebook",
"twitterMsg": "Сообщение Twitter",
"pinterestMsg": "Сообщение Pinterest",
"googleplusMsg": "Сообщение Google+",
"duplicateVariant": "Скопировать",
"addVariantOption": "Добавить опцию",
"removeVariant": "Удалить опцию",
"removeVariant": "Удалить",
"removeVariantConfirm": "Вы уверены, что хотите удалить {{title}}?",
"thisVariant": "этот вариант",
"thisOption": "эту опцию",
"duplicateProduct": "Скопировать товар",
"pinProduct": "Закрепить товар",
"toggleSize": "Переключить размер",
"toggleSize": "Поменять размер",
"deleteProduct": "Удалить товар",
"deleteThisProduct": "Удалить этот товар?",
"deleteSelectedProducts": "Удалить выбранные товары?",
Expand All @@ -249,11 +253,14 @@
"weight": "Вес",
"taxable": "Налогооблагаемый",
"inventoryManagement": "Следить за кол-вом",
"inventoryManagementLabel": "Сделать товар складским и отслеживать его состояние",
"inventoryPolicy": "Откл. при нуле",
"lowInventoryWarningThreshold": "Сообщить если меньше "
"inventoryPolicyLabel": "Не продавать вариант товара, когда его нет в наличие",
"lowInventoryWarningThreshold": "Предупреждать при",
"lowInventoryWarningThresholdLabel": "Предупреждать покупателей о том, что продукт заканчивается, когда количество достигло следующего порога"
},
"variantList": {
"moreOptions": "Есть еще варианты доступные для этого выбора.",
"moreOptions": "Для этого варианта доступны следующие опции:",
"createVariant": "Создать вариант"
},
"gridPackage": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Template.productImageGallery.onRendered(function () {
Template.productImageGallery.events({
"mouseenter .gallery > li": function (event) {
event.stopImmediatePropagation();
// This is a workaround for an issue with FF refiring mouseover when the contents change
if (event.relatedTarget === null) {
return undefined;
}
if (!ReactionCore.hasPermission("createProduct")) {
let first = $(".gallery li:nth-child(1)");
let target = $(event.currentTarget);
Expand All @@ -140,6 +144,7 @@ Template.productImageGallery.events({
});
}
}
return undefined;
},
"click .remove-image": function () {
const mediaId = this._id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Template.productDetail.events({
if (quantity < 1) {
quantity = 1;
}
if (currentVariant.inventoryPolicy && quantity > currentVariant.inventoryQuantity) {
if (currentVariant.inventoryManagement && quantity > currentVariant.inventoryQuantity) {
qtyField.val(currentVariant.inventoryQuantity);
}
}
Expand Down Expand Up @@ -199,17 +199,20 @@ Template.productDetail.events({
template.$(".title-edit-input").focus();
}
const variants = ReactionProduct.getVariants(self._id);
for (let variant of variants) {
let index = _.indexOf(variants, variant);
variants.forEach((variant, index) => {
if (!variant.title) {
errorMsg +=
`${i18next.t("error.variantFieldIsRequired", { field: i18next.t("productVariant.title"), number: index + 1 })} `;
}
if (!variant.price) {
errorMsg +=
`${i18next.t("error.variantFieldIsRequired", { field: i18next.t("productVariant.price"), number: index + 1 })} `;
// if top variant has children, it is not necessary to check its price
if (variant.ancestors.length === 1 && !ReactionProduct.checkChildVariants(variant._id) ||
variant.ancestors.length !== 1) {
if (!variant.price) {
errorMsg +=
`${i18next.t("error.variantFieldIsRequired", { field: i18next.t("productVariant.price"), number: index + 1 })} `;
}
}
}
});
if (errorMsg.length > 0) {
Alerts.inline(errorMsg, "warning", {
placement: "productManagement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>

{{#if hasPermission "createProduct"}}
<div class="variant-edit hidden-xs">
<div class="variant-edit hidden-xs" title="{{i18n 'productDetailEdit.editOption' 'Edit Option'}}">
<i class="fa fa-pencil fa-lg" data-id="{{_id}}"></i>
</div>
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ Template.childVariantForm.events({
"click #remove-child-variant": function (event) {
event.stopPropagation();
event.preventDefault();
let optionTitle = this.optionTitle || "this option";
if (confirm("Are you sure you want to delete " + optionTitle)) {
let id = this._id;
return Meteor.call("products/deleteVariant", id, function (error,
result) {
const title = this.optionTitle || i18next.t("productDetailEdit.thisOption");
if (confirm(i18next.t("productDetailEdit.removeVariantConfirm", { title }))) {
const id = this._id;
return Meteor.call("products/deleteVariant", id, function (error, result) {
// TODO why we have this on option remove?
if (result && ReactionProduct.selectedVariantId() === id) {
return ReactionProduct.setCurrentVariant(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ Template.variantForm.events({
Meteor.call("products/createVariant", template.data._id);
},
"click .btn-remove-variant": function () {
let title = this.title || "this variant";
if (confirm("Are you sure you want to delete " + title)) {
let id = this._id;
const title = this.title || i18next.t("productDetailEdit.thisVariant");
if (confirm(i18next.t("productDetailEdit.removeVariantConfirm", { title }))) {
const id = this._id;
Meteor.call("products/deleteVariant", id, function (error, result) {
if (result && ReactionProduct.selectedVariantId() === id) {
return ReactionProduct.setCurrentVariant(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,20 @@ Template.productGrid.helpers({
return 0;
}

let gridProducts = ReactionCore.Collections.Products.find({}).fetch();
// we are passing `ancestors: []`, because in case when we turn back from PDP
// for a moment we still subscribed to variants too, and we will get an error
// because of it, because our `productGrid` component can't work with variants
// objects.
//
// Also, we it is possible to change this selector to the following:
// `type: { $in: ["simple"] }`, but I found this way is not kind to package
// creators, because to specify they new product type, they will need to change
// this file, which broke another piece of compatibility with `reaction`
let gridProducts = ReactionCore.Collections.Products.find({
ancestors: []
// keep this, as an example
// type: { $in: ["simple"] }
}).fetch();
const products = gridProducts.sort(compare);
Template.instance().products = products;
return products;
Expand Down
4 changes: 2 additions & 2 deletions packages/reaction-ui/.npm/package/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1445ede

Please sign in to comment.