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

Marketplace shop settings #1939

Merged
merged 14 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion client/modules/accounts/templates/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Template.loginDropdown.events({
Template.accountsDropdownApps.helpers({
reactionAppsOptions() {
// get shortcuts with audience permissions based on user roles
const roles = Roles.getRolesForUser(Meteor.userId(), Reaction.getShopId());
const roles = Roles.getRolesForUser(Meteor.userId(), Reaction.getSellerShopId());

return {
provides: "shortcut",
Expand Down
13 changes: 0 additions & 13 deletions client/modules/accounts/templates/profile/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ <h3 class="panel-title" data-i18n="marketplace.becomeSeller">Become a Seller</h3
</div>
</div>
{{/if}}

{{#if hasPermission "admin"}}
<div class="flex-item">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title" data-i18n="admin.settings.shopSettingsLabel">Shop Settings</h3>
</div>
<div class="panel-content">
{{> sellerShopSettings }}
</div>
</div>
</div>
{{/if}}
</div>

</template>
6 changes: 5 additions & 1 deletion client/modules/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ export default {
if (Roles.userIsInRole(userId, permissions, group)) {
return true;
}
/* // global roles check

// global roles check
// TODO: Review this commented out code
/*

const sellerShopPermissions = Roles.getGroupsForUser(userId, "admin");
// we're looking for seller permissions.
if (sellerShopPermissions) {
Expand Down
3 changes: 2 additions & 1 deletion imports/plugins/core/orders/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Reaction.registerPackage({
icon: "fa fa-sun-o",
priority: 1,
container: "dashboard",
template: "orders"
template: "orders",
audience: ["seller"]
}, {
route: "/dashboard/pdf/orders/:id",
workflow: "coreOrderPrintWorkflow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,16 @@ describe("Inventory Hooks", function () {
}
});
spyOnMethod("copyCartToOrder", cart.userId);
const orderId = Meteor.call("cart/copyCartToOrder", cart._id).result;
const order = Orders.findOne(orderId);


// TODO: Should review after merging tag >= 1.1.1 to ensure compatibility
// Fixes bug where finding order by id was returning undefined
// Previously assigned orderId to the result of this.
// const orderId = Meteor.call("cart/copyCartToOrder", cart._id).result;
Meteor.call("cart/copyCartToOrder", cart._id);

// Previously was finding order by orderId
const order = Orders.findOne({ cartId: cart._id });
const shipping = { items: [] };
Meteor.call("orders/shipmentShipped", order, shipping, () => {
Meteor._sleepForMs(500);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,193 @@
<template name="sellerShopSettings">
<div class="form-group">
<label class="control-label" data-i18n="admin.settings.brandImageLabel">Brand Image</label>
{{> select brandImageSelectProps}}
{{> upload onUpload=handleFileUpload}}
</div>
{{!-- TODO Could be consolidated with shopSettings --}}
<div class="panel-group" id="sellerShopSettingsAccordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<a
href="#shop-general"
aria-controls="shop-general"
aria-expanded="true"
role="button"
data-toggle="collapse"
data-parent="#sellerShopSettingsAccordion"
data-i18n="shopSettings.general">General</a>
</div>
</div>
<div id="shop-general" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="General">
<div class="panel-body">
<div class="form-group">
<label class="control-label" data-i18n="admin.settings.brandImageLabel">Brand Image</label>
{{> select brandImageSelectProps}}
{{> upload onUpload=handleFileUpload}}
</div>

{{#autoForm collection=Collections.Shops doc=sellerShop schema=Schemas.Shop id="sellerShopEditForm" type="method-update" meteormethod="marketplace/updateShopDetails"}}
<div class="form-group{{#if afFieldIsInvalid name='name'}} has-error{{/if}}">
<label class="control-label"
data-i18n="shop.namePlaceholder">Shop Name</label>
{{>afFieldInput name="name" class="form-control"}}
{{#if afFieldIsInvalid name="name"}}
<span class="help-block">{{afFieldMessage name="name"}}</span>
{{/if}}
</div>
{{#autoForm collection=Collections.Shops
doc=sellerShop
schema=Schemas.Shop
id="sellerShopEditForm"
type="method-update"
meteormethod="marketplace/updateShopDetails"}}

<div class="form-group{{#if afFieldIsInvalid name='emails.0.address'}} has-error{{/if}}">
<label class="control-label"
data-i18n="shop.emailPlaceholder">Primary Contact Email</label>
{{>afFieldInput name="emails.0.address" class="form-control"}}
{{#if afFieldIsInvalid name="emails.0.address"}}
<span class="help-block">{{afFieldMessage name="emails.0.address"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="name"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.namePlaceholder">Shop Name</label>
{{>afFieldInput name="name" class="form-control"}}
{{#if afFieldIsInvalid name="name"}}
<span class="help-block">{{afFieldMessage name="name"}}</span>
{{/if}}
</div>

<div class="form-group{{#if afFieldIsInvalid name='description'}} has-error{{/if}}">
<label class="control-label"
data-i18n="shop.description">Description</label>
{{>afFieldInput name="description" class="form-control"}}
{{#if afFieldIsInvalid name="description"}}
<span class="help-block">{{afFieldMessage name="description"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="emails.0.address"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.emailPlaceholder">Primary Contact Email</label>
{{>afFieldInput name="emails.0.address" class="form-control"}}
{{#if afFieldIsInvalid name="emails.0.address"}}
<span class="help-block">{{afFieldMessage name="emails.0.address"}}</span>
{{/if}}
</div>

<div class="form-group{{#if afFieldIsInvalid name='keywords'}} has-error{{/if}}">
<label class="control-label"
data-i18n="shop.keywords">Keywords</label>
{{>afFieldInput name="keywords" class="form-control"}}
{{#if afFieldIsInvalid name="keywords"}}
<span class="help-block">{{afFieldMessage name="keywords"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="description"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.description">Description</label>
{{>afFieldInput name="description" class="form-control"}}
{{#if afFieldIsInvalid name="description"}}
<span class="help-block">{{afFieldMessage name="description"}}</span>
{{/if}}
</div>

<div class="form-group{{#if afFieldIsInvalid name="keywords"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.keywords">Keywords</label>
{{>afFieldInput name="keywords" class="form-control"}}
{{#if afFieldIsInvalid name="keywords"}}
<span class="help-block">{{afFieldMessage name="keywords"}}</span>
{{/if}}
</div>

<div class="form-group">
<label class="control-label" data-i18n="shop.timezone">Timezone</label>
{{>afFieldInput
type="select"
name="timezone"
class="form-control"
options=timezoneOptions}}
</div>

<div class="form-group{{#if afFieldIsInvalid name='currency'}} has-error{{/if}}">
<label class="control-label"
data-i18n="shop.currency">Base Currency</label>
{{>afFieldInput
type="select"
name="currency"
class="form-control"
options=currencyOptions}}
{{#if afFieldIsInvalid name="currencies.0.currency"}}
<span class="help-block">{{afFieldMessage name="currency"}}</span>
{{/if}}
<div class="form-group">
<label class="control-label" data-i18n="shop.currency">Base Currency</label>
{{>afFieldInput
type="select"
name="currency"
class="form-control"
options=currencyOptions}}
</div>

<div class="form-group">
<label class="control-label" data-i18n="shop.baseUOM">Base Unit of Measure</label>
{{>afFieldInput
type="select"
name="baseUOM"
class="form-control"
options=uomOptions}}
</div>

{{> shopSettingsSubmitButton}}
{{/autoForm}}
</div>
</div>
</div>

{{> shopSettingsSubmitButton}}
{{/autoForm}}
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<a
href="#shop-address"
aria-controls="shop-address"
aria-expanded="false"
role="button"
data-toggle="collapse"
data-parent="#sellerShopSettingsAccordion"
data-i18n="shopSettings.address">Address</a>
</div>
</div>
<div id="shop-address" class="panel-collapse collapse" role="tabpanel" aria-labelledby="address">
<div class="panel-body">
{{#autoForm collection=Collections.Shops
doc=sellerShop
id="sellerShopEditAddressForm"
type="method-update"
meteormethod="marketplace/updateShopDetails"}}

<div class="form-group{{#if afFieldIsInvalid name="company"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.addressBook.company">Company</label>
{{> afFieldInput name="addressBook.0.company" class="form-control"}}
{{#if afFieldIsInvalid name="addressBook.0.company"}}
<span class="help-block">{{afFieldMessage name="addressBook.0.company"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="fullName"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.addressBook.fullName">Full Name</label>
{{> afFieldInput name="addressBook.0.fullName" class="form-control"}}
{{#if afFieldIsInvalid name="addressBook.0.fullName"}}
<span class="help-block">{{afFieldMessage name="addressBook.0.fullName"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="address1"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.addressBook.address1">Address 1</label>
{{> afFieldInput name="addressBook.0.address1" class="form-control"}}
{{#if afFieldIsInvalid name="addressBook.0.address1"}}
<span class="help-block">{{afFieldMessage name="addressBook.0.address1"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="address2"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.addressBook.address2">Address 2</label>
{{> afFieldInput name="addressBook.0.address2" class="form-control"}}
{{#if afFieldIsInvalid name="addressBook.0.address2"}}
<span class="help-block">{{afFieldMessage name="addressBook.0.address2"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="city"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.addressBook.city">City</label>
{{> afFieldInput name="addressBook.0.city" class="form-control"}}
{{#if afFieldIsInvalid name="addressBook.0.city"}}
<span class="help-block">{{afFieldMessage name="addressBook.0.city"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="region"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.addressBook.region">Region</label>
{{> afFieldInput name="addressBook.0.region" class="form-control"}}
{{#if afFieldIsInvalid name="addressBook.0.region"}}
<span class="help-block">{{afFieldMessage name="addressBook.0.region"}}</span>
{{/if}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="postal"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.addressBook.postal">Postal</label>
{{> afFieldInput name="addressBook.0.postal" class="form-control"}}
{{#if afFieldIsInvalid name="addressBook.0.postal"}}
<span class="help-block">{{afFieldMessage name="addressBook.0.postal"}}</span>
{{/if}}
</div>
<div class="form-group">
<label class="control-label" data-i18n="shop.addressBook.country">Country</label>
{{> afFieldInput name="addressBook.0.country"
type="select"
options=countryOptions
class="form-control"}}
</div>
<div class="form-group{{#if afFieldIsInvalid name="phone"}} has-error{{/if}}">
<label class="control-label" data-i18n="shop.addressBook.phone">Phone</label>
{{> afFieldInput name="addressBook.0.phone" class="form-control"}}
{{#if afFieldIsInvalid name="addressBook.0.phone"}}
<span class="help-block">{{afFieldMessage name="addressBook.0.phone"}}</span>
{{/if}}
</div>
<div class="form-group">
{{> afFieldInput name="addressBook.0.isCommercial"}}
{{> afFieldInput name="addressBook.0.isShippingDefault" defaultValue=true}}
{{> afFieldInput name="addressBook.0.isBillingDefault" defaultValue=true}}

{{> shopSettingsSubmitButton}}
</div>
{{/autoForm}}
</div>
</div>
</div>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import _ from "lodash";
import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { Reaction } from "/lib/api";
import { i18next } from "/client/api";
import { SellerShops, Media } from "/lib/collections";
import { i18next } from "/client/api";
import { Countries } from "/client/collections";

Template.sellerShopSettings.onCreated(function () {
this.autorun(() => {
this.subscribe("SellerShops");
});
});

Template.sellerShopSettings.onCreated(function () {
this.autorun(() => {
Expand Down Expand Up @@ -103,6 +110,29 @@ Template.sellerShopSettings.helpers({
return currencies;
},

// TODO change for i18n
countryOptions() {
return Countries.find().fetch();
},

uomOptions() {
const sellerShop = Reaction.getSellerShop();

if (!sellerShop) {
return;
}

const unitsOfMeasure = sellerShop.unitsOfMeasure;
const uomOptions = [];
for (const measure of unitsOfMeasure) {
uomOptions.push({
label: i18next.t(`uom.${measure.uom}`, { defaultValue: measure.uom }),
value: measure.uom
});
}
return uomOptions;
},

selectedCurrency() {
const sellerShop = Reaction.getSellerShop();

Expand All @@ -123,9 +153,8 @@ Template.sellerShopSettings.helpers({
});

/**
* shopSettings autoform alerts
* shop settings autoform alerts
*/

AutoForm.hooks({
sellerShopEditForm: {
onSuccess: function () {
Expand All @@ -139,3 +168,20 @@ AutoForm.hooks({
}
}
});

/**
* shop address autoform alerts
*/
AutoForm.hooks({
sellerShopEditAddressForm: {
onSuccess: function () {
return Alerts.toast(i18next.t("shopSettings.shopAddressSettingsSaved"),
"success");
},
onError: function (operation, error) {
return Alerts.toast(
`${i18next.t("shopSettings.shopAddressSettingsFailed")} ${error}`, "error"
);
}
}
});
Loading