@rebuy/rebuy-hydrogen 2.3.1 → 3.0.0-alpha.1
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 +195 -17
- package/dist/assets/Close.d.ts +2 -0
- package/dist/assets/Close.d.ts.map +1 -0
- 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 +27 -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/defaultSettings.d.ts +3 -0
- package/dist/components/ProductCard/defaultSettings.d.ts.map +1 -0
- package/dist/components/ProductCard/index.d.ts +3 -0
- package/dist/components/ProductCard/index.d.ts.map +1 -0
- package/dist/components/ProductCard/types.d.ts +52 -0
- package/dist/components/ProductCard/types.d.ts.map +1 -0
- package/dist/components/ProductCarousel/ProductCarousel.d.ts +16 -0
- package/dist/components/ProductCarousel/ProductCarousel.d.ts.map +1 -0
- package/dist/components/ProductCarousel/index.d.ts +2 -0
- package/dist/components/ProductCarousel/index.d.ts.map +1 -0
- package/dist/components/ProductPrice/ProductPrice.d.ts +3 -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/ProductPrice/types.d.ts +23 -0
- package/dist/components/ProductPrice/types.d.ts.map +1 -0
- package/dist/components/QuantityInput/QuantityInput.d.ts +3 -0
- package/dist/components/QuantityInput/QuantityInput.d.ts.map +1 -0
- package/dist/components/QuantityInput/index.d.ts +3 -0
- package/dist/components/QuantityInput/index.d.ts.map +1 -0
- package/dist/components/QuantityInput/types.d.ts +7 -0
- package/dist/components/QuantityInput/types.d.ts.map +1 -0
- package/dist/components/Timer/Timer.d.ts +3 -0
- package/dist/components/Timer/Timer.d.ts.map +1 -0
- package/dist/components/Timer/index.d.ts +3 -0
- package/dist/components/Timer/index.d.ts.map +1 -0
- package/dist/components/Timer/types.d.ts +16 -0
- package/dist/components/Timer/types.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 +8 -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 +8 -0
- package/dist/components/VariantSelect/types.d.ts.map +1 -0
- package/dist/constants/api.d.ts +2 -0
- package/dist/constants/api.d.ts.map +1 -0
- package/dist/context/RebuyConfigContext.d.ts +21 -0
- package/dist/context/RebuyConfigContext.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/hooks/useBreakpoint.d.ts +5 -0
- package/dist/hooks/useBreakpoint.d.ts.map +1 -0
- package/dist/hooks/usePopupTrigger.d.ts +3 -0
- package/dist/hooks/usePopupTrigger.d.ts.map +1 -0
- package/dist/hooks/useRebuyTheme.d.ts +21 -0
- package/dist/hooks/useRebuyTheme.d.ts.map +1 -0
- package/dist/index.css +853 -0
- package/dist/index.css.map +7 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3211 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +3178 -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 +8 -0
- package/dist/providers/RebuyHydrogenReactContextProvider.d.ts.map +1 -0
- package/dist/providers/types.d.ts +71 -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 +275 -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 +23 -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/csp.d.ts +16 -0
- package/dist/utils/csp.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/utils/theme.d.ts +20 -0
- package/dist/utils/theme.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/dist/widgets/RebuyWidget/RebuyWidget.d.ts +3 -0
- package/dist/widgets/RebuyWidget/RebuyWidget.d.ts.map +1 -0
- package/dist/widgets/RebuyWidget/WidgetContent.d.ts +3 -0
- package/dist/widgets/RebuyWidget/WidgetContent.d.ts.map +1 -0
- package/dist/widgets/RebuyWidget/index.d.ts +2 -0
- package/dist/widgets/RebuyWidget/index.d.ts.map +1 -0
- package/dist/widgets/RebuyWidget/types.d.ts +335 -0
- package/dist/widgets/RebuyWidget/types.d.ts.map +1 -0
- package/package.json +86 -47
- 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,415 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Image,
|
3
|
-
Link,
|
4
|
-
Money,
|
5
|
-
useCart,
|
6
|
-
useProductOptions,
|
7
|
-
} from '@shopify/hydrogen';
|
8
|
-
import clsx from 'clsx';
|
9
|
-
import { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
|
10
|
-
import { Heading, 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 RebuyProductPrice = ({ selectedVariant = {} }) => {
|
30
|
-
const { priceV2: price, compareAtPriceV2: compareAtPrice } =
|
31
|
-
selectedVariant;
|
32
|
-
|
33
|
-
return (
|
34
|
-
price && (
|
35
|
-
<div className="gap-4">
|
36
|
-
<Text className="flex gap-2">
|
37
|
-
<Money data={price} withoutTrailingZeros as="span" />
|
38
|
-
{isDiscounted(price, compareAtPrice) && (
|
39
|
-
<CompareAtPrice
|
40
|
-
data={compareAtPrice}
|
41
|
-
className={'opacity-50'}
|
42
|
-
/>
|
43
|
-
)}
|
44
|
-
</Text>
|
45
|
-
</div>
|
46
|
-
)
|
47
|
-
);
|
48
|
-
};
|
49
|
-
|
50
|
-
const VariantSelector = ({ product, onSelectVariant, className = '' }) => {
|
51
|
-
const styles = clsx('rounded py-1', className);
|
52
|
-
|
53
|
-
return (
|
54
|
-
product && (
|
55
|
-
<select
|
56
|
-
onChange={(e) => onSelectVariant(product, e.target.value)}
|
57
|
-
aria-label="select variant"
|
58
|
-
className={styles}
|
59
|
-
value={product.selectedVariant.id}
|
60
|
-
>
|
61
|
-
<optgroup label={getOptionsLabel(product)}>
|
62
|
-
{product.variants.nodes.map(({ id, title }) => (
|
63
|
-
<option key={id + '-BundleVariant'} value={id}>
|
64
|
-
{title}
|
65
|
-
</option>
|
66
|
-
))}
|
67
|
-
</optgroup>
|
68
|
-
</select>
|
69
|
-
)
|
70
|
-
);
|
71
|
-
};
|
72
|
-
|
73
|
-
const getOptionsLabel = (product) => {
|
74
|
-
const options = product.variants.nodes[0].selectedOptions;
|
75
|
-
const optionsFromKeys = Object.keys(options[0]);
|
76
|
-
const optionsFromValues = options.map((option) => option.name);
|
77
|
-
const useValues = optionsFromKeys.every((key) =>
|
78
|
-
['name', 'value'].includes(key)
|
79
|
-
);
|
80
|
-
|
81
|
-
// Return delimited label for available option(s) e.g. Color / Size, Scent, etc
|
82
|
-
return (useValues ? optionsFromValues : optionsFromKeys).join(' / ');
|
83
|
-
};
|
84
|
-
|
85
|
-
const AddToCartPriceMarkup = ({ products, addLineItemsToCart }) => {
|
86
|
-
const isDisabled =
|
87
|
-
products.filter((product) => product.selected).length < 1;
|
88
|
-
|
89
|
-
const totalBundlePrice = () => {
|
90
|
-
let total = 0;
|
91
|
-
let currencyCode = 'USD';
|
92
|
-
|
93
|
-
for (const product of products) {
|
94
|
-
if (product.selected && product.selectedVariant) {
|
95
|
-
const { priceV2: price } = product.selectedVariant;
|
96
|
-
|
97
|
-
total += Number(price.amount);
|
98
|
-
currencyCode = price.currencyCode;
|
99
|
-
}
|
100
|
-
}
|
101
|
-
|
102
|
-
return {
|
103
|
-
amount: String(total),
|
104
|
-
currencyCode,
|
105
|
-
};
|
106
|
-
};
|
107
|
-
|
108
|
-
const totalBundleCompareAtPrice = () => {
|
109
|
-
let compareAtTotal = 0;
|
110
|
-
let currencyCode = 'USD';
|
111
|
-
|
112
|
-
for (const product of products) {
|
113
|
-
if (product.selected && product.selectedVariant) {
|
114
|
-
const { priceV2: price, compareAtPriceV2: compareAtPrice } =
|
115
|
-
product.selectedVariant;
|
116
|
-
|
117
|
-
currencyCode = price.currencyCode;
|
118
|
-
compareAtTotal += Number((compareAtPrice || price).amount);
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
return {
|
123
|
-
amount: String(compareAtTotal),
|
124
|
-
currencyCode,
|
125
|
-
};
|
126
|
-
};
|
127
|
-
|
128
|
-
const price = totalBundlePrice();
|
129
|
-
const compareAtPrice = totalBundleCompareAtPrice();
|
130
|
-
|
131
|
-
return (
|
132
|
-
products.length > 0 && (
|
133
|
-
<div className="flex items-center flex-col">
|
134
|
-
{!isDisabled && (
|
135
|
-
<Text className="flex items-center gap-2 mb-2">
|
136
|
-
<span>Total Price:</span>
|
137
|
-
<Money data={price} withoutTrailingZeros as="span" />
|
138
|
-
{isDiscounted(price, compareAtPrice) && (
|
139
|
-
<CompareAtPrice
|
140
|
-
data={compareAtPrice}
|
141
|
-
className={'opacity-50'}
|
142
|
-
/>
|
143
|
-
)}
|
144
|
-
</Text>
|
145
|
-
)}
|
146
|
-
|
147
|
-
<Button
|
148
|
-
as="button"
|
149
|
-
variant={isDisabled ? 'secondary' : 'primary'}
|
150
|
-
disabled={isDisabled}
|
151
|
-
onClick={addLineItemsToCart}
|
152
|
-
>
|
153
|
-
<Text as="span">
|
154
|
-
{isDisabled ? 'Create your bundle below' : 'Add to bag'}
|
155
|
-
</Text>
|
156
|
-
</Button>
|
157
|
-
</div>
|
158
|
-
)
|
159
|
-
);
|
160
|
-
};
|
161
|
-
|
162
|
-
const BundleImages = ({ products }) => {
|
163
|
-
const selected = products.filter((product) => product.selected);
|
164
|
-
|
165
|
-
return (
|
166
|
-
<ul className="flex flex-nowrap justify-center gap-1 mb-4">
|
167
|
-
{products.map((product, index) => {
|
168
|
-
const image = product.selectedVariant.image;
|
169
|
-
const productImage = image ? (
|
170
|
-
<Image
|
171
|
-
className="fadeIn"
|
172
|
-
data={image}
|
173
|
-
alt={image.altText || `Picture of ${product.title}`}
|
174
|
-
title={product.title}
|
175
|
-
width={80}
|
176
|
-
height={80}
|
177
|
-
loaderOptions={{ scale: 2 }}
|
178
|
-
/>
|
179
|
-
) : (
|
180
|
-
// No image defined
|
181
|
-
product.title
|
182
|
-
);
|
183
|
-
// Hide delimiter for first selected item
|
184
|
-
const showDelimiter = selected[0]?.id !== product.id;
|
185
|
-
|
186
|
-
return (
|
187
|
-
<Fragment key={product.id + '-BundleImages-' + index}>
|
188
|
-
{product.selected && (
|
189
|
-
<>
|
190
|
-
{showDelimiter && (
|
191
|
-
<li className="flex items-center">
|
192
|
-
<span className="font-semibold">+</span>
|
193
|
-
</li>
|
194
|
-
)}
|
195
|
-
<li className="flex items-center">
|
196
|
-
{product.default ? (
|
197
|
-
// Already on product page
|
198
|
-
productImage
|
199
|
-
) : (
|
200
|
-
// Link to product
|
201
|
-
<Link
|
202
|
-
to={`/products/${product.handle}`}
|
203
|
-
title={product.title}
|
204
|
-
>
|
205
|
-
{productImage}
|
206
|
-
</Link>
|
207
|
-
)}
|
208
|
-
</li>
|
209
|
-
</>
|
210
|
-
)}
|
211
|
-
</Fragment>
|
212
|
-
);
|
213
|
-
})}
|
214
|
-
</ul>
|
215
|
-
);
|
216
|
-
};
|
217
|
-
|
218
|
-
const BundleSelection = ({ products, onToggleBundleItem, onSelectVariant }) => {
|
219
|
-
return (
|
220
|
-
<ul>
|
221
|
-
{products.map((product, index) => {
|
222
|
-
const bundleItemRowStyle = clsx(
|
223
|
-
'mb-4',
|
224
|
-
!product.selected ? 'opacity-50' : ''
|
225
|
-
);
|
226
|
-
const bundleItemLabelStyle = clsx(
|
227
|
-
'flex flex-row gap-2 mb-1 cursor-pointer'
|
228
|
-
);
|
229
|
-
const { availableForSale } = product.selectedVariant;
|
230
|
-
const isOutOfStock = !availableForSale;
|
231
|
-
|
232
|
-
return (
|
233
|
-
<li
|
234
|
-
key={product.id + '-BundleSelection' + index}
|
235
|
-
className={bundleItemRowStyle}
|
236
|
-
>
|
237
|
-
<div className="flex flex-row items-start gap-2">
|
238
|
-
<input
|
239
|
-
className="mt-1 rounded-sm accent-black cursor-pointer"
|
240
|
-
type="checkbox"
|
241
|
-
value={product.id}
|
242
|
-
id={`${product.id}-toggle`}
|
243
|
-
checked={product.selected && availableForSale}
|
244
|
-
disabled={isOutOfStock}
|
245
|
-
onChange={() => onToggleBundleItem(product)}
|
246
|
-
/>
|
247
|
-
<div className="flex-grow">
|
248
|
-
<label
|
249
|
-
htmlFor={`${product.id}-toggle`}
|
250
|
-
className={bundleItemLabelStyle}
|
251
|
-
>
|
252
|
-
{isOutOfStock && <b>SOLD OUT</b>}
|
253
|
-
{product.default && <b>This item:</b>}
|
254
|
-
{product.title}
|
255
|
-
|
256
|
-
<RebuyProductPrice
|
257
|
-
selectedVariant={
|
258
|
-
product.selectedVariant
|
259
|
-
}
|
260
|
-
/>
|
261
|
-
</label>
|
262
|
-
|
263
|
-
{product.variants?.nodes.length > 1 && (
|
264
|
-
<VariantSelector
|
265
|
-
product={product}
|
266
|
-
onSelectVariant={onSelectVariant}
|
267
|
-
className="w-full"
|
268
|
-
/>
|
269
|
-
)}
|
270
|
-
</div>
|
271
|
-
</div>
|
272
|
-
</li>
|
273
|
-
);
|
274
|
-
})}
|
275
|
-
</ul>
|
276
|
-
);
|
277
|
-
};
|
278
|
-
|
279
|
-
export const RebuyDynamicBundleProducts = ({
|
280
|
-
product = {},
|
281
|
-
products = [],
|
282
|
-
metadata = {},
|
283
|
-
title = 'Frequently purchased together',
|
284
|
-
className = '',
|
285
|
-
}) => {
|
286
|
-
// Hooks
|
287
|
-
const { linesAdd } = useCart();
|
288
|
-
const { selectedVariant } = useProductOptions();
|
289
|
-
|
290
|
-
// State
|
291
|
-
const [bundleProducts, setBundleProduct] = useState([]);
|
292
|
-
const language = metadata.widget?.language ?? {};
|
293
|
-
const componentTitle = language?.title || title;
|
294
|
-
const styles = clsx('grid gap-4 py-6 md:py-8 lg:py-12', className);
|
295
|
-
|
296
|
-
const rebuyAttributes = useMemo(() => {
|
297
|
-
return [
|
298
|
-
{ key: '_source', value: 'Rebuy' },
|
299
|
-
{
|
300
|
-
key: '_attribution',
|
301
|
-
value: 'Rebuy Dynamic Bundle Recommendations',
|
302
|
-
},
|
303
|
-
];
|
304
|
-
}, []);
|
305
|
-
|
306
|
-
// Initializiation
|
307
|
-
useEffect(() => {
|
308
|
-
const formatProducts = (products = []) => {
|
309
|
-
for (let product of products) {
|
310
|
-
product.selectedVariant = { ...product.variants.nodes[0] };
|
311
|
-
product.selected = product.selectedVariant.availableForSale;
|
312
|
-
}
|
313
|
-
|
314
|
-
return products;
|
315
|
-
};
|
316
|
-
|
317
|
-
// Flag the main product (PDP)
|
318
|
-
product.default = true;
|
319
|
-
|
320
|
-
setBundleProduct(formatProducts([product, ...products]));
|
321
|
-
}, [product, products]);
|
322
|
-
|
323
|
-
// Mirror selectedVariant from PDP + allow override
|
324
|
-
useEffect(() => {
|
325
|
-
const bundleWithVariantMatch = (currentBundle) => {
|
326
|
-
for (let product of currentBundle) {
|
327
|
-
if (product.default) {
|
328
|
-
product.selectedVariant = selectedVariant;
|
329
|
-
product.selected = product.selectedVariant.availableForSale;
|
330
|
-
break;
|
331
|
-
}
|
332
|
-
}
|
333
|
-
|
334
|
-
return [...currentBundle];
|
335
|
-
};
|
336
|
-
|
337
|
-
setBundleProduct(bundleWithVariantMatch);
|
338
|
-
}, [selectedVariant]);
|
339
|
-
|
340
|
-
const onToggleBundleItem = useCallback(
|
341
|
-
(product) => {
|
342
|
-
product.selected = !product.selected;
|
343
|
-
|
344
|
-
setBundleProduct([...bundleProducts]);
|
345
|
-
},
|
346
|
-
[bundleProducts]
|
347
|
-
);
|
348
|
-
|
349
|
-
const onSelectVariant = useCallback(
|
350
|
-
(product, variantId) => {
|
351
|
-
const variant = product.variants.nodes.find(
|
352
|
-
({ id }) => id === variantId
|
353
|
-
);
|
354
|
-
|
355
|
-
if (variant) {
|
356
|
-
product.selectedVariant = variant;
|
357
|
-
product.selected = variant.availableForSale;
|
358
|
-
|
359
|
-
setBundleProduct([...bundleProducts]);
|
360
|
-
}
|
361
|
-
},
|
362
|
-
[bundleProducts]
|
363
|
-
);
|
364
|
-
|
365
|
-
const addLineItemsToCart = useCallback(() => {
|
366
|
-
const itemsToAdd = [];
|
367
|
-
|
368
|
-
for (let product of bundleProducts) {
|
369
|
-
if (product.selected && product.selectedVariant) {
|
370
|
-
itemsToAdd.push({
|
371
|
-
quantity: 1,
|
372
|
-
merchandiseId: product.selectedVariant.id,
|
373
|
-
attributes: rebuyAttributes,
|
374
|
-
});
|
375
|
-
}
|
376
|
-
}
|
377
|
-
|
378
|
-
linesAdd(itemsToAdd);
|
379
|
-
}, [bundleProducts, linesAdd, rebuyAttributes]);
|
380
|
-
|
381
|
-
return (
|
382
|
-
bundleProducts.length > 0 && (
|
383
|
-
<div className={styles}>
|
384
|
-
{componentTitle && (
|
385
|
-
<Heading
|
386
|
-
size="lead"
|
387
|
-
width="full"
|
388
|
-
className="px-6 md:px-8 lg:px-12"
|
389
|
-
>
|
390
|
-
{componentTitle}
|
391
|
-
</Heading>
|
392
|
-
)}
|
393
|
-
|
394
|
-
<div className="px-6 md:px-8 lg:px-12">
|
395
|
-
<div className="flex flex-col lg:flex-row mb-4">
|
396
|
-
<BundleImages products={bundleProducts} />
|
397
|
-
|
398
|
-
<AddToCartPriceMarkup
|
399
|
-
addLineItemsToCart={addLineItemsToCart}
|
400
|
-
products={bundleProducts}
|
401
|
-
/>
|
402
|
-
</div>
|
403
|
-
|
404
|
-
<BundleSelection
|
405
|
-
products={bundleProducts}
|
406
|
-
onToggleBundleItem={onToggleBundleItem}
|
407
|
-
onSelectVariant={onSelectVariant}
|
408
|
-
/>
|
409
|
-
</div>
|
410
|
-
</div>
|
411
|
-
)
|
412
|
-
);
|
413
|
-
};
|
414
|
-
|
415
|
-
export default RebuyDynamicBundleProducts;
|
@@ -1,89 +0,0 @@
|
|
1
|
-
import { Image, Link, Money } from '@shopify/hydrogen';
|
2
|
-
import clsx from 'clsx';
|
3
|
-
import { Text } from '~/components';
|
4
|
-
|
5
|
-
const isDiscounted = (price, compareAtPrice) =>
|
6
|
-
Number(compareAtPrice?.amount) > Number(price?.amount);
|
7
|
-
|
8
|
-
const CompareAtPrice = ({ data: compareAtPrice, className }) => {
|
9
|
-
const styles = clsx('strike', className);
|
10
|
-
|
11
|
-
return (
|
12
|
-
<Money
|
13
|
-
withoutTrailingZeros
|
14
|
-
data={compareAtPrice}
|
15
|
-
as="span"
|
16
|
-
className={styles}
|
17
|
-
/>
|
18
|
-
);
|
19
|
-
};
|
20
|
-
|
21
|
-
const RebuyProductPrice = ({ selectedVariant = {} }) => {
|
22
|
-
const { priceV2: price, compareAtPriceV2: compareAtPrice } =
|
23
|
-
selectedVariant;
|
24
|
-
|
25
|
-
return (
|
26
|
-
price && (
|
27
|
-
<div className="gap-4">
|
28
|
-
<Text className="flex gap-2">
|
29
|
-
<Money data={price} withoutTrailingZeros as="span" />
|
30
|
-
{isDiscounted(price, compareAtPrice) && (
|
31
|
-
<CompareAtPrice
|
32
|
-
data={compareAtPrice}
|
33
|
-
className={'opacity-50'}
|
34
|
-
/>
|
35
|
-
)}
|
36
|
-
</Text>
|
37
|
-
</div>
|
38
|
-
)
|
39
|
-
);
|
40
|
-
};
|
41
|
-
|
42
|
-
export const RebuyProductAddOnCard = ({
|
43
|
-
product = {},
|
44
|
-
selectedVariant = product.variants.nodes[0],
|
45
|
-
}) => {
|
46
|
-
if (!selectedVariant) {
|
47
|
-
return null;
|
48
|
-
}
|
49
|
-
|
50
|
-
const { image, availableForSale } = selectedVariant;
|
51
|
-
const isOutOfStock = !availableForSale;
|
52
|
-
|
53
|
-
return (
|
54
|
-
<div className="mb-4 flex">
|
55
|
-
<div className="flex items-center justify-center overflow-hidden mx-auto">
|
56
|
-
{image && (
|
57
|
-
<Image
|
58
|
-
className="fadeIn"
|
59
|
-
data={image}
|
60
|
-
alt={image.altText || `Picture of ${product.title}`}
|
61
|
-
width={80}
|
62
|
-
height={80}
|
63
|
-
loaderOptions={{ scale: 2 }}
|
64
|
-
/>
|
65
|
-
)}
|
66
|
-
{isOutOfStock && (
|
67
|
-
<div className="absolute top-3 left-3 rounded text-xs bg-primary/60 text-contrast py-3 px-4">
|
68
|
-
<Text>Out of stock</Text>
|
69
|
-
</div>
|
70
|
-
)}
|
71
|
-
</div>
|
72
|
-
|
73
|
-
<div className="grid grid-rows-3 ml-3">
|
74
|
-
<Text className="font-medium">{product.title}</Text>
|
75
|
-
|
76
|
-
<RebuyProductPrice selectedVariant={selectedVariant} />
|
77
|
-
|
78
|
-
<Link
|
79
|
-
to={`/products/${product?.handle}`}
|
80
|
-
className="text-xs underline text-primary/50 hover:underline hover:text-primary"
|
81
|
-
>
|
82
|
-
Learn More
|
83
|
-
</Link>
|
84
|
-
</div>
|
85
|
-
</div>
|
86
|
-
);
|
87
|
-
};
|
88
|
-
|
89
|
-
export default RebuyProductAddOnCard;
|