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

feat(core): allow applying coupons to cart #733

Merged
merged 7 commits into from
Apr 5, 2024
Merged

Conversation

jorgemoya
Copy link
Contributor

What/Why?

Allow applying and removing coupons in cart.

Kapture.2024-04-04.at.13.43.13.mp4

Testing

TBD

Copy link

changeset-bot bot commented Apr 4, 2024

🦋 Changeset detected

Latest commit: 5509362

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
catalyst-latest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 5, 2024 5:04pm
catalyst-testbed ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 5, 2024 5:04pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
catalyst-1millionproducts-store ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2024 5:04pm
catalyst-au ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2024 5:04pm
catalyst-storybook ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2024 5:04pm
catalyst-uk ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2024 5:04pm

Copy link
Contributor

Choose a reason for hiding this comment

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

👏

couponCode: z.string(),
});

export async function applyCouponCode(formData: FormData, checkoutEntityId: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🍹 Could we embed the checkoutEntityId in a hidden input and read it from fromData? Or is it a secret we don't want to expose to the client?

Copy link
Contributor Author

@jorgemoya jorgemoya Apr 5, 2024

Choose a reason for hiding this comment

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

Funnily enough, that is how I originally implemented this. I dont think it's a secret, I believe it is the same as the cart id (I could be wrong). I can revert.

const t = useTranslations('Cart.CheckoutSummary');
const [showAddCoupon, setShowAddCoupon] = useState(false);
const [selectedCoupon, setSelectedCoupon] = useState<Checkout['coupons'][number] | null>(
checkout.coupons[0] || null,
Copy link
Contributor

Choose a reason for hiding this comment

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

🍹 checkout.coupons.at(0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you explain the benefit of this? 📝

Copy link
Contributor

Choose a reason for hiding this comment

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

It's mostly beneficial for retrieving the last item in an array, as you can do arr.at(-1) instead of arr[arr.length - 1]. Again, it's a 🍹, mostly just trying to push towards accessing array indexes via that method.

checkout.coupons[0] || null,
);

const currencyFormatter = new Intl.NumberFormat('en-US', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way we can read the local from the page request?

Copy link
Contributor Author

@jorgemoya jorgemoya Apr 5, 2024

Choose a reason for hiding this comment

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

There are several instances of this so I think it might be best to tackle in a different PR.

@@ -63,6 +63,7 @@ export const ShippingEstimator = ({
<span>{currencyFormatter.format(checkout.shippingCostTotal?.value || 0)}</span>
) : (
<Button
aria-controls="shipping-options"
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Contributor

github-actions bot commented Apr 5, 2024

⚡️🏠 Lighthouse report

Lighthouse ran against https://catalyst-latest-gyiyks6mw-bigcommerce-platform.vercel.app

🖥️ Desktop

We ran Lighthouse against the changes on a desktop and produced this report. Here's the summary:

Category Score
🟢 Performance 100
🟢 Accessibility 100
🟠 Best practices 78
🟢 SEO 90

📱 Mobile

We ran Lighthouse against the changes on a mobile and produced this report. Here's the summary:

Category Score
🟢 Performance 98
🟢 Accessibility 100
🟠 Best practices 78
🟢 SEO 92

@jorgemoya jorgemoya added this pull request to the merge queue Apr 5, 2024
Merged via the queue into main with commit 565e871 Apr 5, 2024
15 checks passed
@jorgemoya jorgemoya deleted the add-coupon-code branch April 5, 2024 18:12
@github-actions github-actions bot mentioned this pull request Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants