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

Dev #610

Merged
merged 4 commits into from
Sep 3, 2024
Merged

Dev #610

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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function CartSummary({
subTotalInclTax,
grandTotal,
discountAmount,
taxAmount,
totalTaxAmount,
shippingMethodName,
shippingFeeInclTax,
coupon,
Expand All @@ -25,10 +25,10 @@ function CartSummary({
total={priceIncludingTax ? subTotalInclTax.text : subTotal.text}
/>
<Shipping method={shippingMethodName} cost={shippingFeeInclTax.text} />
{!priceIncludingTax && <Tax amount={taxAmount.text} />}
{!priceIncludingTax && <Tax amount={totalTaxAmount.text} />}
<Discount code={coupon} discount={discountAmount.text} />
<Total
taxAmount={taxAmount.text}
totalTaxAmount={totalTaxAmount.text}
total={grandTotal.text}
priceIncludingTax={priceIncludingTax}
/>
Expand All @@ -54,7 +54,7 @@ CartSummary.propTypes = {
subTotalInclTax: PropTypes.shape({
text: PropTypes.string.isRequired
}),
taxAmount: PropTypes.shape({
totalTaxAmount: PropTypes.shape({
text: PropTypes.string.isRequired
}),
totalQty: PropTypes.string,
Expand All @@ -79,7 +79,7 @@ CartSummary.defaultProps = {
subTotalInclTax: {
text: ''
},
taxAmount: {
totalTaxAmount: {
text: ''
},
totalQty: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { _ } from '@evershop/evershop/src/lib/locale/translate';

export function Total({ total, taxAmount, priceIncludingTax }) {
export function Total({ total, totalTaxAmount, priceIncludingTax }) {
return (
<div className="summary-row grand-total flex justify-between">
{(priceIncludingTax && (
Expand All @@ -13,7 +13,7 @@ export function Total({ total, taxAmount, priceIncludingTax }) {
</div>
<div>
<span className="italic">
({_('Inclusive of tax ${taxAmount}', { taxAmount })})
({_('Inclusive of tax ${totalTaxAmount}', { totalTaxAmount })})
</span>
</div>
</div>
Expand All @@ -29,7 +29,7 @@ export function Total({ total, taxAmount, priceIncludingTax }) {

Total.propTypes = {
total: PropTypes.string.isRequired,
taxAmount: PropTypes.string.isRequired,
totalTaxAmount: PropTypes.string.isRequired,
priceIncludingTax: PropTypes.bool
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function OrderSummary({
subTotalInclTax,
shippingMethodName,
shippingFeeInclTax,
taxAmount,
totalTaxAmount,
discountAmount,
coupon,
grandTotal,
Expand All @@ -25,12 +25,12 @@ function OrderSummary({
total={priceIncludingTax ? subTotalInclTax.text : subTotal.text}
/>
<Shipping method={shippingMethodName} cost={shippingFeeInclTax.text} />
{!priceIncludingTax && <Tax taxClass="" amount={taxAmount.text} />}
{!priceIncludingTax && <Tax taxClass="" amount={totalTaxAmount.text} />}
<Discount code={coupon} discount={discountAmount.text} />
<Total
total={grandTotal.text}
priceIncludingTax={priceIncludingTax}
taxAmount={taxAmount.text}
totalTaxAmount={totalTaxAmount.text}
/>
</div>
);
Expand Down Expand Up @@ -64,7 +64,7 @@ OrderSummary.propTypes = {
subTotalInclTax: PropTypes.shape({
text: PropTypes.string
}),
taxAmount: PropTypes.shape({
totalTaxAmount: PropTypes.shape({
text: PropTypes.string
}),
priceIncludingTax: PropTypes.bool.isRequired
Expand All @@ -88,7 +88,7 @@ OrderSummary.defaultProps = {
subTotalInclTax: {
text: '0.00'
},
taxAmount: {
totalTaxAmount: {
text: '0.00'
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { _ } from '@evershop/evershop/src/lib/locale/translate';

export function Total({ total, taxAmount, priceIncludingTax }) {
export function Total({ total, totalTaxAmount, priceIncludingTax }) {
return (
<div className="summary-row grand-total">
{(priceIncludingTax && (
Expand All @@ -13,7 +13,7 @@ export function Total({ total, taxAmount, priceIncludingTax }) {
</div>
<div>
<span className="italic">
({_('Inclusive of tax ${taxAmount}', { taxAmount })})
({_('Inclusive of tax ${totalTaxAmount}', { totalTaxAmount })})
</span>
</div>
</div>
Expand All @@ -29,6 +29,6 @@ export function Total({ total, taxAmount, priceIncludingTax }) {

Total.propTypes = {
total: PropTypes.number.isRequired,
taxAmount: PropTypes.number.isRequired,
totalTaxAmount: PropTypes.number.isRequired,
priceIncludingTax: PropTypes.bool.isRequired
};
8 changes: 4 additions & 4 deletions packages/evershop/src/modules/catalog/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ module.exports = () => {
product: {
image: {
thumbnail: {
width: 100.6,
height: 100.5
width: 100,
height: 100
},
listing: {
width: 300.5,
height: 300.5
width: 300,
height: 300
},
single: {
width: 500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ type Cart implements ShoppingCart {
coupon: String
shippingFeeExclTax: Price!
shippingFeeInclTax: Price!
shippingTaxAmount: Price!
discountAmount: Price!
subTotal: Price!
subTotalInclTax: Price!
Expand All @@ -154,6 +155,7 @@ type Cart implements ShoppingCart {
totalWeight: Weight!
taxAmount: Price!
taxAmountBeforeDiscount: Price!
totalTaxAmount: Price!
grandTotal: Price!
shippingMethod: String
shippingMethodName: String
Expand Down
18 changes: 18 additions & 0 deletions packages/evershop/src/modules/checkout/migration/Version-1.0.6.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,22 @@ module.exports = exports = async (connection) => {
connection,
`UPDATE "order" SET sub_total_with_discount_incl_tax = sub_total_with_discount + tax_amount`
);

// Add a column 'total_tax_amount' to the cart table if it does not exist
await execute(
connection,
'ALTER TABLE "cart" ADD COLUMN IF NOT EXISTS "total_tax_amount" decimal(12,4)'
);

// Update the value for the new column 'total_tax_amount' on the cart table get value from the `tax_amount` column
await execute(connection, `UPDATE "cart" SET total_tax_amount = tax_amount`);

// Add a column 'total_tax_amount' to the order table if it does not exist
await execute(
connection,
'ALTER TABLE "order" ADD COLUMN IF NOT EXISTS "total_tax_amount" decimal(12,4)'
);

// Update the value for the new column 'total_tax_amount' on the cart table get value from the `tax_amount` column
await execute(connection, `UPDATE "order" SET total_tax_amount = tax_amount`);
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function Summary({
totalQty,
subTotal,
subTotalInclTax,
taxAmount,
totalTaxAmount,
grandTotal,
coupon,
discountAmount
Expand Down Expand Up @@ -89,7 +89,7 @@ function Summary({
default: priceIncludingTax ? () => null : Tax
},
props: {
amount: taxAmount.text
amount: totalTaxAmount.text
},
sortOrder: 30,
id: 'tax'
Expand All @@ -101,7 +101,7 @@ function Summary({
},
props: {
total: grandTotal.text,
taxAmount: taxAmount.text,
totalTaxAmount: totalTaxAmount.text,
priceIncludingTax
},
sortOrder: 30,
Expand Down Expand Up @@ -129,7 +129,7 @@ Summary.propTypes = {
value: PropTypes.number,
text: PropTypes.string
}),
taxAmount: PropTypes.shape({
totalTaxAmount: PropTypes.shape({
value: PropTypes.number,
text: PropTypes.string
}),
Expand Down Expand Up @@ -172,7 +172,7 @@ export const query = `
text
}

taxAmount {
totalTaxAmount {
value
text
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,69 @@
import React from 'react';
import PropTypes from 'prop-types';
import { toast } from 'react-toastify';
import { Form } from '@components/common/form/Form';
import { Field } from '@components/common/form/Field';
import { useAppDispatch } from '@components/common/context/app';
import { _ } from '@evershop/evershop/src/lib/locale/translate';
import Button from '@components/common/form/Button';

export default function ShippingNote({
setting: { showShippingNote },
cart: { shippingNote, addNoteApi }
}) {
const AppContextDispatch = useAppDispatch();
const [note, setNote] = React.useState(shippingNote);
const [submitting, setSubmitting] = React.useState(false);
return showShippingNote ? (
<div className="shipping-note mt-8">
<Form
id="shippingNoteForm"
action={addNoteApi}
onSuccess={async (response) => {
if (response.error) {
toast.error(response.error.message);
} else {
const url = new URL(window.location.href);
url.searchParams.set('ajax', true);
await AppContextDispatch.fetchPageData(url);
}
}}
>
<Field
name="note"
type="textarea"
value={shippingNote}
placeholder={_('Add a note to your order')}
<div className="form-field-container null">
<div className="field-wrapper flex flex-grow">
<textarea
type="text"
className="form-field"
id="note"
name="note"
placeholder={_('Add a note to your order')}
onChange={(e) => setNote(e.target.value)}
>
{note}
</textarea>
<div className="field-border" />
</div>
</div>
<div className="mt-3">
<Button
title="Save"
variant="primary"
isLoading={submitting}
onAction={() => {
setSubmitting(true);
// Use fetch to send the note to the server
fetch(addNoteApi, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ note }),
credentials: 'include'
})
.then(async (response) => {
if (response.ok) {
const url = new URL(window.location.href);
url.searchParams.set('ajax', true);
await AppContextDispatch.fetchPageData(url);
toast.success(_('Note saved successfully'));
} else {
toast.error(_('Failed to save note'));
}
})
.catch(() => {
toast.error(_('Failed to save note'));
})
.finally(() => {
setSubmitting(false);
});
}}
/>
</Form>
</div>
</div>
) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Summary.propTypes = {
discountAmount: PropTypes.shape({
text: PropTypes.string
}),
taxAmount: PropTypes.shape({
totalTaxAmount: PropTypes.shape({
text: PropTypes.string
}),
shippingFeeInclTax: PropTypes.shape({
Expand Down Expand Up @@ -99,7 +99,7 @@ export const query = `
value
text
}
taxAmount {
totalTaxAmount {
value
text
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Summary.propTypes = {
discountAmount: PropTypes.shape({
text: PropTypes.string
}),
taxAmount: PropTypes.shape({
totalTaxAmount: PropTypes.shape({
text: PropTypes.string
}),
shippingFeeInclTax: PropTypes.shape({
Expand Down Expand Up @@ -96,7 +96,7 @@ export const query = `
value
text
}
taxAmount {
totalTaxAmount {
value
text
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Summary.propTypes = {
subTotalInclTax: PropTypes.shape({
text: PropTypes.string
}),
taxAmount: PropTypes.shape({
totalTaxAmount: PropTypes.shape({
text: PropTypes.string
}),
coupon: PropTypes.string
Expand Down Expand Up @@ -93,7 +93,7 @@ export const query = `
value
text
}
taxAmount {
totalTaxAmount {
value
text
}
Expand Down
Loading
Loading