@rebuy/rebuy-hydrogen 2.3.1 → 3.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/dist/components/AddToCartBtn/AddToCartBtn.d.ts +3 -0
- package/dist/components/AddToCartBtn/AddToCartBtn.d.ts.map +1 -0
- package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts +3 -0
- package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts.map +1 -0
- package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts +3 -0
- package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts.map +1 -0
- package/dist/components/AddToCartBtn/index.d.ts +2 -0
- package/dist/components/AddToCartBtn/index.d.ts.map +1 -0
- package/dist/components/AddToCartBtn/types.d.ts +26 -0
- package/dist/components/AddToCartBtn/types.d.ts.map +1 -0
- package/dist/components/ProductCard/ProductCard.d.ts +3 -0
- package/dist/components/ProductCard/ProductCard.d.ts.map +1 -0
- package/dist/components/ProductCard/index.d.ts +2 -0
- package/dist/components/ProductCard/index.d.ts.map +1 -0
- package/dist/components/ProductCard/types.d.ts +10 -0
- package/dist/components/ProductCard/types.d.ts.map +1 -0
- package/dist/components/ProductPrice/ProductPrice.d.ts +5 -0
- package/dist/components/ProductPrice/ProductPrice.d.ts.map +1 -0
- package/dist/components/ProductPrice/index.d.ts +2 -0
- package/dist/components/ProductPrice/index.d.ts.map +1 -0
- package/dist/components/Title/Title.d.ts +3 -0
- package/dist/components/Title/Title.d.ts.map +1 -0
- package/dist/components/Title/index.d.ts +2 -0
- package/dist/components/Title/index.d.ts.map +1 -0
- package/dist/components/Title/types.d.ts +7 -0
- package/dist/components/Title/types.d.ts.map +1 -0
- package/dist/components/VariantSelect/VariantSelect.d.ts +3 -0
- package/dist/components/VariantSelect/VariantSelect.d.ts.map +1 -0
- package/dist/components/VariantSelect/index.d.ts +2 -0
- package/dist/components/VariantSelect/index.d.ts.map +1 -0
- package/dist/components/VariantSelect/types.d.ts +6 -0
- package/dist/components/VariantSelect/types.d.ts.map +1 -0
- package/dist/context/RebuyContext.d.ts +6 -0
- package/dist/context/RebuyContext.d.ts.map +1 -0
- package/dist/hooks/titleLevel.d.ts +3 -0
- package/dist/hooks/titleLevel.d.ts.map +1 -0
- package/dist/index.css +296 -0
- package/dist/index.css.map +7 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1967 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +1935 -0
- package/dist/index.mjs.map +7 -0
- package/dist/providers/RebuyHydrogenContextProvider.d.ts +3 -0
- package/dist/providers/RebuyHydrogenContextProvider.d.ts.map +1 -0
- package/dist/providers/RebuyHydrogenReactContextProvider.d.ts +3 -0
- package/dist/providers/RebuyHydrogenReactContextProvider.d.ts.map +1 -0
- package/dist/providers/types.d.ts +54 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/queries/cart.queries.d.ts +5 -0
- package/dist/queries/cart.queries.d.ts.map +1 -0
- package/dist/types/common.d.ts +9 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/rebuyCustom.d.ts +240 -0
- package/dist/types/rebuyCustom.d.ts.map +1 -0
- package/dist/types/rebuySmartCart.d.ts +184 -0
- package/dist/types/rebuySmartCart.d.ts.map +1 -0
- package/dist/types/shopify.d.ts +85 -0
- package/dist/types/shopify.d.ts.map +1 -0
- package/dist/types/widgets.d.ts +22 -0
- package/dist/types/widgets.d.ts.map +1 -0
- package/dist/utils/convertToRebuyProduct.d.ts +156 -0
- package/dist/utils/convertToRebuyProduct.d.ts.map +1 -0
- package/dist/utils/createContextParameters.d.ts +3 -0
- package/dist/utils/createContextParameters.d.ts.map +1 -0
- package/dist/utils/getEncodedAttributes.d.ts +3 -0
- package/dist/utils/getEncodedAttributes.d.ts.map +1 -0
- package/dist/utils/getRebuyConfig.d.ts +3 -0
- package/dist/utils/getRebuyConfig.d.ts.map +1 -0
- package/dist/widgetContainer/RebuyWidgetContainer.d.ts +8 -0
- package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -0
- package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts +3 -0
- package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts.map +1 -0
- package/dist/widgets/RebuyCompleteTheLook/index.d.ts +2 -0
- package/dist/widgets/RebuyCompleteTheLook/index.d.ts.map +1 -0
- package/dist/widgets/RebuyCompleteTheLook/types.d.ts +5 -0
- package/dist/widgets/RebuyCompleteTheLook/types.d.ts.map +1 -0
- package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts +5 -0
- package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts.map +1 -0
- package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts +5 -0
- package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts.map +1 -0
- package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts +3 -0
- package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts.map +1 -0
- package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts +3 -0
- package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts.map +1 -0
- package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts +3 -0
- package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts.map +1 -0
- package/dist/widgets/RebuyDynamicBundleProducts/index.d.ts +2 -0
- package/dist/widgets/RebuyDynamicBundleProducts/index.d.ts.map +1 -0
- package/dist/widgets/RebuyDynamicBundleProducts/types.d.ts +19 -0
- package/dist/widgets/RebuyDynamicBundleProducts/types.d.ts.map +1 -0
- package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts +3 -0
- package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts.map +1 -0
- package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts +3 -0
- package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts.map +1 -0
- package/dist/widgets/RebuyProductAddOns/index.d.ts +2 -0
- package/dist/widgets/RebuyProductAddOns/index.d.ts.map +1 -0
- package/dist/widgets/RebuyProductAddOns/types.d.ts +19 -0
- package/dist/widgets/RebuyProductAddOns/types.d.ts.map +1 -0
- package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts +3 -0
- package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts.map +1 -0
- package/dist/widgets/RebuyProductRecommendations/index.d.ts +2 -0
- package/dist/widgets/RebuyProductRecommendations/index.d.ts.map +1 -0
- package/dist/widgets/RebuyProductRecommendations/types.d.ts +5 -0
- package/dist/widgets/RebuyProductRecommendations/types.d.ts.map +1 -0
- package/package.json +84 -46
- package/RebuyCompleteTheLook.client.jsx +0 -188
- package/RebuyContextProvider.client.jsx +0 -222
- package/RebuyContexts.client.jsx +0 -3
- package/RebuyDynamicBundleProducts.client.jsx +0 -415
- package/RebuyProductAddOnCard.client.jsx +0 -89
- package/RebuyProductAddOns.client.jsx +0 -227
- package/RebuyProductRecommendations.client.jsx +0 -68
- package/RebuyProductViewed.client.jsx +0 -62
- package/RebuyRecentlyViewedProducts.client.jsx +0 -68
- package/RebuyWidgetContainer.client.jsx +0 -136
@@ -1,188 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AddToCartButton,
|
3
|
-
Image,
|
4
|
-
Link,
|
5
|
-
Money,
|
6
|
-
ProductOptionsProvider,
|
7
|
-
} from '@shopify/hydrogen';
|
8
|
-
import clsx from 'clsx';
|
9
|
-
import { useState } from 'react';
|
10
|
-
import { Section, Text } from '~/components';
|
11
|
-
import { Button } from '~/components/elements';
|
12
|
-
|
13
|
-
const isDiscounted = (price, compareAtPrice) =>
|
14
|
-
Number(compareAtPrice?.amount) > Number(price?.amount);
|
15
|
-
|
16
|
-
const CompareAtPrice = ({ data: compareAtPrice, className }) => {
|
17
|
-
const styles = clsx('strike', className);
|
18
|
-
|
19
|
-
return (
|
20
|
-
<Money
|
21
|
-
withoutTrailingZeros
|
22
|
-
data={compareAtPrice}
|
23
|
-
as="span"
|
24
|
-
className={styles}
|
25
|
-
/>
|
26
|
-
);
|
27
|
-
};
|
28
|
-
|
29
|
-
const AddToCartMarkup = ({
|
30
|
-
product,
|
31
|
-
selectedVariant = product.variants.nodes[0],
|
32
|
-
}) => {
|
33
|
-
const isOutOfStock = !selectedVariant.availableForSale;
|
34
|
-
|
35
|
-
return (
|
36
|
-
<AddToCartButton
|
37
|
-
disabled={isOutOfStock}
|
38
|
-
variantId={selectedVariant?.id}
|
39
|
-
quantity={1}
|
40
|
-
accessibleAddingToCartLabel="Adding item to your cart"
|
41
|
-
type="button"
|
42
|
-
attributes={[
|
43
|
-
{ key: '_source', value: 'Rebuy' },
|
44
|
-
{ key: '_attribution', value: 'Rebuy Product Recommendations' },
|
45
|
-
]}
|
46
|
-
>
|
47
|
-
<Button
|
48
|
-
width="full"
|
49
|
-
variant={isOutOfStock ? 'secondary' : 'primary'}
|
50
|
-
as="span"
|
51
|
-
className="px-0"
|
52
|
-
>
|
53
|
-
{isOutOfStock ? 'Out of stock' : 'Add'}
|
54
|
-
</Button>
|
55
|
-
</AddToCartButton>
|
56
|
-
);
|
57
|
-
};
|
58
|
-
|
59
|
-
const RebuyProductPrice = ({ selectedVariant = {} }) => {
|
60
|
-
const { priceV2: price, compareAtPriceV2: compareAtPrice } =
|
61
|
-
selectedVariant;
|
62
|
-
|
63
|
-
return (
|
64
|
-
price && (
|
65
|
-
<div className="gap-4">
|
66
|
-
<Text className="flex gap-2">
|
67
|
-
<Money withoutTrailingZeros data={price} />
|
68
|
-
{isDiscounted(price, compareAtPrice) && (
|
69
|
-
<CompareAtPrice
|
70
|
-
className={'opacity-50'}
|
71
|
-
data={compareAtPrice}
|
72
|
-
/>
|
73
|
-
)}
|
74
|
-
</Text>
|
75
|
-
</div>
|
76
|
-
)
|
77
|
-
);
|
78
|
-
};
|
79
|
-
|
80
|
-
const VariantSelector = ({ product, handleSelectedVariant }) => {
|
81
|
-
return (
|
82
|
-
product?.variants.nodes.length > 1 && (
|
83
|
-
<div className="">
|
84
|
-
<select
|
85
|
-
className="w-full py-1 rounded"
|
86
|
-
name=""
|
87
|
-
onChange={(e) =>
|
88
|
-
handleSelectedVariant(product, e.target.value)
|
89
|
-
}
|
90
|
-
>
|
91
|
-
<optgroup label={getOptionsLabel(product)}>
|
92
|
-
{product.variants.nodes.map(({ id, title }) => (
|
93
|
-
<option key={id + '-variant'} value={id}>
|
94
|
-
{title}
|
95
|
-
</option>
|
96
|
-
))}
|
97
|
-
</optgroup>
|
98
|
-
</select>
|
99
|
-
</div>
|
100
|
-
)
|
101
|
-
);
|
102
|
-
};
|
103
|
-
|
104
|
-
const getOptionsLabel = (product) => {
|
105
|
-
const options = product.variants.nodes[0].selectedOptions;
|
106
|
-
const optionsFromKeys = Object.keys(options[0]);
|
107
|
-
const optionsFromValues = options.map((option) => option.name);
|
108
|
-
const useValues = optionsFromKeys.every((key) =>
|
109
|
-
['name', 'value'].includes(key)
|
110
|
-
);
|
111
|
-
|
112
|
-
// Return delimited label for available option(s) e.g. Color / Size, Scent, etc
|
113
|
-
return (useValues ? optionsFromValues : optionsFromKeys).join(' / ');
|
114
|
-
};
|
115
|
-
|
116
|
-
const RebuyProductCard = ({ product }) => {
|
117
|
-
const [selectedVariant, setSelectedVariant] = useState(
|
118
|
-
product.variants.nodes[0]
|
119
|
-
);
|
120
|
-
const { image } = selectedVariant;
|
121
|
-
const handleSelectedVariant = (product, variant_id) => {
|
122
|
-
const updatedVariant = product.variants.nodes.find(
|
123
|
-
(variant) => variant.id === variant_id
|
124
|
-
);
|
125
|
-
|
126
|
-
setSelectedVariant(updatedVariant);
|
127
|
-
};
|
128
|
-
|
129
|
-
return (
|
130
|
-
<div className="grid grid-cols-2 grid-rows-1 gap-6">
|
131
|
-
<Link to={`/products/${product.handle}`}>
|
132
|
-
{image && (
|
133
|
-
<Image
|
134
|
-
className="w-full object-cover fadeIn"
|
135
|
-
data={image}
|
136
|
-
alt={image.altText || `Picture of ${product.title}`}
|
137
|
-
/>
|
138
|
-
)}
|
139
|
-
</Link>
|
140
|
-
<div className="grid gap-1 items-start">
|
141
|
-
<Link to={`/products/${product.handle}`}>
|
142
|
-
<Text>{product.title}</Text>
|
143
|
-
</Link>
|
144
|
-
<RebuyProductPrice selectedVariant={selectedVariant} />
|
145
|
-
<VariantSelector
|
146
|
-
product={product}
|
147
|
-
handleSelectedVariant={handleSelectedVariant}
|
148
|
-
/>
|
149
|
-
<AddToCartMarkup
|
150
|
-
product={product}
|
151
|
-
selectedVariant={selectedVariant}
|
152
|
-
/>
|
153
|
-
</div>
|
154
|
-
</div>
|
155
|
-
);
|
156
|
-
};
|
157
|
-
|
158
|
-
export const RebuyCompleteTheLook = ({
|
159
|
-
product = {},
|
160
|
-
products = [],
|
161
|
-
// eslint-disable-next-line no-unused-vars
|
162
|
-
metadata = {},
|
163
|
-
title = `These pair with ${product.title}`,
|
164
|
-
className = '',
|
165
|
-
}) => {
|
166
|
-
const styles = clsx('', className);
|
167
|
-
|
168
|
-
return (
|
169
|
-
products.length > 0 && (
|
170
|
-
<Section heading={title} padding="n" className={styles}>
|
171
|
-
<ul className="grid gap-8">
|
172
|
-
{products.map((product) => (
|
173
|
-
<li key={product.id}>
|
174
|
-
<ProductOptionsProvider
|
175
|
-
data={product}
|
176
|
-
initialVariantId={product.variants.nodes[0].id}
|
177
|
-
>
|
178
|
-
<RebuyProductCard product={product} />
|
179
|
-
</ProductOptionsProvider>
|
180
|
-
</li>
|
181
|
-
))}
|
182
|
-
</ul>
|
183
|
-
</Section>
|
184
|
-
)
|
185
|
-
);
|
186
|
-
};
|
187
|
-
|
188
|
-
export default RebuyCompleteTheLook;
|
@@ -1,222 +0,0 @@
|
|
1
|
-
import { RebuyClient } from '@rebuy/rebuy';
|
2
|
-
import { RebuyContext } from '@rebuy/rebuy-hydrogen/RebuyContexts.client';
|
3
|
-
import * as Utilities from '@rebuy/rebuy/utilities';
|
4
|
-
import { useCart, useShop, useUrl } from '@shopify/hydrogen';
|
5
|
-
import { useEffect, useMemo, useState } from 'react';
|
6
|
-
|
7
|
-
const REBUY_API_KEY = import.meta.env.PUBLIC_REBUY_API_KEY;
|
8
|
-
const API = '/api/v1';
|
9
|
-
|
10
|
-
const getEncodedAttributes = (attributes) =>
|
11
|
-
encodeURIComponent(
|
12
|
-
JSON.stringify(
|
13
|
-
attributes.reduce(
|
14
|
-
(merged, { key, value }) => ({ ...merged, [key]: value }),
|
15
|
-
{}
|
16
|
-
)
|
17
|
-
)
|
18
|
-
);
|
19
|
-
|
20
|
-
export const RebuyContextProvider = ({ children }) => {
|
21
|
-
// Shopify
|
22
|
-
const cart = useCart();
|
23
|
-
const shop = useShop();
|
24
|
-
const url = useUrl();
|
25
|
-
|
26
|
-
// Default state
|
27
|
-
const [initialized, setInitialized] = useState(false);
|
28
|
-
const [rebuyConfig, setRebuyConfig] = useState(null);
|
29
|
-
const [config, setConfig] = useState({ shop: null });
|
30
|
-
// const [Rebuy, setRebuy] = useState(null);
|
31
|
-
const queryObject = Utilities.queryStringToObject(url.search);
|
32
|
-
const utmObject = Utilities.utmObjectFromString(url);
|
33
|
-
|
34
|
-
if (utmObject != null) {
|
35
|
-
for (const key in utmObject) {
|
36
|
-
url.searchParams.set(key, utmObject[key]);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
// Initialization
|
41
|
-
useEffect(() => {
|
42
|
-
const getRebuyConfig = async () => {
|
43
|
-
try {
|
44
|
-
const request = {
|
45
|
-
url: `${API}/user/config`,
|
46
|
-
parameters: { shop: shop.storeDomain },
|
47
|
-
};
|
48
|
-
|
49
|
-
const { data: rebuy, ...response } = await new RebuyClient(
|
50
|
-
REBUY_API_KEY
|
51
|
-
).getShieldedAsset(request.url, request.parameters);
|
52
|
-
|
53
|
-
// Missing Rebuy shop data?
|
54
|
-
if (!rebuy?.shop) {
|
55
|
-
throw new Error(
|
56
|
-
'Rebuy configuration is not properly set up - missing shop',
|
57
|
-
{ cause: response }
|
58
|
-
);
|
59
|
-
}
|
60
|
-
|
61
|
-
setRebuyConfig(rebuy);
|
62
|
-
} catch (err) {
|
63
|
-
console.warn('Error fetching Rebuy shop config');
|
64
|
-
console.error(err, err.cause);
|
65
|
-
}
|
66
|
-
};
|
67
|
-
|
68
|
-
const onBeforeReady = async () => {
|
69
|
-
// Initializing...
|
70
|
-
if (!rebuyConfig?.shop) {
|
71
|
-
return await getRebuyConfig();
|
72
|
-
}
|
73
|
-
};
|
74
|
-
|
75
|
-
onBeforeReady();
|
76
|
-
}, [rebuyConfig, shop]);
|
77
|
-
|
78
|
-
useEffect(() => {
|
79
|
-
const applyConfig = async () => {
|
80
|
-
// Still fetching Rebuy config OR config already applied. Abort!
|
81
|
-
if (!rebuyConfig || config.shop) return;
|
82
|
-
|
83
|
-
// Bring it all together
|
84
|
-
const appConfig = { ...config, ...rebuyConfig };
|
85
|
-
|
86
|
-
setConfig(appConfig);
|
87
|
-
};
|
88
|
-
|
89
|
-
applyConfig();
|
90
|
-
}, [config, rebuyConfig]);
|
91
|
-
|
92
|
-
useEffect(() => {
|
93
|
-
const onReady = () => {
|
94
|
-
// Still initializing... Abort!
|
95
|
-
if (!config.shop) return;
|
96
|
-
|
97
|
-
// Initialized!
|
98
|
-
setInitialized(true);
|
99
|
-
// const { api_key, cache_key } = config.shop;
|
100
|
-
// setRebuy(new RebuyClient(api_key, { cache_key }));
|
101
|
-
};
|
102
|
-
|
103
|
-
onReady();
|
104
|
-
}, [config]);
|
105
|
-
|
106
|
-
const contextParameters = useMemo(() => {
|
107
|
-
// Still initializing... Abort!
|
108
|
-
if (!config.shop) return null;
|
109
|
-
|
110
|
-
const { cache_key } = config.shop;
|
111
|
-
const contextParameters = {
|
112
|
-
url: url.href,
|
113
|
-
cache_key,
|
114
|
-
};
|
115
|
-
// Cart object
|
116
|
-
const cartContext = {};
|
117
|
-
|
118
|
-
// Set time
|
119
|
-
if (Object.prototype.hasOwnProperty.call(queryObject, 'time')) {
|
120
|
-
contextParameters.time = queryObject.time;
|
121
|
-
}
|
122
|
-
|
123
|
-
// Set Cart: token
|
124
|
-
if (cart.id) {
|
125
|
-
cartContext.token = Utilities.getIdFromGraphUrl(cart.id, 'Cart');
|
126
|
-
contextParameters.cart_token = Utilities.getIdFromGraphUrl(
|
127
|
-
cart.id,
|
128
|
-
'Cart'
|
129
|
-
);
|
130
|
-
}
|
131
|
-
|
132
|
-
// Set Cart: subtotal
|
133
|
-
if (cart.cost?.subtotalAmount?.amount) {
|
134
|
-
const { amount } = cart.cost.subtotalAmount;
|
135
|
-
|
136
|
-
cartContext.subtotal = Utilities.amountToCents(amount);
|
137
|
-
contextParameters.cart_subtotal = Utilities.amountToCents(amount);
|
138
|
-
}
|
139
|
-
|
140
|
-
// Set Cart: line count
|
141
|
-
if (typeof cart.lines != 'undefined') {
|
142
|
-
const totalLines = cart.lines.length;
|
143
|
-
|
144
|
-
cartContext.line_count = totalLines;
|
145
|
-
contextParameters.cart_count = totalLines;
|
146
|
-
contextParameters.cart_line_count = totalLines;
|
147
|
-
}
|
148
|
-
|
149
|
-
// Set Cart: item count
|
150
|
-
if (typeof cart.totalQuantity != 'undefined') {
|
151
|
-
const { totalQuantity } = cart;
|
152
|
-
|
153
|
-
cartContext.item_count = totalQuantity;
|
154
|
-
contextParameters.cart_item_count = totalQuantity;
|
155
|
-
}
|
156
|
-
|
157
|
-
// Set Cart: line items
|
158
|
-
if (typeof cart.lines != 'undefined') {
|
159
|
-
cartContext.items = [];
|
160
|
-
|
161
|
-
for (const cartItem of cart.lines) {
|
162
|
-
const item = {
|
163
|
-
quantity: cartItem.quantity,
|
164
|
-
};
|
165
|
-
|
166
|
-
if (cartItem.product?.id) {
|
167
|
-
item.product_id = Utilities.getIdFromGraphUrl(
|
168
|
-
cartItem.product.id,
|
169
|
-
'Product'
|
170
|
-
);
|
171
|
-
}
|
172
|
-
|
173
|
-
if (cartItem.merchandise?.id) {
|
174
|
-
item.variant_id = Utilities.getIdFromGraphUrl(
|
175
|
-
cartItem.merchandise.id,
|
176
|
-
'ProductVariant'
|
177
|
-
);
|
178
|
-
}
|
179
|
-
|
180
|
-
if (cartItem.attributes) {
|
181
|
-
item.properties = getEncodedAttributes(cartItem.attributes);
|
182
|
-
}
|
183
|
-
|
184
|
-
// TBD: item.selling_plan
|
185
|
-
|
186
|
-
cartContext.items.push(item);
|
187
|
-
}
|
188
|
-
}
|
189
|
-
|
190
|
-
// Set Cart: attributes
|
191
|
-
if (cart.attributes) {
|
192
|
-
cartContext.attributes = getEncodedAttributes(cart.attributes);
|
193
|
-
}
|
194
|
-
|
195
|
-
// Set Cart: notes
|
196
|
-
if (cart.note) {
|
197
|
-
cartContext.note = cart.note;
|
198
|
-
}
|
199
|
-
|
200
|
-
// Set cart
|
201
|
-
contextParameters.cart = cartContext;
|
202
|
-
|
203
|
-
return contextParameters;
|
204
|
-
}, [cart, config, queryObject, url]);
|
205
|
-
|
206
|
-
// Static reference (JSON) + memoization
|
207
|
-
// ^ prevent re-rendering children when context params are unchanged
|
208
|
-
const contextParametersJSON = JSON.stringify(contextParameters);
|
209
|
-
const contextValue = useMemo(
|
210
|
-
() => ({ contextParameters: JSON.parse(contextParametersJSON) }),
|
211
|
-
[contextParametersJSON]
|
212
|
-
);
|
213
|
-
|
214
|
-
// Still initializing...
|
215
|
-
if (!initialized) return null;
|
216
|
-
|
217
|
-
return (
|
218
|
-
<RebuyContext.Provider value={contextValue}>
|
219
|
-
{children}
|
220
|
-
</RebuyContext.Provider>
|
221
|
-
);
|
222
|
-
};
|
package/RebuyContexts.client.jsx
DELETED