Skip to content

Commit

Permalink
Remove deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
wizardlyhel committed Oct 11, 2024
1 parent 54a8824 commit 699e5b6
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 49 deletions.
6 changes: 6 additions & 0 deletions .changeset/modern-suits-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/hydrogen-react': patch
'@shopify/hydrogen': patch
---

Remove deprecated code usage for `priceV2`, `compareAtPriceV2`, and remove export for `getCustomerPrivacy`
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/CartProvider.test.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const CART_LINE: PartialDeep<CartLine, {recurseIntoArrays: true}> = {
merchandise: {
id: 'def',
availableForSale: true,
priceV2: {
price: {
amount: '123',
currencyCode: 'USD',
},
Expand Down
3 changes: 0 additions & 3 deletions packages/hydrogen-react/src/Image.test.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ export function getPreviewImage(image: Partial<ImageType> = {}): PartialDeep<
url: image.url ?? faker.image.imageUrl(),
width: image.width ?? faker.datatype.number(),
height: image.height ?? faker.datatype.number(),
originalSrc: '',
transformedSrc: '',
src: '',
};
}
4 changes: 2 additions & 2 deletions packages/hydrogen-react/src/ProductPrice.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ const Template: Story<ProductPriceProps> = (props) => {
nodes: [
getVariant({
id: '123',
priceV2: {
price: {
currencyCode: 'USD',
amount: '300',
},
compareAtPriceV2: {
compareAtPrice: {
currencyCode: 'USD',
amount: '310',
},
Expand Down
10 changes: 0 additions & 10 deletions packages/hydrogen-react/src/ProductPrice.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ describe('<ProductPrice />', () => {
expect(
screen.getByText(variant?.price?.amount || '', {exact: false}),
).toBeInTheDocument();

expect(
screen.getByText(variant?.priceV2?.amount || '', {exact: false}),
).toBeInTheDocument();
});

it("renders <Money /> with the variant's minimum compareAt price", () => {
Expand Down Expand Up @@ -51,12 +47,6 @@ describe('<ProductPrice />', () => {
exact: false,
}),
).toBeInTheDocument();

expect(
screen.getByText(variant?.compareAtPriceV2?.amount || '', {
exact: false,
}),
).toBeInTheDocument();
});

it('renders <Money /> with unit prices when valueType is `unit`', () => {
Expand Down
21 changes: 3 additions & 18 deletions packages/hydrogen-react/src/ProductPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,20 @@ export function ProductPrice<
) ?? null
: null;

/**
* @deprecated (Next major release) Stop using compareAtPriceV2 and priceV2
*/
const variantPriceProperty =
valueType === 'max' ? 'maxVariantPrice' : 'minVariantPrice';

if (priceType === 'compareAt') {
if (variantId && variant) {
if (variant.compareAtPriceV2) {
console.error(
'<ProductPrice> `compareAtPriceV2` is deprecated. Use `compareAtPrice` instead.',
);
}

price = variant.compareAtPrice ?? variant.compareAtPriceV2;
price = variant.compareAtPrice;
} else {
price = product?.compareAtPriceRange?.[variantPriceProperty];
}

let priceAsNumber: number;
if (variantId && variant) {
priceAsNumber = parseFloat(
variant.price?.amount ?? variant.priceV2?.amount ?? '0',
variant.price?.amount ?? '0',
);
} else {
priceAsNumber = parseFloat(
Expand All @@ -86,13 +77,7 @@ export function ProductPrice<
}
} else {
if (variantId && variant) {
if (variant.priceV2) {
console.error(
'<ProductPrice> `priceV2` is deprecated. Use `price` instead.',
);
}

price = variant.price ?? variant.priceV2;
price = variant.price;
if (valueType === 'unit') {
price = variant.unitPrice;
measurement = variant.unitPriceMeasurement;
Expand Down
20 changes: 9 additions & 11 deletions packages/hydrogen-react/src/ProductProvider.test.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export function getVariant(
variant?.unitPriceMeasurement ?? undefined,
),
price,
priceV2: price,
compareAtPrice,
compareAtPriceV2: compareAtPrice,
selectedOptions: [
{name: faker.random.word(), value: faker.random.word()},
{name: faker.random.word(), value: faker.random.word()},
Expand All @@ -85,7 +83,7 @@ export function getVariant(
};
}

const priceV2: MoneyV2 = {
const price: MoneyV2 = {
amount: '9.99',
currencyCode: 'CAD',
};
Expand All @@ -109,9 +107,9 @@ export const VARIANTS: PartialDeep<
},
],
availableForSale: true,
unitPrice: priceV2,
unitPrice: price,
unitPriceMeasurement: getUnitPriceMeasurement(),
priceV2,
price,
metafields: [],
},
{
Expand All @@ -128,9 +126,9 @@ export const VARIANTS: PartialDeep<
},
],
availableForSale: true,
unitPrice: priceV2,
unitPrice: price,
unitPriceMeasurement: getUnitPriceMeasurement(),
priceV2,
price,
metafields: [],
},
{
Expand All @@ -147,9 +145,9 @@ export const VARIANTS: PartialDeep<
},
],
availableForSale: true,
unitPrice: priceV2,
unitPrice: price,
unitPriceMeasurement: getUnitPriceMeasurement(),
priceV2,
price,
metafields: [],
},
{
Expand All @@ -166,9 +164,9 @@ export const VARIANTS: PartialDeep<
},
],
availableForSale: false,
unitPrice: priceV2,
unitPrice: price,
unitPriceMeasurement: getUnitPriceMeasurement(),
priceV2,
price,
metafields: [],
},
],
Expand Down
4 changes: 0 additions & 4 deletions packages/hydrogen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ export {
type CustomEventMap,
type CustomerPrivacyApiProps,
useCustomerPrivacy,
/*
@deprecated use useAnalytics or useCustomerPrivacy instead
*/
getCustomerPrivacy,
} from './customer-privacy/ShopifyCustomerPrivacy';

export {
Expand Down

0 comments on commit 699e5b6

Please sign in to comment.