-
Notifications
You must be signed in to change notification settings - Fork 219
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
Conversation
🦋 Changeset detectedLatest commit: 5509362 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
4 Ignored Deployments
|
253404b
to
25cc0a8
Compare
25cc0a8
to
0e3b17c
Compare
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍹 checkout.coupons.at(0)
There was a problem hiding this comment.
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? 📝
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
⚡️🏠 Lighthouse reportLighthouse ran against https://catalyst-latest-gyiyks6mw-bigcommerce-platform.vercel.app 🖥️ DesktopWe ran Lighthouse against the changes on a desktop and produced this report. Here's the summary:
📱 MobileWe ran Lighthouse against the changes on a mobile and produced this report. Here's the summary:
|
What/Why?
Allow applying and removing coupons in cart.
Kapture.2024-04-04.at.13.43.13.mp4
Testing
TBD