@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
package/dist/index.mjs
ADDED
@@ -0,0 +1,1935 @@
|
|
1
|
+
// src/providers/RebuyHydrogenContextProvider.tsx
|
2
|
+
import * as Utilities2 from "@rebuy/rebuy/utilities";
|
3
|
+
import { Await, useLocation } from "@remix-run/react";
|
4
|
+
import { useEffect, useMemo, useState } from "react";
|
5
|
+
|
6
|
+
// src/context/RebuyContext.tsx
|
7
|
+
import { createContext } from "react";
|
8
|
+
var RebuyContext = createContext(null);
|
9
|
+
|
10
|
+
// src/utils/createContextParameters.ts
|
11
|
+
import * as Utilities from "@rebuy/rebuy/utilities";
|
12
|
+
|
13
|
+
// src/utils/getEncodedAttributes.ts
|
14
|
+
var getEncodedAttributes = (attributes) => encodeURIComponent(
|
15
|
+
JSON.stringify(attributes.reduce((merged, { key, value }) => ({ ...merged, [key]: value }), {}))
|
16
|
+
);
|
17
|
+
|
18
|
+
// src/utils/createContextParameters.ts
|
19
|
+
var createContextParameters = ({
|
20
|
+
cacheKey,
|
21
|
+
cartAttributes,
|
22
|
+
cartId,
|
23
|
+
cartLines,
|
24
|
+
cartLinesLength,
|
25
|
+
cartNote,
|
26
|
+
cartSubtotal,
|
27
|
+
cartTotalQuantity,
|
28
|
+
isHydrogenReact,
|
29
|
+
queryObject,
|
30
|
+
windowUrl
|
31
|
+
}) => {
|
32
|
+
const contextParameters = {
|
33
|
+
cache_key: cacheKey,
|
34
|
+
cart_count: 0,
|
35
|
+
cart_item_count: 0,
|
36
|
+
cart_line_count: 0,
|
37
|
+
cart_subtotal: 0,
|
38
|
+
isHydrogenReact,
|
39
|
+
time: "",
|
40
|
+
url: windowUrl
|
41
|
+
};
|
42
|
+
const cartContext = {
|
43
|
+
attributes: "",
|
44
|
+
item_count: 0,
|
45
|
+
items: [],
|
46
|
+
line_count: 0,
|
47
|
+
note: "",
|
48
|
+
subtotal: 0,
|
49
|
+
token: ""
|
50
|
+
};
|
51
|
+
if (Object.prototype.hasOwnProperty.call(queryObject, "time")) {
|
52
|
+
contextParameters.time = queryObject.time;
|
53
|
+
}
|
54
|
+
if (cartId) {
|
55
|
+
cartContext.token = Utilities.getIdFromGraphUrl(cartId, "Cart");
|
56
|
+
contextParameters.cart_token = Utilities.getIdFromGraphUrl(cartId, "Cart");
|
57
|
+
}
|
58
|
+
if (cartSubtotal) {
|
59
|
+
cartContext.subtotal = Utilities.amountToCents(parseFloat(cartSubtotal));
|
60
|
+
contextParameters.cart_subtotal = Utilities.amountToCents(parseFloat(cartSubtotal));
|
61
|
+
}
|
62
|
+
if (cartLinesLength) {
|
63
|
+
const totalLines = cartLinesLength;
|
64
|
+
cartContext.line_count = totalLines;
|
65
|
+
contextParameters.cart_count = totalLines;
|
66
|
+
contextParameters.cart_line_count = totalLines;
|
67
|
+
}
|
68
|
+
if (cartTotalQuantity) {
|
69
|
+
cartContext.item_count = cartTotalQuantity;
|
70
|
+
contextParameters.cart_item_count = cartTotalQuantity;
|
71
|
+
}
|
72
|
+
if (cartLines) {
|
73
|
+
cartContext.items = [];
|
74
|
+
for (const cartItem of cartLines) {
|
75
|
+
const item = {
|
76
|
+
attributes: [],
|
77
|
+
product_id: "",
|
78
|
+
properties: "",
|
79
|
+
quantity: cartItem?.quantity,
|
80
|
+
variant_id: ""
|
81
|
+
};
|
82
|
+
if (cartItem?.merchandise?.product?.id) {
|
83
|
+
item.product_id = Utilities.getIdFromGraphUrl(cartItem.merchandise.product.id, "Product");
|
84
|
+
}
|
85
|
+
if (cartItem?.merchandise?.id) {
|
86
|
+
item.variant_id = Utilities.getIdFromGraphUrl(cartItem.merchandise.id, "ProductVariant");
|
87
|
+
}
|
88
|
+
if (cartItem?.attributes?.length) {
|
89
|
+
const validAttributes = cartItem.attributes.filter(
|
90
|
+
(attr) => attr !== void 0 && typeof attr.key === "string" && typeof attr.value === "string"
|
91
|
+
);
|
92
|
+
item.properties = getEncodedAttributes(validAttributes);
|
93
|
+
}
|
94
|
+
cartContext.items.push(item);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
if (cartAttributes) {
|
98
|
+
const validAttributes = cartAttributes.filter(
|
99
|
+
(attr) => attr !== void 0 && typeof attr.key === "string" && typeof attr.value === "string"
|
100
|
+
);
|
101
|
+
cartContext.attributes = getEncodedAttributes(validAttributes);
|
102
|
+
}
|
103
|
+
if (cartNote) {
|
104
|
+
cartContext.note = cartNote;
|
105
|
+
}
|
106
|
+
contextParameters.cart = cartContext;
|
107
|
+
return contextParameters;
|
108
|
+
};
|
109
|
+
|
110
|
+
// src/utils/getRebuyConfig.ts
|
111
|
+
import { RebuyClient } from "@rebuy/rebuy";
|
112
|
+
var getRebuyConfig = async (storeDomain) => {
|
113
|
+
try {
|
114
|
+
const request = {
|
115
|
+
parameters: { shop: storeDomain },
|
116
|
+
url: `/api/v1/user/config`
|
117
|
+
};
|
118
|
+
const { data: rebuy, ...response } = await new RebuyClient(void 0, void 0, storeDomain).getShieldedAsset(
|
119
|
+
request.url,
|
120
|
+
request.parameters
|
121
|
+
);
|
122
|
+
if (!rebuy?.shop) {
|
123
|
+
throw new Error("Rebuy configuration is not properly set up - missing shop", { cause: response });
|
124
|
+
}
|
125
|
+
return rebuy;
|
126
|
+
} catch (error) {
|
127
|
+
const err = error;
|
128
|
+
console.warn("Error fetching Rebuy shop config");
|
129
|
+
console.error(err, err.cause);
|
130
|
+
throw err;
|
131
|
+
}
|
132
|
+
};
|
133
|
+
|
134
|
+
// src/providers/RebuyHydrogenContextProvider.tsx
|
135
|
+
import { jsx } from "react/jsx-runtime";
|
136
|
+
var RebuyHydrogenContext = ({
|
137
|
+
apiKey,
|
138
|
+
cartAttributes,
|
139
|
+
cartCost,
|
140
|
+
cartId,
|
141
|
+
cartLines,
|
142
|
+
cartNote,
|
143
|
+
cartQuantity,
|
144
|
+
children,
|
145
|
+
publicStoreDomain,
|
146
|
+
shop
|
147
|
+
}) => {
|
148
|
+
const [rebuyConfig, setRebuyConfig] = useState(null);
|
149
|
+
const location = useLocation();
|
150
|
+
const queryObject = Utilities2.queryStringToObject(location.search);
|
151
|
+
const windowUrl = `${shop}${location.pathname}${location.search}`;
|
152
|
+
useEffect(() => {
|
153
|
+
const initConfig = async () => {
|
154
|
+
const config = await getRebuyConfig(publicStoreDomain);
|
155
|
+
setRebuyConfig(config);
|
156
|
+
};
|
157
|
+
if (!rebuyConfig?.shop) {
|
158
|
+
initConfig();
|
159
|
+
}
|
160
|
+
}, [rebuyConfig]);
|
161
|
+
const contextParameters = useMemo(
|
162
|
+
() => createContextParameters({
|
163
|
+
cacheKey: rebuyConfig?.shop?.cache_key,
|
164
|
+
cartAttributes,
|
165
|
+
cartId,
|
166
|
+
cartLines,
|
167
|
+
cartLinesLength: cartLines?.length,
|
168
|
+
cartNote,
|
169
|
+
cartSubtotal: cartCost,
|
170
|
+
cartTotalQuantity: cartQuantity,
|
171
|
+
isHydrogenReact: false,
|
172
|
+
queryObject,
|
173
|
+
windowUrl
|
174
|
+
}),
|
175
|
+
[rebuyConfig, windowUrl, queryObject, cartAttributes, cartCost, cartId, cartLines, cartQuantity, cartNote]
|
176
|
+
);
|
177
|
+
const contextParametersJSON = JSON.stringify(contextParameters);
|
178
|
+
const contextValue = useMemo(
|
179
|
+
() => ({ contextParameters: JSON.parse(contextParametersJSON) }),
|
180
|
+
[contextParametersJSON]
|
181
|
+
);
|
182
|
+
return /* @__PURE__ */ jsx(RebuyContext.Provider, { value: contextValue, children });
|
183
|
+
};
|
184
|
+
var RebuyHydrogenContextProvider = ({
|
185
|
+
apiKey,
|
186
|
+
cart,
|
187
|
+
children,
|
188
|
+
publicStoreDomain,
|
189
|
+
shop
|
190
|
+
}) => {
|
191
|
+
return /* @__PURE__ */ jsx(Await, { resolve: cart, children: (resolvedCart) => {
|
192
|
+
const cart2 = resolvedCart;
|
193
|
+
return /* @__PURE__ */ jsx(
|
194
|
+
RebuyHydrogenContext,
|
195
|
+
{
|
196
|
+
apiKey,
|
197
|
+
cartAttributes: cart2?.attributes,
|
198
|
+
cartCost: cart2?.cost?.subtotalAmount?.amount,
|
199
|
+
cartId: cart2?.id,
|
200
|
+
cartLines: cart2?.lines?.nodes,
|
201
|
+
cartNote: cart2?.note,
|
202
|
+
cartQuantity: cart2?.totalQuantity,
|
203
|
+
publicStoreDomain,
|
204
|
+
shop,
|
205
|
+
children
|
206
|
+
}
|
207
|
+
);
|
208
|
+
} });
|
209
|
+
};
|
210
|
+
|
211
|
+
// src/providers/RebuyHydrogenReactContextProvider.tsx
|
212
|
+
import * as Utilities3 from "@rebuy/rebuy/utilities";
|
213
|
+
import { useLocation as useLocation2 } from "@remix-run/react";
|
214
|
+
import { CartProvider, ShopifyProvider, useCart } from "@shopify/hydrogen-react";
|
215
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
216
|
+
|
217
|
+
// src/queries/cart.queries.ts
|
218
|
+
var OPTION_FRAGMENT = `#graphql
|
219
|
+
fragment OptionFragment on ProductOption {
|
220
|
+
id
|
221
|
+
name
|
222
|
+
optionValues {
|
223
|
+
id
|
224
|
+
name
|
225
|
+
swatch {
|
226
|
+
color
|
227
|
+
image {
|
228
|
+
mediaContentType
|
229
|
+
previewImage {
|
230
|
+
height
|
231
|
+
id
|
232
|
+
url
|
233
|
+
width
|
234
|
+
altText
|
235
|
+
}
|
236
|
+
id
|
237
|
+
alt
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}
|
242
|
+
`;
|
243
|
+
var CART_LINE_FRAGMENT = `#graphql
|
244
|
+
fragment CartLineFragment on CartLine {
|
245
|
+
id
|
246
|
+
quantity
|
247
|
+
cost {
|
248
|
+
amountPerQuantity {
|
249
|
+
amount
|
250
|
+
currencyCode
|
251
|
+
}
|
252
|
+
compareAtAmountPerQuantity {
|
253
|
+
amount
|
254
|
+
currencyCode
|
255
|
+
}
|
256
|
+
totalAmount {
|
257
|
+
amount
|
258
|
+
currencyCode
|
259
|
+
}
|
260
|
+
subtotalAmount {
|
261
|
+
amount
|
262
|
+
currencyCode
|
263
|
+
}
|
264
|
+
}
|
265
|
+
attributes {
|
266
|
+
key
|
267
|
+
value
|
268
|
+
}
|
269
|
+
discountAllocations {
|
270
|
+
discountedAmount {
|
271
|
+
amount
|
272
|
+
currencyCode
|
273
|
+
}
|
274
|
+
... on CartAutomaticDiscountAllocation {
|
275
|
+
__typename
|
276
|
+
discountedAmount {
|
277
|
+
amount
|
278
|
+
currencyCode
|
279
|
+
}
|
280
|
+
title
|
281
|
+
}
|
282
|
+
... on CartCodeDiscountAllocation {
|
283
|
+
__typename
|
284
|
+
code
|
285
|
+
discountedAmount {
|
286
|
+
amount
|
287
|
+
currencyCode
|
288
|
+
}
|
289
|
+
}
|
290
|
+
... on CartCustomDiscountAllocation {
|
291
|
+
__typename
|
292
|
+
discountedAmount {
|
293
|
+
amount
|
294
|
+
currencyCode
|
295
|
+
}
|
296
|
+
title
|
297
|
+
}
|
298
|
+
}
|
299
|
+
merchandise {
|
300
|
+
... on ProductVariant {
|
301
|
+
availableForSale
|
302
|
+
id
|
303
|
+
sku
|
304
|
+
title
|
305
|
+
compareAtPrice {
|
306
|
+
amount
|
307
|
+
currencyCode
|
308
|
+
}
|
309
|
+
image {
|
310
|
+
altText
|
311
|
+
height
|
312
|
+
id
|
313
|
+
url
|
314
|
+
width
|
315
|
+
}
|
316
|
+
price {
|
317
|
+
amount
|
318
|
+
currencyCode
|
319
|
+
}
|
320
|
+
product {
|
321
|
+
handle
|
322
|
+
id
|
323
|
+
productType
|
324
|
+
tags
|
325
|
+
title
|
326
|
+
vendor
|
327
|
+
collections(first: 10) {
|
328
|
+
nodes {
|
329
|
+
handle
|
330
|
+
}
|
331
|
+
}
|
332
|
+
options {
|
333
|
+
...OptionFragment
|
334
|
+
}
|
335
|
+
images(first: 20) {
|
336
|
+
nodes {
|
337
|
+
altText
|
338
|
+
height
|
339
|
+
id
|
340
|
+
url
|
341
|
+
width
|
342
|
+
}
|
343
|
+
}
|
344
|
+
}
|
345
|
+
selectedOptions {
|
346
|
+
name
|
347
|
+
value
|
348
|
+
}
|
349
|
+
}
|
350
|
+
}
|
351
|
+
}
|
352
|
+
`;
|
353
|
+
var CART_LINE_COMPONENT_FRAGMENT = `#graphql
|
354
|
+
fragment CartLineComponentFragment on ComponentizableCartLine {
|
355
|
+
id
|
356
|
+
quantity
|
357
|
+
cost {
|
358
|
+
amountPerQuantity {
|
359
|
+
amount
|
360
|
+
currencyCode
|
361
|
+
}
|
362
|
+
compareAtAmountPerQuantity {
|
363
|
+
amount
|
364
|
+
currencyCode
|
365
|
+
}
|
366
|
+
totalAmount {
|
367
|
+
amount
|
368
|
+
currencyCode
|
369
|
+
}
|
370
|
+
subtotalAmount {
|
371
|
+
amount
|
372
|
+
currencyCode
|
373
|
+
}
|
374
|
+
}
|
375
|
+
attributes {
|
376
|
+
key
|
377
|
+
value
|
378
|
+
}
|
379
|
+
discountAllocations {
|
380
|
+
discountedAmount {
|
381
|
+
amount
|
382
|
+
currencyCode
|
383
|
+
}
|
384
|
+
... on CartAutomaticDiscountAllocation {
|
385
|
+
__typename
|
386
|
+
discountedAmount {
|
387
|
+
amount
|
388
|
+
currencyCode
|
389
|
+
}
|
390
|
+
title
|
391
|
+
}
|
392
|
+
... on CartCodeDiscountAllocation {
|
393
|
+
__typename
|
394
|
+
code
|
395
|
+
discountedAmount {
|
396
|
+
amount
|
397
|
+
currencyCode
|
398
|
+
}
|
399
|
+
}
|
400
|
+
... on CartCustomDiscountAllocation {
|
401
|
+
__typename
|
402
|
+
discountedAmount {
|
403
|
+
amount
|
404
|
+
currencyCode
|
405
|
+
}
|
406
|
+
title
|
407
|
+
}
|
408
|
+
}
|
409
|
+
merchandise {
|
410
|
+
... on ProductVariant {
|
411
|
+
availableForSale
|
412
|
+
id
|
413
|
+
sku
|
414
|
+
title
|
415
|
+
compareAtPrice {
|
416
|
+
amount
|
417
|
+
currencyCode
|
418
|
+
}
|
419
|
+
image {
|
420
|
+
altText
|
421
|
+
height
|
422
|
+
id
|
423
|
+
url
|
424
|
+
width
|
425
|
+
}
|
426
|
+
price {
|
427
|
+
amount
|
428
|
+
currencyCode
|
429
|
+
}
|
430
|
+
product {
|
431
|
+
handle
|
432
|
+
id
|
433
|
+
productType
|
434
|
+
tags
|
435
|
+
title
|
436
|
+
vendor
|
437
|
+
collections(first: 10) {
|
438
|
+
nodes {
|
439
|
+
handle
|
440
|
+
}
|
441
|
+
}
|
442
|
+
options {
|
443
|
+
id
|
444
|
+
name
|
445
|
+
optionValues {
|
446
|
+
id
|
447
|
+
name
|
448
|
+
swatch {
|
449
|
+
color
|
450
|
+
image {
|
451
|
+
mediaContentType
|
452
|
+
previewImage {
|
453
|
+
height
|
454
|
+
id
|
455
|
+
url
|
456
|
+
width
|
457
|
+
altText
|
458
|
+
}
|
459
|
+
id
|
460
|
+
alt
|
461
|
+
}
|
462
|
+
}
|
463
|
+
}
|
464
|
+
}
|
465
|
+
images(first: 20) {
|
466
|
+
nodes {
|
467
|
+
altText
|
468
|
+
height
|
469
|
+
id
|
470
|
+
url
|
471
|
+
width
|
472
|
+
}
|
473
|
+
}
|
474
|
+
}
|
475
|
+
selectedOptions {
|
476
|
+
name
|
477
|
+
value
|
478
|
+
}
|
479
|
+
}
|
480
|
+
}
|
481
|
+
lineComponents {
|
482
|
+
id
|
483
|
+
quantity
|
484
|
+
cost {
|
485
|
+
amountPerQuantity {
|
486
|
+
amount
|
487
|
+
currencyCode
|
488
|
+
}
|
489
|
+
compareAtAmountPerQuantity {
|
490
|
+
amount
|
491
|
+
currencyCode
|
492
|
+
}
|
493
|
+
totalAmount {
|
494
|
+
amount
|
495
|
+
currencyCode
|
496
|
+
}
|
497
|
+
subtotalAmount {
|
498
|
+
amount
|
499
|
+
currencyCode
|
500
|
+
}
|
501
|
+
}
|
502
|
+
attributes {
|
503
|
+
key
|
504
|
+
value
|
505
|
+
}
|
506
|
+
discountAllocations {
|
507
|
+
discountedAmount {
|
508
|
+
amount
|
509
|
+
currencyCode
|
510
|
+
}
|
511
|
+
... on CartAutomaticDiscountAllocation {
|
512
|
+
__typename
|
513
|
+
discountedAmount {
|
514
|
+
amount
|
515
|
+
currencyCode
|
516
|
+
}
|
517
|
+
title
|
518
|
+
}
|
519
|
+
... on CartCodeDiscountAllocation {
|
520
|
+
__typename
|
521
|
+
code
|
522
|
+
discountedAmount {
|
523
|
+
amount
|
524
|
+
currencyCode
|
525
|
+
}
|
526
|
+
}
|
527
|
+
... on CartCustomDiscountAllocation {
|
528
|
+
__typename
|
529
|
+
discountedAmount {
|
530
|
+
amount
|
531
|
+
currencyCode
|
532
|
+
}
|
533
|
+
title
|
534
|
+
}
|
535
|
+
}
|
536
|
+
merchandise {
|
537
|
+
... on ProductVariant {
|
538
|
+
availableForSale
|
539
|
+
id
|
540
|
+
sku
|
541
|
+
title
|
542
|
+
compareAtPrice {
|
543
|
+
amount
|
544
|
+
currencyCode
|
545
|
+
}
|
546
|
+
image {
|
547
|
+
altText
|
548
|
+
height
|
549
|
+
id
|
550
|
+
url
|
551
|
+
width
|
552
|
+
}
|
553
|
+
price {
|
554
|
+
amount
|
555
|
+
currencyCode
|
556
|
+
}
|
557
|
+
product {
|
558
|
+
handle
|
559
|
+
id
|
560
|
+
productType
|
561
|
+
tags
|
562
|
+
title
|
563
|
+
vendor
|
564
|
+
collections(first: 10) {
|
565
|
+
nodes {
|
566
|
+
handle
|
567
|
+
}
|
568
|
+
}
|
569
|
+
options {
|
570
|
+
...OptionFragment
|
571
|
+
}
|
572
|
+
images(first: 20) {
|
573
|
+
nodes {
|
574
|
+
altText
|
575
|
+
height
|
576
|
+
id
|
577
|
+
url
|
578
|
+
width
|
579
|
+
}
|
580
|
+
}
|
581
|
+
}
|
582
|
+
selectedOptions {
|
583
|
+
name
|
584
|
+
value
|
585
|
+
}
|
586
|
+
}
|
587
|
+
}
|
588
|
+
}
|
589
|
+
}
|
590
|
+
`;
|
591
|
+
var CART_FRAGMENT = `#graphql
|
592
|
+
fragment CartFragment on Cart {
|
593
|
+
id
|
594
|
+
checkoutUrl
|
595
|
+
createdAt
|
596
|
+
totalQuantity
|
597
|
+
note
|
598
|
+
updatedAt
|
599
|
+
__typename
|
600
|
+
buyerIdentity {
|
601
|
+
countryCode
|
602
|
+
customer {
|
603
|
+
id
|
604
|
+
email
|
605
|
+
firstName
|
606
|
+
lastName
|
607
|
+
displayName
|
608
|
+
}
|
609
|
+
email
|
610
|
+
phone
|
611
|
+
}
|
612
|
+
attributes {
|
613
|
+
key
|
614
|
+
value
|
615
|
+
}
|
616
|
+
cost {
|
617
|
+
subtotalAmount {
|
618
|
+
amount
|
619
|
+
currencyCode
|
620
|
+
}
|
621
|
+
totalAmount {
|
622
|
+
amount
|
623
|
+
currencyCode
|
624
|
+
}
|
625
|
+
}
|
626
|
+
discountAllocations {
|
627
|
+
discountedAmount {
|
628
|
+
amount
|
629
|
+
currencyCode
|
630
|
+
}
|
631
|
+
... on CartAutomaticDiscountAllocation {
|
632
|
+
__typename
|
633
|
+
discountedAmount {
|
634
|
+
amount
|
635
|
+
currencyCode
|
636
|
+
}
|
637
|
+
title
|
638
|
+
}
|
639
|
+
... on CartCodeDiscountAllocation {
|
640
|
+
__typename
|
641
|
+
code
|
642
|
+
discountedAmount {
|
643
|
+
amount
|
644
|
+
currencyCode
|
645
|
+
}
|
646
|
+
}
|
647
|
+
... on CartCustomDiscountAllocation {
|
648
|
+
__typename
|
649
|
+
discountedAmount {
|
650
|
+
amount
|
651
|
+
currencyCode
|
652
|
+
}
|
653
|
+
title
|
654
|
+
}
|
655
|
+
}
|
656
|
+
discountCodes {
|
657
|
+
applicable
|
658
|
+
code
|
659
|
+
}
|
660
|
+
lines(first: $numCartLines) {
|
661
|
+
edges {
|
662
|
+
node {
|
663
|
+
...CartLineComponentFragment
|
664
|
+
}
|
665
|
+
}
|
666
|
+
edges {
|
667
|
+
node {
|
668
|
+
...CartLineFragment
|
669
|
+
}
|
670
|
+
}
|
671
|
+
}
|
672
|
+
}
|
673
|
+
${CART_LINE_FRAGMENT}
|
674
|
+
${CART_LINE_COMPONENT_FRAGMENT}
|
675
|
+
${OPTION_FRAGMENT}
|
676
|
+
`;
|
677
|
+
|
678
|
+
// src/providers/RebuyHydrogenReactContextProvider.tsx
|
679
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
680
|
+
var PUBLIC_PRIMARY_DOMAIN = import.meta.env.PUBLIC_PRIMARY_DOMAIN;
|
681
|
+
var PUBLIC_REBUY_API_KEY = import.meta.env.PUBLIC_REBUY_API_KEY;
|
682
|
+
var PUBLIC_STORE_DOMAIN = import.meta.env.PUBLIC_STORE_DOMAIN;
|
683
|
+
var PUBLIC_STOREFRONT_ID = import.meta.env.PUBLIC_STOREFRONT_ID;
|
684
|
+
var PUBLIC_STOREFRONT_API_TOKEN = import.meta.env.PUBLIC_STOREFRONT_API_TOKEN || "";
|
685
|
+
var RebuyHydrogenReactContext = ({ children }) => {
|
686
|
+
const [rebuyConfig, setRebuyConfig] = useState2(null);
|
687
|
+
const location = useLocation2();
|
688
|
+
const queryObject = Utilities3.queryStringToObject(location.search);
|
689
|
+
const windowUrl = `${PUBLIC_PRIMARY_DOMAIN}${location.pathname}${location.search}`;
|
690
|
+
const cart = useCart();
|
691
|
+
useEffect2(() => {
|
692
|
+
const initConfig = async () => {
|
693
|
+
const config = await getRebuyConfig(PUBLIC_STORE_DOMAIN);
|
694
|
+
setRebuyConfig(config);
|
695
|
+
};
|
696
|
+
if (!rebuyConfig?.shop) {
|
697
|
+
initConfig();
|
698
|
+
}
|
699
|
+
}, [rebuyConfig, PUBLIC_STORE_DOMAIN]);
|
700
|
+
const contextParameters = useMemo2(
|
701
|
+
() => createContextParameters({
|
702
|
+
cacheKey: rebuyConfig?.shop?.cache_key,
|
703
|
+
cartAttributes: cart?.attributes,
|
704
|
+
cartId: cart?.id,
|
705
|
+
cartLines: cart?.lines,
|
706
|
+
cartLinesLength: cart?.lines?.length,
|
707
|
+
cartSubtotal: cart?.cost?.subtotalAmount?.amount,
|
708
|
+
cartTotalQuantity: cart?.totalQuantity,
|
709
|
+
isHydrogenReact: true,
|
710
|
+
queryObject,
|
711
|
+
windowUrl
|
712
|
+
}),
|
713
|
+
[rebuyConfig, windowUrl, queryObject, cart]
|
714
|
+
);
|
715
|
+
const contextParametersJSON = JSON.stringify(contextParameters);
|
716
|
+
const contextValue = useMemo2(
|
717
|
+
() => ({ contextParameters: JSON.parse(contextParametersJSON) }),
|
718
|
+
[contextParametersJSON]
|
719
|
+
);
|
720
|
+
return /* @__PURE__ */ jsx2(RebuyContext.Provider, { value: contextValue, children });
|
721
|
+
};
|
722
|
+
var RebuyHydrogenReactContextProvider = ({
|
723
|
+
cartFragment = CART_FRAGMENT,
|
724
|
+
children,
|
725
|
+
countryIsoCode = "US",
|
726
|
+
customerAccessToken = "",
|
727
|
+
data,
|
728
|
+
languageIsoCode = "EN",
|
729
|
+
numCartLines,
|
730
|
+
onAttributesUpdate,
|
731
|
+
onAttributesUpdateComplete,
|
732
|
+
onBuyerIdentityUpdate,
|
733
|
+
onBuyerIdentityUpdateComplete,
|
734
|
+
onCreate,
|
735
|
+
onCreateComplete,
|
736
|
+
onDiscountCodesUpdate,
|
737
|
+
onDiscountCodesUpdateComplete,
|
738
|
+
onLineAdd,
|
739
|
+
onLineAddComplete,
|
740
|
+
onLineRemove,
|
741
|
+
onLineRemoveComplete,
|
742
|
+
onLineUpdate,
|
743
|
+
onLineUpdateComplete,
|
744
|
+
onNoteUpdate,
|
745
|
+
onNoteUpdateComplete,
|
746
|
+
storefrontApiVersion = "2025-01"
|
747
|
+
}) => {
|
748
|
+
const adapted = {
|
749
|
+
onAttributesUpdate: onAttributesUpdate ? () => onAttributesUpdate() : void 0,
|
750
|
+
onAttributesUpdateComplete: onAttributesUpdateComplete ? () => onAttributesUpdateComplete() : void 0,
|
751
|
+
onBuyerIdentityUpdate: onBuyerIdentityUpdate ? () => onBuyerIdentityUpdate() : void 0,
|
752
|
+
onBuyerIdentityUpdateComplete: onBuyerIdentityUpdateComplete ? () => onBuyerIdentityUpdateComplete() : void 0,
|
753
|
+
onCreate: onCreate ? () => onCreate() : void 0,
|
754
|
+
onCreateComplete: onCreateComplete ? () => onCreateComplete() : void 0,
|
755
|
+
onDiscountCodesUpdate: onDiscountCodesUpdate ? () => onDiscountCodesUpdate() : void 0,
|
756
|
+
onDiscountCodesUpdateComplete: onDiscountCodesUpdateComplete ? () => onDiscountCodesUpdateComplete() : void 0,
|
757
|
+
onLineAdd: onLineAdd ? () => onLineAdd() : void 0,
|
758
|
+
onLineAddComplete: onLineAddComplete ? () => onLineAddComplete() : void 0,
|
759
|
+
onLineRemove: onLineRemove ? () => onLineRemove() : void 0,
|
760
|
+
onLineRemoveComplete: onLineRemoveComplete ? () => onLineRemoveComplete() : void 0,
|
761
|
+
onLineUpdate: onLineUpdate ? () => onLineUpdate() : void 0,
|
762
|
+
onLineUpdateComplete: onLineUpdateComplete ? () => onLineUpdateComplete() : void 0,
|
763
|
+
onNoteUpdate: onNoteUpdate ? () => onNoteUpdate() : void 0,
|
764
|
+
onNoteUpdateComplete: onNoteUpdateComplete ? () => onNoteUpdateComplete() : void 0
|
765
|
+
};
|
766
|
+
return /* @__PURE__ */ jsx2(
|
767
|
+
ShopifyProvider,
|
768
|
+
{
|
769
|
+
countryIsoCode,
|
770
|
+
languageIsoCode,
|
771
|
+
storeDomain: PUBLIC_STORE_DOMAIN,
|
772
|
+
storefrontApiVersion,
|
773
|
+
storefrontId: PUBLIC_STOREFRONT_ID,
|
774
|
+
storefrontToken: PUBLIC_STOREFRONT_API_TOKEN,
|
775
|
+
children: /* @__PURE__ */ jsx2(
|
776
|
+
CartProvider,
|
777
|
+
{
|
778
|
+
cartFragment,
|
779
|
+
countryCode: countryIsoCode,
|
780
|
+
customerAccessToken,
|
781
|
+
data,
|
782
|
+
languageCode: languageIsoCode,
|
783
|
+
numCartLines,
|
784
|
+
onAttributesUpdate: adapted.onAttributesUpdate,
|
785
|
+
onAttributesUpdateComplete: adapted.onAttributesUpdateComplete,
|
786
|
+
onBuyerIdentityUpdate: adapted.onBuyerIdentityUpdate,
|
787
|
+
onBuyerIdentityUpdateComplete: adapted.onBuyerIdentityUpdateComplete,
|
788
|
+
onCreate: adapted.onCreate,
|
789
|
+
onCreateComplete: adapted.onCreateComplete,
|
790
|
+
onDiscountCodesUpdate: adapted.onDiscountCodesUpdate,
|
791
|
+
onDiscountCodesUpdateComplete: adapted.onDiscountCodesUpdateComplete,
|
792
|
+
onLineAdd: adapted.onLineAdd,
|
793
|
+
onLineAddComplete: adapted.onLineAddComplete,
|
794
|
+
onLineRemove: adapted.onLineRemove,
|
795
|
+
onLineRemoveComplete: adapted.onLineRemoveComplete,
|
796
|
+
onLineUpdate: adapted.onLineUpdate,
|
797
|
+
onLineUpdateComplete: adapted.onLineUpdateComplete,
|
798
|
+
onNoteUpdate: adapted.onNoteUpdate,
|
799
|
+
onNoteUpdateComplete: adapted.onNoteUpdateComplete,
|
800
|
+
children: /* @__PURE__ */ jsx2(RebuyHydrogenReactContext, { children })
|
801
|
+
}
|
802
|
+
)
|
803
|
+
}
|
804
|
+
);
|
805
|
+
};
|
806
|
+
|
807
|
+
// src/widgetContainer/RebuyWidgetContainer.tsx
|
808
|
+
import { RebuyClient as RebuyClient2 } from "@rebuy/rebuy";
|
809
|
+
import * as Utilities4 from "@rebuy/rebuy/utilities";
|
810
|
+
import { flattenConnection } from "@shopify/hydrogen";
|
811
|
+
import React, { useContext, useEffect as useEffect3, useMemo as useMemo3, useState as useState3 } from "react";
|
812
|
+
var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
813
|
+
const { apiKey, collection, collectionId, dataSource, limit, options, product, productId, variant, variantId } = props;
|
814
|
+
const contextParameters = useContext(RebuyContext);
|
815
|
+
const [Rebuy, setRebuy] = useState3(null);
|
816
|
+
const [initialized, setInitialized] = useState3(false);
|
817
|
+
const shopifyProductId = product?.id ?? productId ?? null;
|
818
|
+
const shopifyVariantId = variant?.id ?? variantId ?? null;
|
819
|
+
const shopifyCollectionId = collection?.id ?? collectionId ?? null;
|
820
|
+
const [products, setProducts] = useState3([]);
|
821
|
+
const [metadata, setMetadata] = useState3();
|
822
|
+
useEffect3(() => {
|
823
|
+
if (!Rebuy) {
|
824
|
+
const client = new RebuyClient2(apiKey);
|
825
|
+
client.setContextParameters(
|
826
|
+
contextParameters
|
827
|
+
// TODO: fix this type when @rebuy/rebuy is moved to typescript
|
828
|
+
);
|
829
|
+
if (options) {
|
830
|
+
client.setDefaultParameters(options);
|
831
|
+
}
|
832
|
+
setRebuy(client);
|
833
|
+
setInitialized(true);
|
834
|
+
}
|
835
|
+
}, [apiKey, Rebuy, contextParameters, options]);
|
836
|
+
useEffect3(() => {
|
837
|
+
if (!Rebuy) return;
|
838
|
+
Rebuy.setContextParameters(
|
839
|
+
contextParameters
|
840
|
+
// TODO: fix this type when @rebuy/rebuy is moved to typescript
|
841
|
+
);
|
842
|
+
}, [Rebuy, contextParameters]);
|
843
|
+
const request = useMemo3(() => {
|
844
|
+
const request2 = {
|
845
|
+
endpoint: dataSource || "/api/v1/products/recommended",
|
846
|
+
params: {}
|
847
|
+
// Keeping this object generic to allow for custom endpoints
|
848
|
+
};
|
849
|
+
if (shopifyProductId) {
|
850
|
+
request2.params.shopify_product_ids = Utilities4.getIdFromGraphUrl(shopifyProductId, "Product");
|
851
|
+
}
|
852
|
+
if (shopifyProductId) {
|
853
|
+
request2.params.shopify_product_ids = Utilities4.getIdFromGraphUrl(shopifyProductId, "Product");
|
854
|
+
}
|
855
|
+
if (shopifyVariantId) {
|
856
|
+
request2.params.shopify_variant_ids = Utilities4.getIdFromGraphUrl(shopifyVariantId, "ProductVariant");
|
857
|
+
}
|
858
|
+
if (shopifyCollectionId) {
|
859
|
+
request2.params.shopify_collection_ids = Utilities4.getIdFromGraphUrl(shopifyCollectionId, "Collection");
|
860
|
+
}
|
861
|
+
if (limit) {
|
862
|
+
request2.params.limit = limit;
|
863
|
+
}
|
864
|
+
return request2;
|
865
|
+
}, [dataSource, shopifyProductId, shopifyVariantId, shopifyCollectionId, limit]);
|
866
|
+
useEffect3(() => {
|
867
|
+
let isMounted = true;
|
868
|
+
if (!Rebuy || !initialized) return;
|
869
|
+
const fetchData = async () => {
|
870
|
+
const { data, metadata: metadata2 } = await Rebuy.getStorefrontData(request.endpoint, request.params);
|
871
|
+
if (isMounted) {
|
872
|
+
setProducts(
|
873
|
+
Array.isArray(data) ? data.map((product2) => ({
|
874
|
+
...product2,
|
875
|
+
variants: {
|
876
|
+
nodes: product2.variants ? flattenConnection(product2.variants) : []
|
877
|
+
}
|
878
|
+
})) : []
|
879
|
+
);
|
880
|
+
setMetadata(metadata2);
|
881
|
+
}
|
882
|
+
};
|
883
|
+
fetchData();
|
884
|
+
return () => {
|
885
|
+
isMounted = false;
|
886
|
+
};
|
887
|
+
}, [Rebuy, initialized, request]);
|
888
|
+
const childrenWithProps = (props2) => React.Children.map(
|
889
|
+
children,
|
890
|
+
(child) => React.isValidElement(child) ? React.cloneElement(child, props2) : child
|
891
|
+
);
|
892
|
+
const childProps = {
|
893
|
+
...props,
|
894
|
+
isHydrogenReact: contextParameters?.contextParameters?.isHydrogenReact,
|
895
|
+
key: product?.id,
|
896
|
+
metadata,
|
897
|
+
products
|
898
|
+
};
|
899
|
+
return childrenWithProps(childProps);
|
900
|
+
};
|
901
|
+
var RebuyWidgetContainer = RebuyWidgetContainerBase;
|
902
|
+
|
903
|
+
// src/components/ProductCard/ProductCard.tsx
|
904
|
+
import { Link } from "@remix-run/react";
|
905
|
+
import { Image } from "@shopify/hydrogen";
|
906
|
+
import { useState as useState4 } from "react";
|
907
|
+
|
908
|
+
// src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx
|
909
|
+
import { CartForm, Money } from "@shopify/hydrogen";
|
910
|
+
|
911
|
+
// src/components/AddToCartBtn/AddToCartBtn.module.css
|
912
|
+
var AddToCartBtn_default = {
|
913
|
+
button: "AddToCartBtn_button"
|
914
|
+
};
|
915
|
+
|
916
|
+
// src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx
|
917
|
+
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
918
|
+
var HydrogenAddToCartBtn = ({
|
919
|
+
addToCartBtnText,
|
920
|
+
addToCartCallback,
|
921
|
+
disabled,
|
922
|
+
linesToAdd,
|
923
|
+
moneyData
|
924
|
+
}) => {
|
925
|
+
return /* @__PURE__ */ jsx3(
|
926
|
+
CartForm,
|
927
|
+
{
|
928
|
+
action: CartForm.ACTIONS.LinesAdd,
|
929
|
+
inputs: {
|
930
|
+
lines: linesToAdd
|
931
|
+
},
|
932
|
+
route: "/cart",
|
933
|
+
children: (fetcher) => /* @__PURE__ */ jsx3(Fragment, { children: /* @__PURE__ */ jsxs(
|
934
|
+
"button",
|
935
|
+
{
|
936
|
+
className: AddToCartBtn_default.button,
|
937
|
+
disabled: disabled || fetcher.state !== "idle",
|
938
|
+
onClick: addToCartCallback,
|
939
|
+
type: "submit",
|
940
|
+
children: [
|
941
|
+
addToCartBtnText,
|
942
|
+
moneyData && /* @__PURE__ */ jsxs(Fragment, { children: [
|
943
|
+
/* @__PURE__ */ jsx3("span", { children: " | " }),
|
944
|
+
/* @__PURE__ */ jsx3(Money, { data: moneyData, withoutTrailingZeros: true })
|
945
|
+
] })
|
946
|
+
]
|
947
|
+
}
|
948
|
+
) })
|
949
|
+
}
|
950
|
+
);
|
951
|
+
};
|
952
|
+
|
953
|
+
// src/components/AddToCartBtn/HydrogenReactAddToCartBtn.tsx
|
954
|
+
import { Money as Money2, useCart as useCart2 } from "@shopify/hydrogen-react";
|
955
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
956
|
+
var HydrogenReactAddToCartBtn = ({
|
957
|
+
addToCartBtnText,
|
958
|
+
addToCartCallback,
|
959
|
+
disabled,
|
960
|
+
linesToAdd,
|
961
|
+
moneyData
|
962
|
+
}) => {
|
963
|
+
const { linesAdd } = useCart2();
|
964
|
+
const handleAddToCart = () => {
|
965
|
+
linesAdd(linesToAdd);
|
966
|
+
addToCartCallback?.();
|
967
|
+
};
|
968
|
+
return /* @__PURE__ */ jsxs2("button", { className: AddToCartBtn_default.button, disabled, onClick: handleAddToCart, type: "button", children: [
|
969
|
+
addToCartBtnText,
|
970
|
+
moneyData && /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
971
|
+
/* @__PURE__ */ jsx4("span", { children: " | " }),
|
972
|
+
/* @__PURE__ */ jsx4(Money2, { data: moneyData, withoutTrailingZeros: true })
|
973
|
+
] })
|
974
|
+
] });
|
975
|
+
};
|
976
|
+
|
977
|
+
// src/components/AddToCartBtn/AddToCartBtn.tsx
|
978
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
979
|
+
var AddToCartBtn = ({
|
980
|
+
addToCartBtnText,
|
981
|
+
addToCartCallback,
|
982
|
+
disabled,
|
983
|
+
isHydrogenReact,
|
984
|
+
moneyData,
|
985
|
+
selectedVariants
|
986
|
+
}) => {
|
987
|
+
const linesToAdd = selectedVariants.map((variant) => ({
|
988
|
+
attributes: [
|
989
|
+
{ key: "_source", value: "Rebuy" },
|
990
|
+
{ key: "_attribution", value: "Rebuy Product Recommendations" }
|
991
|
+
],
|
992
|
+
merchandiseId: variant.id,
|
993
|
+
quantity: 1,
|
994
|
+
selectedVariant: variant
|
995
|
+
}));
|
996
|
+
if (isHydrogenReact) {
|
997
|
+
return /* @__PURE__ */ jsx5(
|
998
|
+
HydrogenReactAddToCartBtn,
|
999
|
+
{
|
1000
|
+
addToCartBtnText,
|
1001
|
+
addToCartCallback,
|
1002
|
+
disabled,
|
1003
|
+
linesToAdd,
|
1004
|
+
moneyData
|
1005
|
+
}
|
1006
|
+
);
|
1007
|
+
}
|
1008
|
+
return /* @__PURE__ */ jsx5(
|
1009
|
+
HydrogenAddToCartBtn,
|
1010
|
+
{
|
1011
|
+
addToCartBtnText,
|
1012
|
+
addToCartCallback,
|
1013
|
+
disabled,
|
1014
|
+
linesToAdd,
|
1015
|
+
moneyData
|
1016
|
+
}
|
1017
|
+
);
|
1018
|
+
};
|
1019
|
+
|
1020
|
+
// src/components/ProductPrice/ProductPrice.tsx
|
1021
|
+
import { Money as Money3 } from "@shopify/hydrogen";
|
1022
|
+
|
1023
|
+
// src/components/ProductPrice/ProductPrice.module.css
|
1024
|
+
var ProductPrice_default = {
|
1025
|
+
priceContainer: "ProductPrice_priceContainer",
|
1026
|
+
compareAtPrice: "ProductPrice_compareAtPrice"
|
1027
|
+
};
|
1028
|
+
|
1029
|
+
// src/components/ProductPrice/ProductPrice.tsx
|
1030
|
+
import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
1031
|
+
var RebuyProductPrice = ({ selectedVariant }) => {
|
1032
|
+
if (!selectedVariant) return null;
|
1033
|
+
const { compareAtPriceV2: compareAtPrice, priceV2: price } = selectedVariant;
|
1034
|
+
const isDiscounted = (price2, compareAtPrice2) => Number(compareAtPrice2?.amount) > Number(price2?.amount);
|
1035
|
+
const CompareAtPrice = ({ data: compareAtPrice2 }) => {
|
1036
|
+
return compareAtPrice2 && /* @__PURE__ */ jsx6(Money3, { as: "span", className: ProductPrice_default.compareAtPrice, data: compareAtPrice2, withoutTrailingZeros: true });
|
1037
|
+
};
|
1038
|
+
return price && /* @__PURE__ */ jsxs3("div", { className: ProductPrice_default.priceContainer, children: [
|
1039
|
+
/* @__PURE__ */ jsx6(Money3, { data: price, withoutTrailingZeros: true }),
|
1040
|
+
compareAtPrice && isDiscounted(price, compareAtPrice) && /* @__PURE__ */ jsx6(CompareAtPrice, { data: compareAtPrice })
|
1041
|
+
] });
|
1042
|
+
};
|
1043
|
+
|
1044
|
+
// src/components/Title/Title.tsx
|
1045
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
1046
|
+
var Title = ({ level, style, text }) => {
|
1047
|
+
switch (level) {
|
1048
|
+
case "h1":
|
1049
|
+
return /* @__PURE__ */ jsx7("h1", { style, children: text });
|
1050
|
+
default:
|
1051
|
+
case "h2":
|
1052
|
+
return /* @__PURE__ */ jsx7("h2", { style, children: text });
|
1053
|
+
case "h3":
|
1054
|
+
return /* @__PURE__ */ jsx7("h3", { style, children: text });
|
1055
|
+
case "h4":
|
1056
|
+
return /* @__PURE__ */ jsx7("h4", { style, children: text });
|
1057
|
+
case "h5":
|
1058
|
+
return /* @__PURE__ */ jsx7("h5", { style, children: text });
|
1059
|
+
case "h6":
|
1060
|
+
return /* @__PURE__ */ jsx7("h6", { style, children: text });
|
1061
|
+
}
|
1062
|
+
};
|
1063
|
+
|
1064
|
+
// src/components/VariantSelect/VariantSelect.module.css
|
1065
|
+
var VariantSelect_default = {
|
1066
|
+
select: "VariantSelect_select"
|
1067
|
+
};
|
1068
|
+
|
1069
|
+
// src/components/VariantSelect/VariantSelect.tsx
|
1070
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
1071
|
+
var VariantSelect = ({ handleSelectedVariant, product }) => {
|
1072
|
+
const getOptionsLabel = (product2) => {
|
1073
|
+
const options = product2.variants.nodes[0].selectedOptions;
|
1074
|
+
const optionsFromKeys = options ? Object.keys(options[0]) : [];
|
1075
|
+
const optionsFromValues = options ? options.map((option) => option.name) : [];
|
1076
|
+
const useValues = optionsFromKeys.every((key) => ["name", "value"].includes(key));
|
1077
|
+
return (useValues ? optionsFromValues : optionsFromKeys).join(" / ");
|
1078
|
+
};
|
1079
|
+
return product?.variants.nodes.length > 1 && /* @__PURE__ */ jsx8("div", { children: /* @__PURE__ */ jsx8(
|
1080
|
+
"select",
|
1081
|
+
{
|
1082
|
+
"aria-label": "select variant",
|
1083
|
+
className: VariantSelect_default.select,
|
1084
|
+
onChange: (e) => handleSelectedVariant(product, e.target.value),
|
1085
|
+
children: /* @__PURE__ */ jsx8("optgroup", { label: getOptionsLabel(product), children: product.variants.nodes.map(({ id, title }) => /* @__PURE__ */ jsx8("option", { value: id, children: title }, id + "-variant")) })
|
1086
|
+
}
|
1087
|
+
) });
|
1088
|
+
};
|
1089
|
+
|
1090
|
+
// src/components/ProductCard/ProductCard.module.css
|
1091
|
+
var ProductCard_default = {
|
1092
|
+
container: "ProductCard_container",
|
1093
|
+
productInfo: "ProductCard_productInfo"
|
1094
|
+
};
|
1095
|
+
|
1096
|
+
// src/components/ProductCard/ProductCard.tsx
|
1097
|
+
import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
|
1098
|
+
var ProductCard = ({
|
1099
|
+
addToCartBtnText,
|
1100
|
+
addToCartCallback,
|
1101
|
+
isHydrogenReact,
|
1102
|
+
product,
|
1103
|
+
productCardTitleLevel
|
1104
|
+
}) => {
|
1105
|
+
const [selectedVariant, setSelectedVariant] = useState4(product.variants.nodes[0]);
|
1106
|
+
const { image } = selectedVariant;
|
1107
|
+
const handleSelectedVariant = (product2, variant_id) => {
|
1108
|
+
const updatedVariant = product2.variants.nodes.find((variant) => variant.id === variant_id);
|
1109
|
+
if (updatedVariant) {
|
1110
|
+
setSelectedVariant(updatedVariant);
|
1111
|
+
}
|
1112
|
+
};
|
1113
|
+
return /* @__PURE__ */ jsxs4("div", { className: ProductCard_default.container, children: [
|
1114
|
+
/* @__PURE__ */ jsxs4("div", { children: [
|
1115
|
+
/* @__PURE__ */ jsx9(Link, { to: `/products/${product.handle}`, children: /* @__PURE__ */ jsx9(
|
1116
|
+
Image,
|
1117
|
+
{
|
1118
|
+
alt: image?.altText ?? `Picture of ${product.title}`,
|
1119
|
+
data: image,
|
1120
|
+
sizes: "(max-width: 320px) 280px, (max-width: 768px) 720px, 1440px"
|
1121
|
+
}
|
1122
|
+
) }),
|
1123
|
+
/* @__PURE__ */ jsxs4("div", { className: ProductCard_default.productInfo, children: [
|
1124
|
+
/* @__PURE__ */ jsx9(Link, { to: `/products/${product.handle}`, children: /* @__PURE__ */ jsx9(Title, { level: productCardTitleLevel, text: product.title }) }),
|
1125
|
+
/* @__PURE__ */ jsx9(RebuyProductPrice, { selectedVariant }),
|
1126
|
+
/* @__PURE__ */ jsx9(VariantSelect, { handleSelectedVariant, product })
|
1127
|
+
] })
|
1128
|
+
] }),
|
1129
|
+
/* @__PURE__ */ jsx9(
|
1130
|
+
AddToCartBtn,
|
1131
|
+
{
|
1132
|
+
addToCartBtnText,
|
1133
|
+
addToCartCallback,
|
1134
|
+
isHydrogenReact,
|
1135
|
+
selectedVariants: [selectedVariant]
|
1136
|
+
}
|
1137
|
+
)
|
1138
|
+
] });
|
1139
|
+
};
|
1140
|
+
|
1141
|
+
// src/hooks/titleLevel.tsx
|
1142
|
+
var getTitleLevel = (level, decreaseLevel = false) => {
|
1143
|
+
switch (level) {
|
1144
|
+
case "h1":
|
1145
|
+
if (decreaseLevel) {
|
1146
|
+
return "h2" /* H2 */;
|
1147
|
+
}
|
1148
|
+
return "h1" /* H1 */;
|
1149
|
+
case "h2":
|
1150
|
+
if (decreaseLevel) {
|
1151
|
+
return "h3" /* H3 */;
|
1152
|
+
}
|
1153
|
+
return "h2" /* H2 */;
|
1154
|
+
case "h3":
|
1155
|
+
if (decreaseLevel) {
|
1156
|
+
return "h4" /* H4 */;
|
1157
|
+
}
|
1158
|
+
return "h3" /* H3 */;
|
1159
|
+
case "h4":
|
1160
|
+
if (decreaseLevel) {
|
1161
|
+
return "h5" /* H5 */;
|
1162
|
+
}
|
1163
|
+
return "h4" /* H4 */;
|
1164
|
+
case "h5":
|
1165
|
+
if (decreaseLevel) {
|
1166
|
+
return "h6" /* H6 */;
|
1167
|
+
}
|
1168
|
+
return "h5" /* H5 */;
|
1169
|
+
case "h6":
|
1170
|
+
if (decreaseLevel) {
|
1171
|
+
return "h6" /* H6 */;
|
1172
|
+
}
|
1173
|
+
return "h6" /* H6 */;
|
1174
|
+
default:
|
1175
|
+
return "h2" /* H2 */;
|
1176
|
+
}
|
1177
|
+
};
|
1178
|
+
|
1179
|
+
// src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.module.css
|
1180
|
+
var RebuyCompleteTheLook_default = {
|
1181
|
+
container: "RebuyCompleteTheLook_container",
|
1182
|
+
productGrid: "RebuyCompleteTheLook_productGrid",
|
1183
|
+
productItem: "RebuyCompleteTheLook_productItem"
|
1184
|
+
};
|
1185
|
+
|
1186
|
+
// src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.tsx
|
1187
|
+
import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
|
1188
|
+
var RebuyCompleteTheLook = (props) => {
|
1189
|
+
const {
|
1190
|
+
addToCartBtnText = "Add to cart",
|
1191
|
+
addToCartCallback,
|
1192
|
+
customTitle = `These pair with ${props.product?.title}`,
|
1193
|
+
customTitleLevel = "h2",
|
1194
|
+
customTitleStyle,
|
1195
|
+
products = []
|
1196
|
+
} = props;
|
1197
|
+
if (products.length === 0) {
|
1198
|
+
console.log("RebuyCompleteTheLook: No products found");
|
1199
|
+
return null;
|
1200
|
+
}
|
1201
|
+
return /* @__PURE__ */ jsxs5("section", { className: RebuyCompleteTheLook_default.container, children: [
|
1202
|
+
/* @__PURE__ */ jsx10(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
|
1203
|
+
/* @__PURE__ */ jsx10("ul", { className: RebuyCompleteTheLook_default.productGrid, children: products.map((product) => /* @__PURE__ */ jsx10("li", { className: RebuyCompleteTheLook_default.productItem, children: /* @__PURE__ */ jsx10(
|
1204
|
+
ProductCard,
|
1205
|
+
{
|
1206
|
+
addToCartBtnText,
|
1207
|
+
addToCartCallback,
|
1208
|
+
isHydrogenReact: props.isHydrogenReact,
|
1209
|
+
product,
|
1210
|
+
productCardTitleLevel: getTitleLevel(customTitleLevel, true)
|
1211
|
+
}
|
1212
|
+
) }, product.id)) })
|
1213
|
+
] });
|
1214
|
+
};
|
1215
|
+
|
1216
|
+
// src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx
|
1217
|
+
import { useCallback, useEffect as useEffect4, useState as useState5 } from "react";
|
1218
|
+
|
1219
|
+
// src/utils/convertToRebuyProduct.tsx
|
1220
|
+
var convertToRebuyProduct = (isHydrogenReact, product) => {
|
1221
|
+
const mainProductVariants = isHydrogenReact ? product?.variants?.nodes?.map((variant) => {
|
1222
|
+
return {
|
1223
|
+
...variant
|
1224
|
+
};
|
1225
|
+
}) || [] : product?.adjacentVariants.map((variant) => {
|
1226
|
+
return {
|
1227
|
+
availableForSale: variant.availableForSale,
|
1228
|
+
compareAtPriceV2: {
|
1229
|
+
amount: variant.compareAtPrice?.amount || "",
|
1230
|
+
currencyCode: variant.compareAtPrice?.currencyCode || "USD"
|
1231
|
+
},
|
1232
|
+
id: variant.id,
|
1233
|
+
image: {
|
1234
|
+
altText: variant.image?.altText || "",
|
1235
|
+
height: variant.image?.height || 100,
|
1236
|
+
id: variant.image?.id || "",
|
1237
|
+
url: variant.image?.url || "",
|
1238
|
+
width: variant.image?.width || 100
|
1239
|
+
},
|
1240
|
+
priceV2: {
|
1241
|
+
amount: variant.price.amount || "",
|
1242
|
+
currencyCode: variant.price.currencyCode || "USD"
|
1243
|
+
},
|
1244
|
+
product: {
|
1245
|
+
handle: product.handle,
|
1246
|
+
id: product.id,
|
1247
|
+
title: product.title,
|
1248
|
+
vendor: product.vendor
|
1249
|
+
},
|
1250
|
+
selectedOptions: variant.selectedOptions,
|
1251
|
+
sku: variant.sku || "",
|
1252
|
+
title: variant.title || ""
|
1253
|
+
};
|
1254
|
+
}) || [];
|
1255
|
+
return isHydrogenReact ? {
|
1256
|
+
collections: {
|
1257
|
+
nodes: product?.collections.nodes.map((collection) => {
|
1258
|
+
return {
|
1259
|
+
handle: collection.handle
|
1260
|
+
};
|
1261
|
+
}) || []
|
1262
|
+
},
|
1263
|
+
compareAtPriceRange: {
|
1264
|
+
maxVariantCompareAtPrice: null,
|
1265
|
+
minVariantCompareAtPrice: null
|
1266
|
+
},
|
1267
|
+
description: product?.description || "",
|
1268
|
+
descriptionHtml: product?.descriptionHtml || "",
|
1269
|
+
featuredImage: {
|
1270
|
+
altText: product?.featuredImage?.altText || "",
|
1271
|
+
height: product?.featuredImage?.height || 100,
|
1272
|
+
id: product?.featuredImage?.id || "",
|
1273
|
+
url: product?.featuredImage?.url || "",
|
1274
|
+
width: product?.featuredImage?.width || 100
|
1275
|
+
},
|
1276
|
+
handle: product?.handle || "",
|
1277
|
+
id: product?.id || "",
|
1278
|
+
images: [{ altText: "", height: 100, id: "", url: "", width: 100 }],
|
1279
|
+
media: [],
|
1280
|
+
metafields: [],
|
1281
|
+
options: [],
|
1282
|
+
priceRange: product?.priceRange || {
|
1283
|
+
maxVariantPrice: { amount: "0", currencyCode: "USD" },
|
1284
|
+
minVariantPrice: { amount: "0", currencyCode: "USD" }
|
1285
|
+
},
|
1286
|
+
selected: true,
|
1287
|
+
selectedOptions: product?.selectedVariant?.selectedOptions?.reduce((acc, option) => {
|
1288
|
+
return { ...acc, [option.name]: option.value };
|
1289
|
+
}, {}) || {},
|
1290
|
+
selectedSellingPlan: {},
|
1291
|
+
selectedSellingPlanAllocation: {},
|
1292
|
+
selectedVariant: {
|
1293
|
+
availableForSale: product?.selectedVariant?.availableForSale || false,
|
1294
|
+
compareAtPriceV2: {
|
1295
|
+
amount: product?.selectedVariant?.compareAtPrice?.amount || "",
|
1296
|
+
currencyCode: product?.selectedVariant?.compareAtPrice?.currencyCode || "USD"
|
1297
|
+
},
|
1298
|
+
id: product?.selectedVariant?.id || "",
|
1299
|
+
image: {
|
1300
|
+
altText: product?.selectedVariant?.image?.altText || "",
|
1301
|
+
height: product?.selectedVariant?.image?.height || 100,
|
1302
|
+
id: product?.selectedVariant?.image?.id || "",
|
1303
|
+
url: product?.selectedVariant?.image?.url || "",
|
1304
|
+
width: product?.selectedVariant?.image?.width || 100
|
1305
|
+
},
|
1306
|
+
priceV2: {
|
1307
|
+
amount: product?.selectedVariant?.price.amount || "",
|
1308
|
+
currencyCode: product?.selectedVariant?.price.currencyCode || "USD"
|
1309
|
+
},
|
1310
|
+
product: {
|
1311
|
+
handle: product?.handle || "",
|
1312
|
+
id: product?.id || "",
|
1313
|
+
title: product?.title || "",
|
1314
|
+
vendor: product?.vendor || ""
|
1315
|
+
},
|
1316
|
+
selectedOptions: product?.selectedVariant?.selectedOptions || [],
|
1317
|
+
sku: product?.selectedVariant?.sku || "",
|
1318
|
+
title: product?.selectedVariant?.title || ""
|
1319
|
+
},
|
1320
|
+
sellingPlanGroups: [],
|
1321
|
+
seo: {
|
1322
|
+
description: product?.seo?.description || "",
|
1323
|
+
title: product?.seo?.title || ""
|
1324
|
+
},
|
1325
|
+
title: product?.title || "",
|
1326
|
+
variants: {
|
1327
|
+
nodes: mainProductVariants
|
1328
|
+
},
|
1329
|
+
vendor: product?.vendor || ""
|
1330
|
+
} : {
|
1331
|
+
collections: {
|
1332
|
+
nodes: []
|
1333
|
+
},
|
1334
|
+
compareAtPriceRange: {
|
1335
|
+
maxVariantCompareAtPrice: null,
|
1336
|
+
minVariantCompareAtPrice: null
|
1337
|
+
},
|
1338
|
+
description: product?.description || "",
|
1339
|
+
descriptionHtml: product?.descriptionHtml || "",
|
1340
|
+
featuredImage: {
|
1341
|
+
altText: product?.selectedOrFirstAvailableVariant?.image?.altText || "",
|
1342
|
+
height: product?.selectedOrFirstAvailableVariant?.image?.height || 100,
|
1343
|
+
id: product?.selectedOrFirstAvailableVariant?.image?.id || "",
|
1344
|
+
url: product?.selectedOrFirstAvailableVariant?.image?.url || "",
|
1345
|
+
width: product?.selectedOrFirstAvailableVariant?.image?.width || 100
|
1346
|
+
},
|
1347
|
+
handle: product?.handle || "",
|
1348
|
+
id: product?.id || "",
|
1349
|
+
images: [
|
1350
|
+
{
|
1351
|
+
altText: product?.selectedOrFirstAvailableVariant?.image?.altText || "",
|
1352
|
+
height: product?.selectedOrFirstAvailableVariant?.image?.height || 100,
|
1353
|
+
id: product?.selectedOrFirstAvailableVariant?.image?.id || "",
|
1354
|
+
url: product?.selectedOrFirstAvailableVariant?.image?.url || "",
|
1355
|
+
width: product?.selectedOrFirstAvailableVariant?.image?.width || 100
|
1356
|
+
}
|
1357
|
+
],
|
1358
|
+
media: [],
|
1359
|
+
metafields: [],
|
1360
|
+
options: [],
|
1361
|
+
priceRange: product?.priceRange || {
|
1362
|
+
maxVariantPrice: { amount: "0", currencyCode: "USD" },
|
1363
|
+
minVariantPrice: { amount: "0", currencyCode: "USD" }
|
1364
|
+
},
|
1365
|
+
selected: true,
|
1366
|
+
selectedOptions: product?.selectedOrFirstAvailableVariant?.selectedOptions?.reduce((acc, option) => {
|
1367
|
+
return { ...acc, [option.name]: option.value };
|
1368
|
+
}, {}) || {},
|
1369
|
+
selectedSellingPlan: {},
|
1370
|
+
selectedSellingPlanAllocation: {},
|
1371
|
+
selectedVariant: {
|
1372
|
+
availableForSale: product?.selectedOrFirstAvailableVariant?.availableForSale || false,
|
1373
|
+
compareAtPriceV2: {
|
1374
|
+
amount: product?.selectedOrFirstAvailableVariant?.compareAtPrice?.amount || "",
|
1375
|
+
currencyCode: product?.selectedOrFirstAvailableVariant?.compareAtPrice?.currencyCode || "USD"
|
1376
|
+
},
|
1377
|
+
id: product?.selectedOrFirstAvailableVariant?.id || "",
|
1378
|
+
image: {
|
1379
|
+
altText: product?.selectedOrFirstAvailableVariant?.image?.altText || "",
|
1380
|
+
height: product?.selectedOrFirstAvailableVariant?.image?.height || 100,
|
1381
|
+
id: product?.selectedOrFirstAvailableVariant?.image?.id || "",
|
1382
|
+
url: product?.selectedOrFirstAvailableVariant?.image?.url || "",
|
1383
|
+
width: product?.selectedOrFirstAvailableVariant?.image?.width || 100
|
1384
|
+
},
|
1385
|
+
priceV2: {
|
1386
|
+
amount: product?.selectedOrFirstAvailableVariant?.price.amount || "",
|
1387
|
+
currencyCode: product?.selectedOrFirstAvailableVariant?.price.currencyCode || "USD"
|
1388
|
+
},
|
1389
|
+
product: {
|
1390
|
+
handle: product?.handle || "",
|
1391
|
+
id: product?.id || "",
|
1392
|
+
title: product?.title || "",
|
1393
|
+
vendor: product?.vendor || ""
|
1394
|
+
},
|
1395
|
+
selectedOptions: product?.selectedOrFirstAvailableVariant?.selectedOptions || [],
|
1396
|
+
sku: product?.selectedOrFirstAvailableVariant?.sku || "",
|
1397
|
+
title: product?.selectedOrFirstAvailableVariant?.title || ""
|
1398
|
+
},
|
1399
|
+
sellingPlanGroups: [],
|
1400
|
+
seo: {
|
1401
|
+
description: null,
|
1402
|
+
title: null
|
1403
|
+
},
|
1404
|
+
title: product?.title || "",
|
1405
|
+
variants: {
|
1406
|
+
nodes: [
|
1407
|
+
{
|
1408
|
+
availableForSale: product?.selectedOrFirstAvailableVariant?.availableForSale || false,
|
1409
|
+
compareAtPriceV2: {
|
1410
|
+
amount: product?.selectedOrFirstAvailableVariant?.compareAtPrice?.amount || "",
|
1411
|
+
currencyCode: product?.selectedOrFirstAvailableVariant?.compareAtPrice?.currencyCode || "USD"
|
1412
|
+
},
|
1413
|
+
id: product?.selectedOrFirstAvailableVariant?.id || "",
|
1414
|
+
image: {
|
1415
|
+
altText: product?.selectedOrFirstAvailableVariant?.image?.altText || "",
|
1416
|
+
height: product?.selectedOrFirstAvailableVariant?.image?.height || 100,
|
1417
|
+
id: product?.selectedOrFirstAvailableVariant?.image?.id || "",
|
1418
|
+
url: product?.selectedOrFirstAvailableVariant?.image?.url || "",
|
1419
|
+
width: product?.selectedOrFirstAvailableVariant?.image?.width || 100
|
1420
|
+
},
|
1421
|
+
priceV2: {
|
1422
|
+
amount: product?.selectedOrFirstAvailableVariant?.price.amount || "",
|
1423
|
+
currencyCode: product?.selectedOrFirstAvailableVariant?.price.currencyCode || "USD"
|
1424
|
+
},
|
1425
|
+
product: {
|
1426
|
+
handle: product?.handle || "",
|
1427
|
+
id: product?.id || "",
|
1428
|
+
title: product?.title || "",
|
1429
|
+
vendor: product?.vendor || ""
|
1430
|
+
},
|
1431
|
+
selectedOptions: product?.selectedOrFirstAvailableVariant?.selectedOptions || [],
|
1432
|
+
sku: product?.selectedOrFirstAvailableVariant?.sku || "",
|
1433
|
+
title: product?.selectedOrFirstAvailableVariant?.title || ""
|
1434
|
+
},
|
1435
|
+
...mainProductVariants
|
1436
|
+
]
|
1437
|
+
},
|
1438
|
+
vendor: product?.vendor || ""
|
1439
|
+
};
|
1440
|
+
};
|
1441
|
+
|
1442
|
+
// src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx
|
1443
|
+
import { Link as Link2 } from "@remix-run/react";
|
1444
|
+
import { Image as Image2 } from "@shopify/hydrogen";
|
1445
|
+
import { Fragment as Fragment3 } from "react";
|
1446
|
+
|
1447
|
+
// src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.module.css
|
1448
|
+
var RebuyDynamicBundleProducts_default = {
|
1449
|
+
container: "RebuyDynamicBundleProducts_container",
|
1450
|
+
addCartBtnContainer: "RebuyDynamicBundleProducts_addCartBtnContainer",
|
1451
|
+
bundleContainer: "RebuyDynamicBundleProducts_bundleContainer",
|
1452
|
+
select: "RebuyDynamicBundleProducts_select",
|
1453
|
+
bundleItemRowContainer: "RebuyDynamicBundleProducts_bundleItemRowContainer",
|
1454
|
+
unselected: "RebuyDynamicBundleProducts_unselected",
|
1455
|
+
bundleItemRow: "RebuyDynamicBundleProducts_bundleItemRow",
|
1456
|
+
bundleItemInput: "RebuyDynamicBundleProducts_bundleItemInput",
|
1457
|
+
bundleItemLabel: "RebuyDynamicBundleProducts_bundleItemLabel",
|
1458
|
+
bundleImages: "RebuyDynamicBundleProducts_bundleImages",
|
1459
|
+
bundleImage: "RebuyDynamicBundleProducts_bundleImage",
|
1460
|
+
"fade-in": "RebuyDynamicBundleProducts_fade-in",
|
1461
|
+
bundleImageDelimiter: "RebuyDynamicBundleProducts_bundleImageDelimiter",
|
1462
|
+
compareAtPrice: "RebuyDynamicBundleProducts_compareAtPrice"
|
1463
|
+
};
|
1464
|
+
|
1465
|
+
// src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx
|
1466
|
+
import { Fragment as Fragment4, jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
|
1467
|
+
var BundleImages = ({ products }) => {
|
1468
|
+
const selected = products.filter((product) => product.selected);
|
1469
|
+
return /* @__PURE__ */ jsx11("ul", { className: RebuyDynamicBundleProducts_default.bundleImages, children: products.map((product, index) => {
|
1470
|
+
const image = product.selectedVariant?.image;
|
1471
|
+
const productImage = image ? /* @__PURE__ */ jsx11(
|
1472
|
+
Image2,
|
1473
|
+
{
|
1474
|
+
alt: image.altText || `Picture of ${product.title}`,
|
1475
|
+
className: RebuyDynamicBundleProducts_default.bundleImage,
|
1476
|
+
data: image,
|
1477
|
+
height: 80,
|
1478
|
+
title: product.title,
|
1479
|
+
width: 80
|
1480
|
+
}
|
1481
|
+
) : (
|
1482
|
+
// No image defined
|
1483
|
+
product.title
|
1484
|
+
);
|
1485
|
+
const showDelimiter = selected[0]?.id !== product.id;
|
1486
|
+
return /* @__PURE__ */ jsx11(Fragment3, { children: product.selected && /* @__PURE__ */ jsxs6(Fragment4, { children: [
|
1487
|
+
showDelimiter && /* @__PURE__ */ jsx11("li", { className: RebuyDynamicBundleProducts_default.bundleImageDelimiter, children: /* @__PURE__ */ jsx11("span", { children: "+" }) }),
|
1488
|
+
/* @__PURE__ */ jsx11("li", { className: "flex items-center", children: product.default ? (
|
1489
|
+
// Already on product page
|
1490
|
+
productImage
|
1491
|
+
) : (
|
1492
|
+
// Link to product
|
1493
|
+
/* @__PURE__ */ jsx11(Link2, { title: product.title, to: `/products/${product.handle}`, children: productImage })
|
1494
|
+
) })
|
1495
|
+
] }) }, product.id + "-BundleImages-" + index);
|
1496
|
+
}) });
|
1497
|
+
};
|
1498
|
+
|
1499
|
+
// src/widgets/RebuyDynamicBundleProducts/Select.tsx
|
1500
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
1501
|
+
var Select = ({ onSelectVariant, product }) => {
|
1502
|
+
const getOptionsLabel = (product2) => {
|
1503
|
+
const options = product2.variants.nodes[0].selectedOptions;
|
1504
|
+
const optionsFromKeys = options ? Object.keys(options[0]) : [];
|
1505
|
+
const optionsFromValues = options ? options.map((option) => option.name) : [];
|
1506
|
+
const useValues = optionsFromKeys.every((key) => ["name", "value"].includes(key));
|
1507
|
+
return (useValues ? optionsFromValues : optionsFromKeys).join(" / ");
|
1508
|
+
};
|
1509
|
+
return product && /* @__PURE__ */ jsx12(
|
1510
|
+
"select",
|
1511
|
+
{
|
1512
|
+
"aria-label": "select variant",
|
1513
|
+
className: RebuyDynamicBundleProducts_default.select,
|
1514
|
+
onChange: (e) => onSelectVariant(product, e.target.value),
|
1515
|
+
value: product.selectedVariant.id,
|
1516
|
+
children: /* @__PURE__ */ jsx12("optgroup", { label: getOptionsLabel(product), children: product.variants.nodes.map(({ id, title }) => /* @__PURE__ */ jsx12("option", { value: id, children: title }, id + "-BundleVariant")) })
|
1517
|
+
}
|
1518
|
+
);
|
1519
|
+
};
|
1520
|
+
|
1521
|
+
// src/widgets/RebuyDynamicBundleProducts/BundleSelection.tsx
|
1522
|
+
import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
|
1523
|
+
var BundleSelection = ({ onSelectVariant, onToggleBundleItem, products }) => {
|
1524
|
+
return /* @__PURE__ */ jsx13("ul", { children: products.map((product, index) => {
|
1525
|
+
const { availableForSale } = product.selectedVariant;
|
1526
|
+
const isOutOfStock = !availableForSale;
|
1527
|
+
return /* @__PURE__ */ jsx13(
|
1528
|
+
"li",
|
1529
|
+
{
|
1530
|
+
className: `${RebuyDynamicBundleProducts_default.bundleItemRowContainer} ${!product.selected && RebuyDynamicBundleProducts_default.unselected}`,
|
1531
|
+
children: /* @__PURE__ */ jsxs7("div", { className: RebuyDynamicBundleProducts_default.bundleItemRow, children: [
|
1532
|
+
/* @__PURE__ */ jsx13(
|
1533
|
+
"input",
|
1534
|
+
{
|
1535
|
+
checked: product.selected && availableForSale,
|
1536
|
+
className: "mt-1 rounded-sm accent-black cursor-pointer",
|
1537
|
+
disabled: isOutOfStock,
|
1538
|
+
id: `${product.id}-toggle`,
|
1539
|
+
onChange: () => onToggleBundleItem(product),
|
1540
|
+
type: "checkbox",
|
1541
|
+
value: product.id
|
1542
|
+
}
|
1543
|
+
),
|
1544
|
+
/* @__PURE__ */ jsxs7("div", { className: RebuyDynamicBundleProducts_default.bundleItemInput, children: [
|
1545
|
+
/* @__PURE__ */ jsxs7("label", { className: RebuyDynamicBundleProducts_default.bundleItemLabel, htmlFor: `${product.id}-toggle`, children: [
|
1546
|
+
isOutOfStock && /* @__PURE__ */ jsx13("b", { children: "SOLD OUT" }),
|
1547
|
+
product.default && /* @__PURE__ */ jsx13("b", { children: "This item:" }),
|
1548
|
+
product.title,
|
1549
|
+
/* @__PURE__ */ jsx13(RebuyProductPrice, { selectedVariant: product.selectedVariant })
|
1550
|
+
] }),
|
1551
|
+
product.variants.nodes.length > 1 && /* @__PURE__ */ jsx13(Select, { onSelectVariant, product })
|
1552
|
+
] })
|
1553
|
+
] })
|
1554
|
+
},
|
1555
|
+
product.id + "-BundleSelection" + index
|
1556
|
+
);
|
1557
|
+
}) });
|
1558
|
+
};
|
1559
|
+
|
1560
|
+
// src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx
|
1561
|
+
import { Money as Money4 } from "@shopify/hydrogen";
|
1562
|
+
import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
|
1563
|
+
var BundlePrice = ({ products }) => {
|
1564
|
+
const isDisabled = products.filter((product) => product.selected).length < 1;
|
1565
|
+
const totalBundlePrice = () => {
|
1566
|
+
let total = 0;
|
1567
|
+
let currencyCode = "USD";
|
1568
|
+
for (const product of products) {
|
1569
|
+
if (product.selected && product.selectedVariant) {
|
1570
|
+
const { priceV2: price2 } = product.selectedVariant;
|
1571
|
+
total += Number(price2?.amount);
|
1572
|
+
currencyCode = price2?.currencyCode || "USD";
|
1573
|
+
}
|
1574
|
+
}
|
1575
|
+
return {
|
1576
|
+
amount: String(total),
|
1577
|
+
currencyCode
|
1578
|
+
};
|
1579
|
+
};
|
1580
|
+
const totalBundleCompareAtPrice = () => {
|
1581
|
+
let compareAtTotal = 0;
|
1582
|
+
let currencyCode = "USD";
|
1583
|
+
for (const product of products) {
|
1584
|
+
if (product.selected && product.selectedVariant) {
|
1585
|
+
const { compareAtPriceV2: compareAtPrice2, priceV2: price2 } = product.selectedVariant;
|
1586
|
+
currencyCode = price2?.currencyCode || "USD";
|
1587
|
+
compareAtTotal += Number((compareAtPrice2 || price2)?.amount);
|
1588
|
+
}
|
1589
|
+
}
|
1590
|
+
return {
|
1591
|
+
amount: String(compareAtTotal),
|
1592
|
+
currencyCode
|
1593
|
+
};
|
1594
|
+
};
|
1595
|
+
const isDiscounted = (price2, compareAtPrice2) => Number(compareAtPrice2?.amount) > Number(price2?.amount);
|
1596
|
+
const price = totalBundlePrice();
|
1597
|
+
const compareAtPrice = totalBundleCompareAtPrice();
|
1598
|
+
const CompareAtPrice = ({ data: compareAtPrice2 }) => {
|
1599
|
+
return compareAtPrice2 && /* @__PURE__ */ jsx14(Money4, { as: "span", className: RebuyDynamicBundleProducts_default.compareAtPrice, data: compareAtPrice2, withoutTrailingZeros: true });
|
1600
|
+
};
|
1601
|
+
return products.length > 0 && /* @__PURE__ */ jsx14("div", { className: "flex items-center flex-col", children: !isDisabled && /* @__PURE__ */ jsxs8("p", { className: "flex items-center gap-2 mb-2", children: [
|
1602
|
+
/* @__PURE__ */ jsx14("span", { children: "Total Price:" }),
|
1603
|
+
/* @__PURE__ */ jsx14(Money4, { as: "span", data: price, withoutTrailingZeros: true }),
|
1604
|
+
isDiscounted(price, compareAtPrice) && /* @__PURE__ */ jsx14(CompareAtPrice, { data: compareAtPrice })
|
1605
|
+
] }) });
|
1606
|
+
};
|
1607
|
+
|
1608
|
+
// src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx
|
1609
|
+
import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
|
1610
|
+
var RebuyDynamicBundleProducts = (props) => {
|
1611
|
+
const {
|
1612
|
+
addToCartBtnText = "Add to cart",
|
1613
|
+
addToCartCallback,
|
1614
|
+
customTitle = `These pair with ${props.product?.title}`,
|
1615
|
+
customTitleLevel = "h2",
|
1616
|
+
customTitleStyle,
|
1617
|
+
isHydrogenReact,
|
1618
|
+
product,
|
1619
|
+
products = []
|
1620
|
+
} = props;
|
1621
|
+
const [bundleProducts, setBundleProducts] = useState5([]);
|
1622
|
+
useEffect4(() => {
|
1623
|
+
const mainProduct = convertToRebuyProduct(isHydrogenReact || false, product);
|
1624
|
+
const formattedProducts = products.map((product2) => {
|
1625
|
+
return {
|
1626
|
+
...product2,
|
1627
|
+
selected: true,
|
1628
|
+
selectedVariant: product2.variants.nodes[0]
|
1629
|
+
};
|
1630
|
+
});
|
1631
|
+
setBundleProducts([mainProduct, ...formattedProducts]);
|
1632
|
+
}, [product, products, isHydrogenReact]);
|
1633
|
+
const onToggleBundleItem = useCallback(
|
1634
|
+
(product2) => {
|
1635
|
+
product2.selected = !product2.selected;
|
1636
|
+
setBundleProducts([...bundleProducts]);
|
1637
|
+
},
|
1638
|
+
[bundleProducts]
|
1639
|
+
);
|
1640
|
+
const onSelectVariant = useCallback(
|
1641
|
+
(product2, variant_id) => {
|
1642
|
+
const variant = product2.variants.nodes.find(({ id }) => id === variant_id);
|
1643
|
+
if (variant) {
|
1644
|
+
product2.selectedVariant = variant;
|
1645
|
+
product2.selected = variant.availableForSale || false;
|
1646
|
+
setBundleProducts([...bundleProducts]);
|
1647
|
+
}
|
1648
|
+
},
|
1649
|
+
[bundleProducts]
|
1650
|
+
);
|
1651
|
+
if (products.length === 0) {
|
1652
|
+
console.log("RebuyDynamicBundleProducts: No products found");
|
1653
|
+
return null;
|
1654
|
+
}
|
1655
|
+
return /* @__PURE__ */ jsxs9("section", { className: RebuyDynamicBundleProducts_default.container, children: [
|
1656
|
+
/* @__PURE__ */ jsx15(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
|
1657
|
+
/* @__PURE__ */ jsxs9("div", { className: RebuyDynamicBundleProducts_default.bundleContainer, children: [
|
1658
|
+
/* @__PURE__ */ jsx15(BundleImages, { products: bundleProducts }),
|
1659
|
+
/* @__PURE__ */ jsx15(BundlePrice, { products: bundleProducts }),
|
1660
|
+
/* @__PURE__ */ jsx15("div", { className: RebuyDynamicBundleProducts_default.addCartBtnContainer, children: /* @__PURE__ */ jsx15(
|
1661
|
+
AddToCartBtn,
|
1662
|
+
{
|
1663
|
+
addToCartBtnText,
|
1664
|
+
addToCartCallback,
|
1665
|
+
disabled: bundleProducts.filter((product2) => product2.selected).length === 0,
|
1666
|
+
isHydrogenReact,
|
1667
|
+
selectedVariants: bundleProducts.filter((product2) => product2.selected).map((product2) => {
|
1668
|
+
return product2.selectedVariant;
|
1669
|
+
})
|
1670
|
+
}
|
1671
|
+
) }),
|
1672
|
+
/* @__PURE__ */ jsx15(
|
1673
|
+
BundleSelection,
|
1674
|
+
{
|
1675
|
+
onSelectVariant,
|
1676
|
+
onToggleBundleItem,
|
1677
|
+
products: bundleProducts
|
1678
|
+
}
|
1679
|
+
)
|
1680
|
+
] })
|
1681
|
+
] });
|
1682
|
+
};
|
1683
|
+
|
1684
|
+
// src/widgets/RebuyProductAddOns/RebuyProductAddOns.tsx
|
1685
|
+
import { Money as Money5 } from "@shopify/hydrogen-react";
|
1686
|
+
import { useCallback as useCallback2, useEffect as useEffect5, useState as useState6 } from "react";
|
1687
|
+
|
1688
|
+
// src/widgets/RebuyProductAddOns/RebuyProductAddOnCard.tsx
|
1689
|
+
import { Link as Link3 } from "@remix-run/react";
|
1690
|
+
import { Image as Image3 } from "@shopify/hydrogen";
|
1691
|
+
|
1692
|
+
// src/widgets/RebuyProductAddOns/RebuyProductAddOns.module.css
|
1693
|
+
var RebuyProductAddOns_default = {
|
1694
|
+
container: "RebuyProductAddOns_container",
|
1695
|
+
productAddOnsList: "RebuyProductAddOns_productAddOnsList",
|
1696
|
+
addOnCard: "RebuyProductAddOns_addOnCard",
|
1697
|
+
addOnCardContent: "RebuyProductAddOns_addOnCardContent",
|
1698
|
+
addOnCardInput: "RebuyProductAddOns_addOnCardInput",
|
1699
|
+
addOnCardContentImage: "RebuyProductAddOns_addOnCardContentImage",
|
1700
|
+
addOnCardOutOfStock: "RebuyProductAddOns_addOnCardOutOfStock",
|
1701
|
+
addOnCardTextContent: "RebuyProductAddOns_addOnCardTextContent",
|
1702
|
+
addOnCardLearnMore: "RebuyProductAddOns_addOnCardLearnMore",
|
1703
|
+
addCartBtnContainer: "RebuyProductAddOns_addCartBtnContainer",
|
1704
|
+
moneyContainer: "RebuyProductAddOns_moneyContainer"
|
1705
|
+
};
|
1706
|
+
|
1707
|
+
// src/widgets/RebuyProductAddOns/RebuyProductAddOnCard.tsx
|
1708
|
+
import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
|
1709
|
+
var RebuyProductAddOnCard = ({
|
1710
|
+
handleChange,
|
1711
|
+
learnMoreText,
|
1712
|
+
outOfStockText,
|
1713
|
+
product,
|
1714
|
+
titleLevel
|
1715
|
+
}) => {
|
1716
|
+
const { availableForSale, image } = product.selectedVariant || {};
|
1717
|
+
return /* @__PURE__ */ jsx16("label", { className: RebuyProductAddOns_default.addOnCard, htmlFor: product.id, children: /* @__PURE__ */ jsxs10("div", { className: RebuyProductAddOns_default.addOnCardContent, children: [
|
1718
|
+
/* @__PURE__ */ jsx16(
|
1719
|
+
"input",
|
1720
|
+
{
|
1721
|
+
checked: Boolean(product.selected),
|
1722
|
+
className: RebuyProductAddOns_default.addOnCardInput,
|
1723
|
+
disabled: !product.variants.nodes[0].availableForSale,
|
1724
|
+
id: product.id,
|
1725
|
+
name: product.title,
|
1726
|
+
onChange: (event) => handleChange(event, product),
|
1727
|
+
type: "checkbox",
|
1728
|
+
value: ""
|
1729
|
+
}
|
1730
|
+
),
|
1731
|
+
/* @__PURE__ */ jsx16("div", { className: RebuyProductAddOns_default.addOnCardContentImage, children: image && /* @__PURE__ */ jsx16(
|
1732
|
+
Image3,
|
1733
|
+
{
|
1734
|
+
alt: image.altText || `Picture of ${product.title}`,
|
1735
|
+
data: image,
|
1736
|
+
height: 150,
|
1737
|
+
width: 300
|
1738
|
+
}
|
1739
|
+
) }),
|
1740
|
+
/* @__PURE__ */ jsxs10("div", { className: RebuyProductAddOns_default.addOnCardTextContent, children: [
|
1741
|
+
!availableForSale && /* @__PURE__ */ jsx16("p", { className: RebuyProductAddOns_default.addOnCardOutOfStock, children: outOfStockText }),
|
1742
|
+
/* @__PURE__ */ jsx16(Title, { level: titleLevel, text: product.title }),
|
1743
|
+
/* @__PURE__ */ jsx16(RebuyProductPrice, { selectedVariant: product.selectedVariant }),
|
1744
|
+
/* @__PURE__ */ jsx16(Link3, { className: RebuyProductAddOns_default.addOnCardLearnMore, to: `/products/${product.handle}`, children: learnMoreText })
|
1745
|
+
] })
|
1746
|
+
] }) });
|
1747
|
+
};
|
1748
|
+
|
1749
|
+
// src/widgets/RebuyProductAddOns/RebuyProductAddOns.tsx
|
1750
|
+
import { jsx as jsx17, jsxs as jsxs11 } from "react/jsx-runtime";
|
1751
|
+
var RebuyProductAddOns = (props) => {
|
1752
|
+
const {
|
1753
|
+
addToCartCallback,
|
1754
|
+
customTitle = `These pair with ${props.product?.title}`,
|
1755
|
+
customTitleLevel = "h2",
|
1756
|
+
customTitleStyle,
|
1757
|
+
includeMainProduct = false,
|
1758
|
+
isHydrogenReact,
|
1759
|
+
learnMoreText = "Learn more",
|
1760
|
+
outOfStockText = "Out of stock",
|
1761
|
+
product,
|
1762
|
+
products = [],
|
1763
|
+
addToCartBtnText = "Add to cart",
|
1764
|
+
subtotalText = "Add-ons Subtotal: ",
|
1765
|
+
withProductText = `With ${product?.title}: `
|
1766
|
+
} = props;
|
1767
|
+
const [addedItems, setAddedItems] = useState6(products);
|
1768
|
+
const [subtotalWithProduct, setSubtotalWithProduct] = useState6();
|
1769
|
+
const [subtotalWithOutProduct, setSubtotalWithOutProduct] = useState6();
|
1770
|
+
useEffect5(() => {
|
1771
|
+
let initialTotal = 0;
|
1772
|
+
let currencyCode = "USD";
|
1773
|
+
products.map((product2) => {
|
1774
|
+
product2.selectedVariant = product2.variants.nodes[0];
|
1775
|
+
product2.selected = true;
|
1776
|
+
if (product2.selectedVariant?.priceV2) {
|
1777
|
+
initialTotal += Number(product2.selectedVariant.priceV2.amount);
|
1778
|
+
currencyCode = product2.selectedVariant.priceV2.currencyCode || "USD";
|
1779
|
+
}
|
1780
|
+
});
|
1781
|
+
setSubtotalWithProduct({
|
1782
|
+
amount: String(initialTotal),
|
1783
|
+
currencyCode
|
1784
|
+
});
|
1785
|
+
setSubtotalWithOutProduct({
|
1786
|
+
amount: String(
|
1787
|
+
initialTotal - Number(
|
1788
|
+
isHydrogenReact ? product?.selectedVariant?.price.amount : product?.selectedOrFirstAvailableVariant?.price.amount
|
1789
|
+
)
|
1790
|
+
),
|
1791
|
+
currencyCode
|
1792
|
+
});
|
1793
|
+
setAddedItems(products);
|
1794
|
+
if (includeMainProduct) {
|
1795
|
+
setAddedItems([convertToRebuyProduct(isHydrogenReact || false, product), ...products]);
|
1796
|
+
} else {
|
1797
|
+
setAddedItems(products);
|
1798
|
+
}
|
1799
|
+
}, [products, product, isHydrogenReact, includeMainProduct]);
|
1800
|
+
const handleChange = useCallback2(
|
1801
|
+
(event, product2) => {
|
1802
|
+
const newProducts = [...products];
|
1803
|
+
const productIndex = newProducts.findIndex((p) => p.id === product2.id);
|
1804
|
+
if (productIndex !== -1) {
|
1805
|
+
newProducts[productIndex] = {
|
1806
|
+
...newProducts[productIndex],
|
1807
|
+
selected: event.target.checked
|
1808
|
+
};
|
1809
|
+
product2.selected = event.target.checked;
|
1810
|
+
if (event.target.checked) {
|
1811
|
+
setAddedItems((prev) => [...prev, product2]);
|
1812
|
+
} else {
|
1813
|
+
setAddedItems((prev) => prev.filter((item) => item.id !== product2.id));
|
1814
|
+
}
|
1815
|
+
}
|
1816
|
+
},
|
1817
|
+
[products]
|
1818
|
+
);
|
1819
|
+
useEffect5(() => {
|
1820
|
+
let total = 0;
|
1821
|
+
let currencyCode = "USD";
|
1822
|
+
addedItems.forEach((item) => {
|
1823
|
+
if (item.selected && item.selectedVariant?.priceV2) {
|
1824
|
+
total += Number(item.selectedVariant.priceV2.amount);
|
1825
|
+
currencyCode = item.selectedVariant.priceV2.currencyCode || "USD";
|
1826
|
+
}
|
1827
|
+
});
|
1828
|
+
setSubtotalWithProduct({
|
1829
|
+
amount: String(total),
|
1830
|
+
currencyCode
|
1831
|
+
});
|
1832
|
+
setSubtotalWithOutProduct({
|
1833
|
+
amount: String(
|
1834
|
+
total - Number(
|
1835
|
+
isHydrogenReact ? product?.selectedVariant?.price.amount : product?.selectedOrFirstAvailableVariant?.price.amount
|
1836
|
+
)
|
1837
|
+
),
|
1838
|
+
currencyCode
|
1839
|
+
});
|
1840
|
+
}, [addedItems, product, isHydrogenReact]);
|
1841
|
+
if (products.length === 0) {
|
1842
|
+
console.log("RebuyProductAddOns: No products found");
|
1843
|
+
return null;
|
1844
|
+
}
|
1845
|
+
return /* @__PURE__ */ jsxs11("div", { className: RebuyProductAddOns_default.container, children: [
|
1846
|
+
/* @__PURE__ */ jsx17(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
|
1847
|
+
/* @__PURE__ */ jsx17("ul", { className: RebuyProductAddOns_default.productAddOnsList, children: products.map((product2) => /* @__PURE__ */ jsx17("li", { children: /* @__PURE__ */ jsx17(
|
1848
|
+
RebuyProductAddOnCard,
|
1849
|
+
{
|
1850
|
+
handleChange,
|
1851
|
+
learnMoreText,
|
1852
|
+
outOfStockText,
|
1853
|
+
product: product2,
|
1854
|
+
titleLevel: getTitleLevel(customTitleLevel, true)
|
1855
|
+
}
|
1856
|
+
) }, product2.id)) }),
|
1857
|
+
/* @__PURE__ */ jsxs11("div", { className: RebuyProductAddOns_default.productAddOnsFooter, children: [
|
1858
|
+
/* @__PURE__ */ jsxs11("div", { className: RebuyProductAddOns_default.moneyContainer, children: [
|
1859
|
+
subtotalText,
|
1860
|
+
subtotalWithOutProduct && /* @__PURE__ */ jsx17(Money5, { data: subtotalWithOutProduct, withoutTrailingZeros: true })
|
1861
|
+
] }),
|
1862
|
+
includeMainProduct && /* @__PURE__ */ jsxs11("div", { className: RebuyProductAddOns_default.moneyContainer, children: [
|
1863
|
+
withProductText,
|
1864
|
+
subtotalWithProduct && /* @__PURE__ */ jsx17(Money5, { data: subtotalWithProduct, withoutTrailingZeros: true })
|
1865
|
+
] }),
|
1866
|
+
/* @__PURE__ */ jsx17("div", { className: RebuyProductAddOns_default.addCartBtnContainer, children: includeMainProduct ? /* @__PURE__ */ jsx17(
|
1867
|
+
AddToCartBtn,
|
1868
|
+
{
|
1869
|
+
addToCartBtnText,
|
1870
|
+
addToCartCallback,
|
1871
|
+
disabled: addedItems.length === 0,
|
1872
|
+
isHydrogenReact,
|
1873
|
+
moneyData: subtotalWithProduct,
|
1874
|
+
selectedVariants: addedItems.map((item) => item.selectedVariant)
|
1875
|
+
}
|
1876
|
+
) : /* @__PURE__ */ jsx17(
|
1877
|
+
AddToCartBtn,
|
1878
|
+
{
|
1879
|
+
addToCartBtnText,
|
1880
|
+
addToCartCallback,
|
1881
|
+
disabled: addedItems.length === 0,
|
1882
|
+
isHydrogenReact,
|
1883
|
+
moneyData: subtotalWithOutProduct,
|
1884
|
+
selectedVariants: addedItems.map((item) => item.selectedVariant)
|
1885
|
+
}
|
1886
|
+
) })
|
1887
|
+
] })
|
1888
|
+
] });
|
1889
|
+
};
|
1890
|
+
|
1891
|
+
// src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.module.css
|
1892
|
+
var RebuyProductRecommendations_default = {
|
1893
|
+
container: "RebuyProductRecommendations_container",
|
1894
|
+
productGrid: "RebuyProductRecommendations_productGrid"
|
1895
|
+
};
|
1896
|
+
|
1897
|
+
// src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.tsx
|
1898
|
+
import { jsx as jsx18, jsxs as jsxs12 } from "react/jsx-runtime";
|
1899
|
+
var RebuyProductRecommendations = (props) => {
|
1900
|
+
const {
|
1901
|
+
addToCartBtnText = "Add to cart",
|
1902
|
+
addToCartCallback,
|
1903
|
+
customTitle = `These pair with ${props.product?.title}`,
|
1904
|
+
customTitleLevel = "h2",
|
1905
|
+
customTitleStyle,
|
1906
|
+
products = []
|
1907
|
+
} = props;
|
1908
|
+
if (products.length === 0) {
|
1909
|
+
console.log("RebuyProductRecommendations: No products found");
|
1910
|
+
return null;
|
1911
|
+
}
|
1912
|
+
return /* @__PURE__ */ jsxs12("section", { className: RebuyProductRecommendations_default.container, children: [
|
1913
|
+
/* @__PURE__ */ jsx18(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
|
1914
|
+
/* @__PURE__ */ jsx18("ul", { className: RebuyProductRecommendations_default.productGrid, children: products.map((product) => /* @__PURE__ */ jsx18("li", { className: RebuyProductRecommendations_default.productItem, children: /* @__PURE__ */ jsx18(
|
1915
|
+
ProductCard,
|
1916
|
+
{
|
1917
|
+
addToCartBtnText,
|
1918
|
+
addToCartCallback,
|
1919
|
+
isHydrogenReact: props.isHydrogenReact,
|
1920
|
+
product,
|
1921
|
+
productCardTitleLevel: getTitleLevel(customTitleLevel, true)
|
1922
|
+
}
|
1923
|
+
) }, product.id)) })
|
1924
|
+
] });
|
1925
|
+
};
|
1926
|
+
export {
|
1927
|
+
RebuyCompleteTheLook,
|
1928
|
+
RebuyDynamicBundleProducts,
|
1929
|
+
RebuyHydrogenContextProvider,
|
1930
|
+
RebuyHydrogenReactContextProvider,
|
1931
|
+
RebuyProductAddOns,
|
1932
|
+
RebuyProductRecommendations,
|
1933
|
+
RebuyWidgetContainer
|
1934
|
+
};
|
1935
|
+
//# sourceMappingURL=index.mjs.map
|