Skip to content

Commit

Permalink
Add Selling Plan ID to BuyNowButton (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvisockas authored Jun 20, 2024
1 parent 0924410 commit 54c2f7a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/clean-planes-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen-react': minor
---

Add `sellingPlanId` support to `BuyNowButton`.
5 changes: 5 additions & 0 deletions .changeset/red-apes-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': minor
---

Add `sellingPlanId` support to `BuyNowButton`.
2 changes: 2 additions & 0 deletions packages/hydrogen-react/src/BuyNowButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('<BuyNowButton/>', () => {
]}
quantity={4}
variantId="SKU123"
sellingPlanId="1234"
>
Buy now
</BuyNowButton>,
Expand All @@ -70,6 +71,7 @@ describe('<BuyNowButton/>', () => {
{
quantity: 4,
merchandiseId: 'SKU123',
sellingPlanId: '1234',
attributes: [
{key: 'color', value: 'blue'},
{key: 'size', value: 'large'},
Expand Down
6 changes: 5 additions & 1 deletion packages/hydrogen-react/src/BuyNowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface BuyNowButtonPropsBase {
quantity?: number;
/** The ID of the variant. */
variantId: string;
/** The selling plan ID of the subscription variant */
sellingPlanId?: string;
/** An array of cart line attributes that belong to the item being added to the cart. */
attributes?: {
key: string;
Expand All @@ -34,6 +36,7 @@ export function BuyNowButton<AsType extends React.ElementType = 'button'>(
const {
quantity,
variantId,
sellingPlanId,
onClick,
attributes,
children,
Expand All @@ -54,10 +57,11 @@ export function BuyNowButton<AsType extends React.ElementType = 'button'>(
quantity: quantity ?? 1,
merchandiseId: variantId,
attributes,
sellingPlanId,
},
],
});
}, [cartCreate, quantity, variantId, attributes]);
}, [cartCreate, quantity, variantId, attributes, sellingPlanId]);

return (
<BaseButton
Expand Down

0 comments on commit 54c2f7a

Please sign in to comment.