Skip to content

Commit

Permalink
Merge pull request #397 from evershopcommerce/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
treoden authored Nov 13, 2023
2 parents 9f3e40a + 534b3aa commit 7162d4d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import React from 'react';
import { useAppState } from '@components/common/context/app';
import { Card } from '@components/admin/cms/Card';

export default function BestCustomers({ listUrl }) {
export default function BestCustomers({ listUrl, setting }) {
const context = useAppState();
const currency = context.currency || 'USD';
const customers = context.bestCustomers || [];

return (
Expand Down Expand Up @@ -33,7 +32,7 @@ export default function BestCustomers({ listUrl }) {
{customers.map((c, i) => {
const grandTotal = new Intl.NumberFormat('en', {
style: 'currency',
currency
currency: setting.storeCurrency
}).format(c.total);
return (
// eslint-disable-next-line react/no-array-index-key
Expand All @@ -54,5 +53,17 @@ export default function BestCustomers({ listUrl }) {
}

BestCustomers.propTypes = {
setting: PropTypes.shape({
storeCurrency: PropTypes.string
}).isRequired,
listUrl: PropTypes.string.isRequired
};

export const query = `
query Query {
setting {
storeCurrency
}
listUrl: url(routeId: "productGrid")
}
`;
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import PropTypes from 'prop-types';
import React from 'react';
import { toast } from 'react-toastify';
import { useAppState } from '@components/common/context/app';
import { Card } from '@components/admin/cms/Card';
import './Bestsellers.scss';

export default function BestSellers({ api, listUrl }) {
const context = useAppState();
const currency = context.currency || 'USD';
export default function BestSellers({ api, listUrl, setting }) {
const [products, setProducts] = React.useState([]);
const [fetching, setFetching] = React.useState(true);

Expand Down Expand Up @@ -66,9 +63,9 @@ export default function BestSellers({ api, listUrl }) {
</tr>
)}
{products.map((p, i) => {
const formatedPrice = new Intl.NumberFormat('en', {
const formattedPrice = new Intl.NumberFormat('en', {
style: 'currency',
currency
currency: setting.storeCurrency
}).format(p.price);
return (
// eslint-disable-next-line react/no-array-index-key
Expand Down Expand Up @@ -112,7 +109,7 @@ export default function BestSellers({ api, listUrl }) {
{p.name}
</a>
</td>
<td>{formatedPrice}</td>
<td>{formattedPrice}</td>
<td>{p.qty} sold</td>
</tr>
);
Expand All @@ -126,6 +123,9 @@ export default function BestSellers({ api, listUrl }) {
}

BestSellers.propTypes = {
setting: PropTypes.shape({
storeCurrency: PropTypes.string
}).isRequired,
api: PropTypes.string.isRequired,
listUrl: PropTypes.string.isRequired
};
Expand All @@ -137,6 +137,9 @@ export const layout = {

export const query = `
query Query {
setting {
storeCurrency
}
api: url(routeId: "bestsellers")
listUrl: url(routeId: "productGrid")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');
const { emit } = require('@evershop/evershop/src/lib/event/emitter');
const { debug } = require('@evershop/evershop/src/lib/log/debuger');
const { getSetting } = require('../../../setting/services/setting');
const { display } = require('zero-decimal-currencies');

// eslint-disable-next-line no-unused-vars
module.exports = async (request, response, delegate, next) => {
Expand Down Expand Up @@ -56,7 +57,7 @@ module.exports = async (request, response, delegate, next) => {
// Create payment transaction
await insert('payment_transaction')
.given({
amount: paymentIntent.amount,
amount: parseFloat(display(paymentIntent.amount, paymentIntent.currency)),
payment_transaction_order_id: order.order_id,
transaction_id: paymentIntent.id,
transaction_type: 'online',
Expand Down

0 comments on commit 7162d4d

Please sign in to comment.