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

Remove hardcoded billing and shipping objects #2813

Merged
merged 74 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
d7b40d0
When creating shipping records, create one for each shop
brent-hoover Aug 31, 2017
864e52d
Return an empty object if cart has no items
brent-hoover Sep 1, 2017
dc3f5ee
Fix grammatical errors in test description
brent-hoover Sep 1, 2017
e0dc83e
Update copyToCart to work with by shop shipping records
brent-hoover Sep 1, 2017
e23ed7c
Add billing/shipping shopIds to fix stripe test
brent-hoover Sep 1, 2017
aa772ee
Break copyCartToOrder to it's own file
brent-hoover Sep 1, 2017
fa45c4f
Add shopId to schema
brent-hoover Sep 1, 2017
bf9e50d
Set selected method on all shipping records
brent-hoover Sep 1, 2017
42d6341
Only show shipping methods associate with the primary shop
brent-hoover Sep 1, 2017
a9433c4
Check rates against schema
brent-hoover Sep 1, 2017
cd701b1
Remove blackbox from Cart.shipping so it will actually validate
brent-hoover Sep 1, 2017
5ba6521
Validate shipping methods
brent-hoover Sep 1, 2017
37f6a7c
Put blackbox back
brent-hoover Sep 5, 2017
baab68c
simple-schema not working, remove
brent-hoover Sep 5, 2017
8916529
only show shipping methods from primaryShopId
brent-hoover Sep 5, 2017
9d0010a
Merge branch 'marketplace' into brent-fix-shipping-record-noshopid
brent-hoover Sep 5, 2017
d3d1da9
Lint fixes
brent-hoover Sep 5, 2017
ded21a6
Merge branch 'marketplace' into brent-fix-shipping-record-noshopid
brent-hoover Sep 7, 2017
b24c32a
Assign items to shipping records based on shopId
brent-hoover Sep 7, 2017
278ee70
Assign shopIds when adding shipping address
brent-hoover Sep 7, 2017
b245a4d
Only show the address when it has data
brent-hoover Sep 7, 2017
48b81fe
Lint fix
brent-hoover Sep 7, 2017
553d893
FIx tests
brent-hoover Sep 7, 2017
78fd30e
Merge branch 'marketplace' into brent-fix-shipping-record-noshopid
spencern Sep 7, 2017
f33da7d
Remove hardcoded shipping object
Sep 7, 2017
4fd58e1
Remove more instances of shipping[0] and billing[0]
Sep 8, 2017
5fd8f8c
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 8, 2017
a3c4c4c
Fix react proptype error
Sep 8, 2017
4933b60
Fix billingRecord error
Sep 8, 2017
7e624ac
export getShipppingObject function outside of component
Sep 8, 2017
5297781
More removal of hardcoded shipping object
Sep 8, 2017
09e17ad
More removal of hardcoded shipping and billing object
Sep 8, 2017
e8709c3
Fix failing tests
Sep 8, 2017
eed0d3d
Remove hardcoded shipping object
Sep 11, 2017
847805f
Rewrite test suits to remove hardcoded shipping and billing objects
Sep 12, 2017
9d15260
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 12, 2017
3e04d1d
Export helper functions out of components, add JSDOCs for them
Sep 12, 2017
15cf436
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 13, 2017
97b8bc4
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 13, 2017
44dd1a1
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 13, 2017
c19b4fa
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
spencern Sep 14, 2017
c30e0d8
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 14, 2017
1554d97
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 14, 2017
30a5bbd
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 15, 2017
42bbd41
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 18, 2017
70592a7
Move getBillingInfo and getShippingInfo to helper file; refactor find…
Sep 18, 2017
21c4798
Merge branch 'kieha-remove-zeroth-indexes-2770' of https://github.com…
Sep 18, 2017
2fc89ba
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
spencern Sep 18, 2017
9bc17b8
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
spencern Sep 19, 2017
cb72ef5
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 19, 2017
2db1e56
Replace empty string object key with non-empty string; create headerl…
Sep 19, 2017
c566890
Fix typo; prefer 'error' over 'err'
Sep 19, 2017
50c4f2b
Revert spinner fix
Sep 19, 2017
0b1babe
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 19, 2017
7e42107
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 20, 2017
e6b1e12
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 20, 2017
09802e9
Scope nested callback errors based on Meteor call action
Sep 21, 2017
2a17940
Handle errors if getBillingInfo method returns empty object
Sep 21, 2017
806e1e8
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 21, 2017
da8f1b3
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 21, 2017
6e59986
Handle errors if getBillingInfo method returns empty object
Sep 21, 2017
fe06cf1
Resolve merge conflicts
Sep 21, 2017
dd1c62f
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
spencern Sep 22, 2017
a4fcf23
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 23, 2017
c8209df
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 24, 2017
8b0b539
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
spencern Sep 24, 2017
529a531
Pass empty object to 'getBillingInfo' and 'getShippingInfo' calls if …
Sep 26, 2017
d5590a6
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
Sep 26, 2017
6b7cf0a
Merge branch 'kieha-remove-zeroth-indexes-2770' of https://github.com…
Sep 26, 2017
16a7be4
Remove lodash references
Sep 26, 2017
608b086
Remove more lodash references; use shorthand function patters for one…
Sep 26, 2017
e6368d7
Fix failing tests
Sep 26, 2017
0fe9e6a
Fix case issue in orderTable
spencern Sep 26, 2017
e645ede
Merge branch 'marketplace' into kieha-remove-zeroth-indexes-2770
spencern Sep 26, 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
35 changes: 23 additions & 12 deletions imports/plugins/core/orders/client/components/orderSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from "react";
import PropTypes from "prop-types";
import moment from "moment";
import { Badge, ClickToCopy } from "@reactioncommerce/reaction-ui";
import { getOrderRiskBadge, getOrderRiskStatus } from "../helpers";
import { getOrderRiskBadge, getOrderRiskStatus, getBillingInfo, getShippingInfo } from "../helpers";

class OrderSummary extends Component {
static propTypes = {
Expand All @@ -15,7 +15,8 @@ class OrderSummary extends Component {
}

badgeStatus() {
const orderStatus = this.props.order.workflow.status;
const order = this.props.order;
const orderStatus = order && order.workflow && order.workflow.status;

if (orderStatus === "new") {
return "info";
Expand Down Expand Up @@ -44,12 +45,18 @@ class OrderSummary extends Component {

render() {
const { dateFormat, tracking, order, profileShippingAddress, printableLabels } = this.props;
const paymentMethod = getBillingInfo(order).paymentMethod || {};
const invoice = getBillingInfo(order).invoice || {};
const shipmentMethod = getShippingInfo(order).shipmentMethod || {};
const orderRisk = getOrderRiskStatus(order);

return (
<div>
<div className="order-summary-form-group bg-info" style={{ lineHeight: 3, marginTop: -15, marginRight: -15, marginLeft: -15 }}>
<strong style={{ marginLeft: 15 }}>{profileShippingAddress.fullName}</strong>
<div
className="order-summary-form-group bg-info"
style={{ lineHeight: 3, marginTop: -15, marginRight: -15, marginLeft: -15 }}
>
<strong style={{ marginLeft: 15 }}>{profileShippingAddress && profileShippingAddress.fullName}</strong>
<div className="invoice-details" style={{ marginRight: 15, position: "relative" }}>
{order.email}
</div>
Expand All @@ -60,8 +67,8 @@ class OrderSummary extends Component {
<div style={{ marginBottom: 4 }}>
<Badge
badgeSize="large"
i18nKeyLabel={`cartDrawer.${order.workflow.status}`}
label={order.workflow.status}
i18nKeyLabel={`cartDrawer.${order && order.workflow && order.workflow.status}`}
label={order && order.workflow && order.workflow.status}
status={this.badgeStatus()}
/>
{orderRisk &&
Expand Down Expand Up @@ -97,28 +104,28 @@ class OrderSummary extends Component {
<div className="order-summary-form-group">
<strong data-i18n="order.processor">Processor</strong>
<div className="invoice-details">
{order.billing[0].paymentMethod.processor}
{paymentMethod && paymentMethod.processor}
</div>
</div>

<div className="order-summary-form-group">
<strong data-i18n="order.payment">Payment</strong>
<div className="invoice-details">
{order.billing[0].paymentMethod.storedCard} ({order.billing[0].invoice.total})
{paymentMethod.storedCard} ({invoice.total})
</div>
</div>

<div className="order-summary-form-group">
<strong data-i18n="order.transaction">Transaction</strong>
<div className="invoice-details">
{order.billing[0].paymentMethod.transactionId}
{paymentMethod.transactionId}
</div>
</div>

<div className="order-summary-form-group">
<strong data-i18n="orderShipping.carrier">Carrier</strong>
<div className="invoice-details">
{order.shipping[0].shipmentMethod.carrier} - {order.shipping[0].shipmentMethod.label}
{shipmentMethod.carrier} - {shipmentMethod.label}
</div>
</div>

Expand Down Expand Up @@ -155,9 +162,13 @@ class OrderSummary extends Component {

<div style={{ marginTop: 4 }}>
<span>{profileShippingAddress.fullName}</span>
<br/><span>{profileShippingAddress.address1}</span>
<br/>
<span>{profileShippingAddress.address1}</span>
{profileShippingAddress.address2 && <span><br/>{profileShippingAddress.address2}</span>}
<br/><span>{profileShippingAddress.city}, {profileShippingAddress.region}, {profileShippingAddress.country} {profileShippingAddress.postal}</span>
<br/>
<span>
{profileShippingAddress.city}, {profileShippingAddress.region}, {profileShippingAddress.country} {profileShippingAddress.postal}
</span>
</div>
</div>
);
Expand Down
106 changes: 64 additions & 42 deletions imports/plugins/core/orders/client/components/orderTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ import PropTypes from "prop-types";
import Avatar from "react-avatar";
import moment from "moment";
import classnames from "classnames/dedupe";
import { Reaction, i18next } from "/client/api";
import { i18next } from "/client/api";
import { Orders } from "/lib/collections";
import { Badge, ClickToCopy, Icon, Translation, Checkbox, Loading, SortableTable } from "@reactioncommerce/reaction-ui";
import OrderTableColumn from "./orderTableColumn";
import OrderBulkActionsBar from "./orderBulkActionsBar";
import { formatPriceString } from "/client/api";
import ProductImage from "./productImage";
import { getOrderRiskBadge, getOrderRiskStatus } from "../helpers";
import { getOrderRiskBadge, getOrderRiskStatus, getBillingInfo, getShippingInfo } from "../helpers";

const classNames = {
colClassNames: {
"name": "order-table-column-name",
"email": "order-table-column-email",
"date": "order-table-column-date hidden-xs hidden-sm",
"id": "order-table-column-id hidden-xs hidden-sm",
"total": "order-table-column-total",
"shipping": "order-table-column-shipping hidden-xs hidden-sm",
"status": "order-table-column-status",
"": "order-table-column-control"
name: "order-table-column-name",
email: "order-table-column-email",
date: "order-table-column-date hidden-xs hidden-sm",
id: "order-table-column-id hidden-xs hidden-sm",
total: "order-table-column-total",
shipping: "order-table-column-shipping hidden-xs hidden-sm",
status: "order-table-column-status",
control: "order-table-column-control"
},
headerClassNames: {
"name": "order-table-header-name",
"email": "order-table-header-email",
"date": "order-table-header-date hidden-xs hidden-sm",
"id": "order-table-header-id hidden-xs hidden-sm",
"total": "order-table-header-total",
"shipping": "order-table-header-shipping hidden-xs hidden-sm",
"status": "order-table-header-status",
"": "order-table-header-control"
name: "order-table-header-name",
email: "order-table-header-email",
date: "order-table-header-date hidden-xs hidden-sm",
id: "order-table-header-id hidden-xs hidden-sm",
total: "order-table-header-total",
shipping: "order-table-header-shipping hidden-xs hidden-sm",
status: "order-table-header-status",
control: "order-table-header-control"
}
};

Expand All @@ -54,13 +54,6 @@ class OrderTable extends Component {
toggleShippingFlowList: PropTypes.func
}

// helper function to get appropriate billing info
getBillingInfo(order) {
return order.billing.find(
billing => billing.shopId === Reaction.getShopId()
) || {};
}

/**
* Fullfilment Badge
* @param {Object} order object containing info for order and coreOrderWorkflow
Expand Down Expand Up @@ -100,6 +93,7 @@ class OrderTable extends Component {

renderOrderInfo(order) {
const { displayMedia } = this.props;
const invoice = getBillingInfo(order).invoice || {};

return (
<div className="order-info">
Expand All @@ -120,7 +114,7 @@ class OrderTable extends Component {
</span>

<span className="order-data order-data-total">
<strong>Total: {formatPriceString(this.getBillingInfo(order).invoice.total)}</strong>
<strong>Total: {formatPriceString(invoice.total)}</strong>
</span>
</div>

Expand All @@ -145,7 +139,9 @@ class OrderTable extends Component {
}

renderShipmentInfo(order) {
const emailAddress = order.email || <Translation defaultValue={"Email not availabe"} i18nKey={"admin.orderWorkflow.ordersList.emailNotFound"} />;
const emailAddress = order.email ||
<Translation defaultValue={"Email not available"} i18nKey={"admin.orderWorkflow.ordersList.emailNotFound"} />;
const shipping = getShippingInfo(order);
const orderRisk = getOrderRiskStatus(order);

return (
Expand All @@ -154,11 +150,11 @@ class OrderTable extends Component {
<Avatar
email={order.email}
round={true}
name={order.shipping[0].address.fullName}
name={shipping.address && shipping.address.fullName}
size={30}
className="rui-order-avatar"
/>
<strong>{order.shipping[0].address.fullName}</strong> | {emailAddress}
<strong>{shipping.address && shipping.address.fullName}</strong> | {emailAddress}
{orderRisk &&
<Badge
className="risk-info"
Expand All @@ -170,8 +166,8 @@ class OrderTable extends Component {
<div className="workflow-info">
<Badge
badgeSize="large"
i18nKeyLabel={`cartDrawer.${order.shipping[0].workflow.status}`}
label={order.shipping[0].workflow.status}
i18nKeyLabel={`cartDrawer.${shipping.workflow && shipping.workflow.status}`}
label={shipping.workflow && shipping.workflow.status}
status="basic"
/>
<Badge
Expand Down Expand Up @@ -216,14 +212,38 @@ class OrderTable extends Component {
if (this.props.isOpen) {
// Render order list column/row data
const filteredFields = {
"name": "shipping[0].address.fullName",
"email": "email",
"date": "createdAt",
"id": "_id",
"total": "billing[0].invoice.total",
"shipping": "shipping[0].workflow.status",
"status": "workflow.status",
"": ""
name: {
accessor: row => getShippingInfo(row).address && getShippingInfo(row).address.fullName,
id: "shippingFullName"
},
email: {
accessor: "email",
id: "email"
},
date: {
accessor: "createdAt",
id: "createdAt"
},
id: {
accessor: "_id",
id: "_id"
},
total: {
accessor: row => getBillingInfo(row).invoice && getBillingInfo(row).invoice.total,
id: "billingTotal"
},
shipping: {
accessor: row => getShippingInfo(row).workflow && getShippingInfo(row).workflow.status,
id: "shippingStatus"
},
status: {
accessor: "workflow.status",
id: "workflow.status"
},
control: {
accessor: "",
id: ""
}
};

const columnNames = Object.keys(filteredFields);
Expand Down Expand Up @@ -271,16 +291,18 @@ class OrderTable extends Component {
</span>
</div>
);
} else if (columnName === "") {
columnNameLabel = "";
} else if (columnName === "control") {
colHeader = " ";
resizable = false;
sortable = false;
} else {
columnNameLabel = i18next.t(`admin.table.headers.${columnName}`);
}


const columnMeta = {
accessor: filteredFields[columnName],
accessor: filteredFields[columnName].accessor,
id: filteredFields[columnName].id,
Header: colHeader ? colHeader : columnNameLabel,
headerClassName: classNames.headerClassNames[columnName],
className: classNames.colClassNames[columnName],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import moment from "moment";
import { formatPriceString, i18next } from "/client/api";
import Avatar from "react-avatar";
import { Badge, ClickToCopy, Icon, RolloverCheckbox, Checkbox } from "@reactioncommerce/reaction-ui";
import { getOrderRiskBadge, getOrderRiskStatus } from "../helpers";
import { getOrderRiskBadge, getOrderRiskStatus, getBillingInfo } from "../helpers";

class OrderTableColumn extends Component {
static propTypes = {
Expand Down Expand Up @@ -49,9 +49,10 @@ class OrderTableColumn extends Component {

render() {
const columnAccessor = this.props.row.column.id;
const invoice = getBillingInfo(this.props.row.original).invoice || {};
const orderRisk = getOrderRiskStatus(this.props.row.original);

if (columnAccessor === "shipping[0].address.fullName") {
if (columnAccessor === "shippingFullName") {
return (
<div style={{ display: "inline-flex" }}>
{this.renderCheckboxOnSelect(this.props.row)}
Expand Down Expand Up @@ -93,14 +94,14 @@ class OrderTableColumn extends Component {
</div>
);
}
if (columnAccessor === "billing[0].invoice.total") {
if (columnAccessor === "billingTotal") {
return (
<div style={{ marginTop: 7 }}>
<strong>{formatPriceString(this.props.row.original.billing[0].invoice.total)}</strong>
<strong>{formatPriceString(invoice.total)}</strong>
</div>
);
}
if (columnAccessor === "shipping[0].workflow.status") {
if (columnAccessor === "shippingStatus") {
return (
<Badge
className="orders-badge"
Expand Down
Loading