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

Shipping panel normalization #1740

Merged
merged 38 commits into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f95abc7
Migrate flat rates to shipping-rates plugin
Jan 23, 2017
0280620
Update from release-0.19
Jan 26, 2017
a2124d0
Initial shipping grid refactor
Jan 28, 2017
f615503
Merge branch 'release-0.19.0' into 1404-shipping-dashboard-panels
Jan 28, 2017
ab0936e
Catch invalid product grid filters
Jan 28, 2017
5b3910c
Add transform
Jan 28, 2017
4220cfc
Flat rate editing
Jan 28, 2017
50aa1a7
Remove old shipping ui
Jan 28, 2017
f5320ba
remove Loading template
Jan 28, 2017
2c77c6b
Rename shippoMethod -> settings
Jan 28, 2017
a463c2a
consolidated checkout shipping template
Jan 28, 2017
4a35660
Default groups
Jan 28, 2017
8a55415
fallback to shop email for guest orders
Jan 28, 2017
07c9b97
Resolve variables.less conflict
Jan 28, 2017
bebc96b
make transform optional
Jan 29, 2017
7962bf2
Silence of the logs
Jan 29, 2017
ec91188
Catch case where items is undefined
Jan 29, 2017
0f59d0d
Updated SMS label
Jan 29, 2017
a481bda
Update imports, add roles
Jan 29, 2017
2d56952
bs form defaults
Jan 29, 2017
3f46cb2
Refactor notes
Jan 29, 2017
097c48f
Add shippo carrier UI
Jan 29, 2017
6e45652
Implement onGetShippingRates hook
Jan 29, 2017
3a41db5
Updated configuration alert
Jan 29, 2017
5ac92d9
Deprecate core shipping methods
Jan 29, 2017
1b753f8
Shippo Carrier editing
Jan 29, 2017
21ffb70
Add flatten-obj dependency
Jan 29, 2017
b780a6b
Remove iconButton from carriers
Jan 29, 2017
e049a09
Update shipping configuration check
Jan 30, 2017
7259774
Updated provider enable/disable handling
Jan 30, 2017
dc161df
Updated payment package toggle handling
Jan 30, 2017
37663f0
Merge branch 'release-0.19.0' into 1404-shipping-dashboard-panels
Jan 30, 2017
18e6e5a
Lint / review cleanup
Jan 31, 2017
4e4ab49
Updated dependencies
Jan 31, 2017
5cc5120
[better] pattern implementation for roles.
Jan 31, 2017
46fd621
Add loader, revised loading state check
Jan 31, 2017
f25f61d
Removed default enabled
Jan 31, 2017
f50bccb
Remove carrier label editing
Jan 31, 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
3 changes: 3 additions & 0 deletions client/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ Session.setDefault("DEFAULT_LAYOUT", DEFAULT_LAYOUT);
Session.setDefault("DEFAULT_WORKFLOW", DEFAULT_WORKFLOW);
Session.setDefault("INDEX_OPTIONS", INDEX_OPTIONS);
Session.setDefault("productScrollLimit", ITEMS_INCREMENT);

// autoform default template
AutoForm.setDefaultTemplate("bootstrap3");
1 change: 0 additions & 1 deletion imports/plugins/core/layout/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import "./templates/layout/header/button.html";
import "./templates/layout/header/header.html";
import "./templates/layout/header/header.js";
import "./templates/layout/header/tags.html";
import "./templates/layout/loading/loading.html";
import "./templates/layout/notFound/notFound.html";
import "./templates/layout/notFound/notFound.js";
import "./templates/layout/notice/unauthorized.html";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ <h3 class="panel-title">
</h3>
</div>
{{#if isReady}}
{{#each reactionApps provides='shippingMethod' enabled=true}}
{{> Template.dynamic template=template}}
{{else}}
<div class="panel-body">
<div class="alert alert-danger">
<span data-i18n="checkoutShipping.noShippingPackages">No shipping packages are configured. </span>
<a href="{{pathFor 'dashboard'}}">
<span data-i18n="checkoutShipping.configureNow">Configure now.</span>
</a>
</div>
</div>
{{/each}}
<div class="panel-body">
<ul class="checkout-shipping list-group">
{{#if shippingConfigured}}
{{#each shipmentQuotes}}
<li class="list-group-item {{isSelected ..}}" data-carrier="{{carrier}}" data-method="{{method}}">
<span class="text-left">{{method.carrier}} - {{method.label}}</span>
<span class="pull-right">{{formatPrice rate}}</span>
</li>
{{else}}
<div class="panel-body">
<div class="alert alert-danger">
<span data-i18n="checkoutShipping.noShippingMethods">No shipping methods are configured.</span>
<a href="{{pathFor 'dashboard'}}">
<span data-i18n="checkoutShipping.configureNow">Configure now.</span>
</a>
</div>
</div>
{{/each}}
{{/if}}
</ul>
</div>
{{else}}
<div class="spinner-container">
<div class="spinner"></div>
Expand Down
64 changes: 41 additions & 23 deletions imports/plugins/core/shipping/client/templates/checkout/shipping.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
import _ from "lodash";
import { Cart, Shipping } from "/lib/collections";
import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { Reaction } from "/client/api";
import { Cart, Shipping } from "/lib/collections";

//
// These helpers can be used in general shipping packages
// cartShippingMethods to get current shipment methods
// until we handle multiple methods, we just use the first
function cartShippingMethods(currentCart) {
// cartShippingQuotes
// returns multiple methods
function cartShippingQuotes(currentCart) {
const cart = currentCart || Cart.findOne();
const shipmentQuotes = [];

if (cart) {
if (cart.shipping) {
if (cart.shipping[0].shipmentQuotes) {
return cart.shipping[0].shipmentQuotes;
for (shipping of cart.shipping) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be const shipping?

if (shipping.shipmentQuotes) {
for (quote of shipping.shipmentQuotes) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here as well?

shipmentQuotes.push(quote);
}
}
}
}
}
return undefined;
return shipmentQuotes;
}
// getShipmentMethod to get current shipment method
// until we handle multiple methods, we just use the first
function getShipmentMethod(currentCart) {
// cartShipmentMethods to get current shipment method
// this returns multiple methods, if more than one carrier
// has been chosen
function cartShipmentMethods(currentCart) {
const cart = currentCart || Cart.findOne();
const shipmentMethods = [];

if (cart) {
if (cart.shipping) {
if (cart.shipping[0].shipmentMethod) {
return cart.shipping[0].shipmentMethod;
for (shipping of cart.shipping) {
if (shipping.shipmentMethod) {
shipmentMethods.push(shipping.shipmentMethod);
}
}
}
}
return undefined;
return shipmentMethods;
}

Template.coreCheckoutShipping.onCreated(function () {
Expand All @@ -42,8 +52,11 @@ Template.coreCheckoutShipping.helpers({
// retrieves current rates and updates shipping rates
// in the users cart collection (historical, and prevents repeated rate lookup)
shipmentQuotes: function () {
const cart = Cart.findOne();
return cartShippingMethods(cart);
const instance = Template.instance();
if (instance.subscriptionsReady()) {
const cart = Cart.findOne();
return cartShippingQuotes(cart);
}
},

// helper to make sure there are some shipping providers
Expand All @@ -59,10 +72,13 @@ Template.coreCheckoutShipping.helpers({
// helper to display currently selected shipmentMethod
isSelected: function () {
const self = this;
const shipmentMethod = getShipmentMethod();
// if there is already a selected method, set active
if (_.isEqual(self.method, shipmentMethod)) {
return "active";
const shipmentMethods = cartShipmentMethods();

for (method of shipmentMethods) {
// if there is already a selected method, set active
if (_.isEqual(self.method, method)) {
return "active";
}
}
return null;
},
Expand All @@ -71,8 +87,10 @@ Template.coreCheckoutShipping.helpers({
const instance = Template.instance();
const isReady = instance.subscriptionsReady();

if (isReady) {
return true;
if (Reaction.Subscriptions.Cart.ready()) {
if (isReady) {
return true;
}
}

return false;
Expand Down

This file was deleted.

This file was deleted.

8 changes: 2 additions & 6 deletions imports/plugins/core/shipping/client/templates/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import "./checkout/shipping.html";
import "./checkout/shipping.js";

import "./flatRates/shipping.html";
import "./flatRates/shipping.js";

import "./shipping.html";
import "./shipping.js";
import "./shipping.less";
import "./settings/shipping.html";
import "./settings/shipping.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template name="shippingSettings">
{{#each reactionApps provides='shippingSettings'}}

<div class="panel panel-default">
<div class="panel-heading panel-heading-flex">
<div class="panel-title">
<i class="fa fa-{{name}}"></i>
<span data-i18n="{{i18nKeyLabel}}">{{label}}</span>

</div>
<div class="panel-controls">
<input class="checkbox-switch shipping-settings" type="checkbox" name="enabled" data-id={{packageId}} data-key="{{settingsKey}}" {{checked enabled}}>
</div>
</div>
<div class="panel-body {{shown enabled}}">
{{> Template.dynamic template=template data=.}}
</div>
</div>
{{/each}}

</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Template } from "meteor/templating";
/*
* Template shippinges Helpers
*/
Template.shippingSettings.onCreated(function () {
this.autorun(() => {
this.subscribe("Shipping");
});
});

Template.shippingSettings.helpers({
checked(enabled) {
if (enabled === true) {
return "checked";
}
return "";
},
shown(enabled) {
if (enabled !== true) {
return "hidden";
}
return "";
}
});

Template.shippingSettings.events({
/**
* shippingSettings settings update enabled status for shipping service on change
* @param {event} event jQuery Event
* @return {void}
*/
"change input.checkbox-switch.shipping-settings[name=enabled]": (event) => {
event.preventDefault();
const settingsKey = event.target.getAttribute("data-key");
const packageId = event.target.getAttribute("data-id");
const fields = [{
property: "enabled",
value: event.target.checked
}];
// save shipping registry updates
if (packageId) {
// TODO also disable providers
Meteor.call("registry/update", packageId, settingsKey, fields);
}
}
});
Loading