@brainerce/mcp-server 2.0.1 → 2.1.0
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/dist/bin/http.js +891 -14
- package/dist/bin/stdio.js +891 -14
- package/dist/index.js +891 -14
- package/dist/index.mjs +891 -14
- package/package.json +1 -1
package/dist/bin/http.js
CHANGED
|
@@ -732,27 +732,103 @@ const nudges: CartNudge[] = await client.getCartNudges(cartId);
|
|
|
732
732
|
Display: banners in header, badges on product cards (strikethrough + discounted price), nudges below cart totals, applied discounts as line items in order summary.`;
|
|
733
733
|
}
|
|
734
734
|
function getRecommendationsSection() {
|
|
735
|
-
return `## Product Recommendations
|
|
735
|
+
return `## Product Recommendations & Upsell Features
|
|
736
736
|
|
|
737
|
-
|
|
737
|
+
### Relation Types
|
|
738
|
+
- **Cross-sell**: Complementary products ("Bought a phone? Add a case") \u2014 shown on product page + cart
|
|
739
|
+
- **Upsell**: Premium alternatives ("Upgrade to Pro for $20 more") \u2014 shown on product page + cart upgrade banner
|
|
740
|
+
- **Related**: Similar products ("Other shirts in this collection") \u2014 shown on product page
|
|
741
|
+
|
|
742
|
+
### Product Page Recommendations
|
|
743
|
+
Recommendations come **embedded in the product response** \u2014 no extra API call needed.
|
|
738
744
|
|
|
739
745
|
\`\`\`typescript
|
|
740
|
-
import type { ProductRecommendation, ProductRecommendationsResponse
|
|
746
|
+
import type { ProductRecommendation, ProductRecommendationsResponse } from 'brainerce';
|
|
741
747
|
|
|
742
|
-
// Product page \u2014 recommendations are embedded in the product response
|
|
743
748
|
const product = await client.getProductBySlug('some-slug');
|
|
744
749
|
const recs = (product as any).recommendations as ProductRecommendationsResponse | undefined;
|
|
745
|
-
// recs?.upsells \u2014 premium alternatives (show on product page)
|
|
746
|
-
// recs?.related \u2014 similar products (show at bottom of product page)
|
|
747
|
-
// recs?.crossSells \u2014 complementary products (typically used on cart page)
|
|
748
750
|
|
|
749
|
-
//
|
|
750
|
-
|
|
751
|
+
// recs?.crossSells \u2014 complementary products \u2192 "Frequently Bought Together" section
|
|
752
|
+
// recs?.upsells \u2014 premium alternatives \u2192 "Upgrade Your Choice" section
|
|
753
|
+
// recs?.related \u2014 similar products \u2192 "Similar Products" section
|
|
754
|
+
\`\`\`
|
|
755
|
+
|
|
756
|
+
### Cart Page Features
|
|
757
|
+
|
|
758
|
+
**Cross-sell recommendations** (existing products the customer might also want):
|
|
759
|
+
\`\`\`typescript
|
|
760
|
+
import type { CartRecommendationsResponse } from 'brainerce';
|
|
761
|
+
const cartRecs = await client.getCartRecommendations(cartId, 4);
|
|
751
762
|
// cartRecs.recommendations \u2014 deduplicated cross-sells (excludes items already in cart)
|
|
752
763
|
\`\`\`
|
|
753
764
|
|
|
754
|
-
|
|
755
|
-
|
|
765
|
+
**Cart upgrade banner** (upsell relations with small price delta \u2014 "Upgrade to X for +$Y"):
|
|
766
|
+
\`\`\`typescript
|
|
767
|
+
import type { CartUpgradesResponse } from 'brainerce';
|
|
768
|
+
const { upgrades } = await client.getCartUpgrades(cartId);
|
|
769
|
+
// upgrades is a Record<sourceProductId, { targetProduct, priceDelta, deltaPercent }>
|
|
770
|
+
// Show inline banner per cart item if upgrade exists
|
|
771
|
+
\`\`\`
|
|
772
|
+
|
|
773
|
+
**Bundle offers** (discounted complementary products configured by the store owner):
|
|
774
|
+
\`\`\`typescript
|
|
775
|
+
import type { CartBundlesResponse } from 'brainerce';
|
|
776
|
+
const { bundles } = await client.getCartBundles(cartId);
|
|
777
|
+
// bundles[].bundleProduct \u2014 the product to offer
|
|
778
|
+
// bundles[].originalPrice / bundles[].discountedPrice \u2014 prices
|
|
779
|
+
// bundles[].discountType ('PERCENTAGE' | 'FIXED_AMOUNT') + discountValue
|
|
780
|
+
\`\`\`
|
|
781
|
+
|
|
782
|
+
**Free shipping progress bar** (configured threshold in channel settings):
|
|
783
|
+
\`\`\`typescript
|
|
784
|
+
const { storeInfo } = useStoreInfo(); // from store provider
|
|
785
|
+
const threshold = storeInfo?.upsell?.freeShippingThreshold;
|
|
786
|
+
const subtotal = parseFloat(cart.subtotal);
|
|
787
|
+
const remaining = threshold ? threshold - subtotal : 0;
|
|
788
|
+
const qualified = threshold ? subtotal >= threshold : false;
|
|
789
|
+
// Show progress bar: remaining > 0 ? "You're $X away from free shipping!" : "You've got free shipping!"
|
|
790
|
+
\`\`\`
|
|
791
|
+
|
|
792
|
+
### Checkout Features
|
|
793
|
+
|
|
794
|
+
**Order bumps** (one-click add-ons at checkout):
|
|
795
|
+
\`\`\`typescript
|
|
796
|
+
import type { CheckoutBumpsResponse } from 'brainerce';
|
|
797
|
+
const { bumps } = await client.getCheckoutBumps(checkoutId);
|
|
798
|
+
// bumps[].bumpProduct \u2014 product to offer
|
|
799
|
+
// bumps[].originalPrice / discountedPrice \u2014 with optional discount
|
|
800
|
+
// bumps[].title / description \u2014 display text
|
|
801
|
+
|
|
802
|
+
// Add a bump to cart:
|
|
803
|
+
await client.addOrderBump(cartId, bumpId);
|
|
804
|
+
// Remove a bump:
|
|
805
|
+
await client.removeOrderBump(cartId, bumpId);
|
|
806
|
+
// Detect already-added bumps: check cart.items for metadata?.isOrderBump === true
|
|
807
|
+
\`\`\`
|
|
808
|
+
|
|
809
|
+
### Feature Flags (per-channel)
|
|
810
|
+
All upsell features are controlled by \`storeInfo.upsell.*\`:
|
|
811
|
+
- \`freeShippingBarEnabled\` \u2014 free shipping progress bar in cart
|
|
812
|
+
- \`frequentlyBoughtTogetherEnabled\` \u2014 cross-sell section on product page
|
|
813
|
+
- \`cartUpgradeBannerEnabled\` \u2014 upgrade banner per cart item
|
|
814
|
+
- \`cartBundleEnabled\` \u2014 bundle offers in cart
|
|
815
|
+
- \`checkoutOrderBumpEnabled\` \u2014 order bumps at checkout
|
|
816
|
+
- \`freeShippingThreshold\` \u2014 threshold amount for free shipping bar
|
|
817
|
+
|
|
818
|
+
Always check the flag before rendering: \`if (storeInfo?.upsell?.featureName !== false)\`
|
|
819
|
+
|
|
820
|
+
### Components Reference
|
|
821
|
+
| Component | Location | Purpose |
|
|
822
|
+
|-----------|----------|---------|
|
|
823
|
+
| FrequentlyBoughtTogether | products/ | Cross-sells with "Add all to cart" on product page |
|
|
824
|
+
| RecommendationSection | products/ | Grid of upsells or related products on product page |
|
|
825
|
+
| CartRecommendationSection | products/ | Cross-sell grid at bottom of cart page |
|
|
826
|
+
| FreeShippingBar | cart/ | Progress bar toward free shipping threshold |
|
|
827
|
+
| CartUpgradeBanner | cart/ | Inline "Upgrade to X for +$Y" per cart item |
|
|
828
|
+
| CartBundleOfferCard | cart/ | Discounted bundle offer card in cart |
|
|
829
|
+
| OrderBumpCard | checkout/ | Checkbox add-on card in checkout sidebar |
|
|
830
|
+
|
|
831
|
+
ProductRecommendation: \`id\`, \`name\`, \`slug\`, \`basePrice\`, \`salePrice\`, \`images\`, \`type\`, \`inventory\`, \`relationType\`.`;
|
|
756
832
|
}
|
|
757
833
|
function getInventorySection() {
|
|
758
834
|
return `## Inventory, Stock Display & Reservation Countdown
|
|
@@ -2925,13 +3001,17 @@ export default async function ProductDetailPage({ params }: Props) {
|
|
|
2925
3001
|
|
|
2926
3002
|
import { useEffect, useState } from 'react';
|
|
2927
3003
|
import Link from 'next/link';
|
|
2928
|
-
import type { CartRecommendationsResponse } from 'brainerce';
|
|
3004
|
+
import type { CartRecommendationsResponse, CartUpgradesResponse, CartBundlesResponse } from 'brainerce';
|
|
2929
3005
|
import { getClient } from '@/lib/brainerce';
|
|
2930
3006
|
import { useCart } from '@/providers/store-provider';
|
|
3007
|
+
import { useStoreInfo } from '@/providers/store-provider';
|
|
2931
3008
|
import { CartItem } from '@/components/cart/cart-item';
|
|
3009
|
+
import { CartUpgradeBanner } from '@/components/cart/cart-upgrade-banner';
|
|
3010
|
+
import { CartBundleOfferCard } from '@/components/cart/cart-bundle-offer';
|
|
2932
3011
|
import { CartSummary } from '@/components/cart/cart-summary';
|
|
2933
3012
|
import { CouponInput } from '@/components/cart/coupon-input';
|
|
2934
3013
|
import { CartNudges } from '@/components/cart/cart-nudges';
|
|
3014
|
+
import { FreeShippingBar } from '@/components/cart/free-shipping-bar';
|
|
2935
3015
|
import { ReservationCountdown } from '@/components/cart/reservation-countdown';
|
|
2936
3016
|
import { CartRecommendationSection } from '@/components/products/recommendation-section';
|
|
2937
3017
|
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
@@ -2939,9 +3019,12 @@ import { useTranslations } from '@/lib/translations';
|
|
|
2939
3019
|
|
|
2940
3020
|
export default function CartPage() {
|
|
2941
3021
|
const { cart, cartLoading, refreshCart, itemCount } = useCart();
|
|
3022
|
+
const { storeInfo } = useStoreInfo();
|
|
2942
3023
|
const t = useTranslations('cart');
|
|
2943
3024
|
const tc = useTranslations('common');
|
|
2944
3025
|
const [cartRecs, setCartRecs] = useState<CartRecommendationsResponse | null>(null);
|
|
3026
|
+
const [upgrades, setUpgrades] = useState<CartUpgradesResponse | null>(null);
|
|
3027
|
+
const [bundles, setBundles] = useState<CartBundlesResponse | null>(null);
|
|
2945
3028
|
|
|
2946
3029
|
// Load cross-sell recommendations when cart changes
|
|
2947
3030
|
useEffect(() => {
|
|
@@ -2956,6 +3039,32 @@ export default function CartPage() {
|
|
|
2956
3039
|
.catch(() => {});
|
|
2957
3040
|
}, [cart?.id, cart?.items.length]);
|
|
2958
3041
|
|
|
3042
|
+
// Load upgrade suggestions when cart changes
|
|
3043
|
+
useEffect(() => {
|
|
3044
|
+
if (!cart?.id || cart.items.length === 0 || storeInfo?.upsell?.cartUpgradeBannerEnabled === false) {
|
|
3045
|
+
setUpgrades(null);
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
const client = getClient();
|
|
3049
|
+
client
|
|
3050
|
+
.getCartUpgrades(cart.id)
|
|
3051
|
+
.then(setUpgrades)
|
|
3052
|
+
.catch(() => {});
|
|
3053
|
+
}, [cart?.id, cart?.items.length, storeInfo?.upsell?.cartUpgradeBannerEnabled]);
|
|
3054
|
+
|
|
3055
|
+
// Load bundle offers when cart changes
|
|
3056
|
+
useEffect(() => {
|
|
3057
|
+
if (!cart?.id || cart.items.length === 0 || storeInfo?.upsell?.cartBundleEnabled === false) {
|
|
3058
|
+
setBundles(null);
|
|
3059
|
+
return;
|
|
3060
|
+
}
|
|
3061
|
+
const client = getClient();
|
|
3062
|
+
client
|
|
3063
|
+
.getCartBundles(cart.id)
|
|
3064
|
+
.then(setBundles)
|
|
3065
|
+
.catch(() => {});
|
|
3066
|
+
}, [cart?.id, cart?.items.length, storeInfo?.upsell?.cartBundleEnabled]);
|
|
3067
|
+
|
|
2959
3068
|
if (cartLoading) {
|
|
2960
3069
|
return (
|
|
2961
3070
|
<div className="flex min-h-[60vh] items-center justify-center">
|
|
@@ -3015,10 +3124,30 @@ export default function CartPage() {
|
|
|
3015
3124
|
{/* Cart items */}
|
|
3016
3125
|
<div>
|
|
3017
3126
|
{cart.items.map((item) => (
|
|
3018
|
-
<
|
|
3127
|
+
<div key={item.id}>
|
|
3128
|
+
<CartItem item={item} onUpdate={refreshCart} />
|
|
3129
|
+
{upgrades?.upgrades?.[item.productId] && (
|
|
3130
|
+
<CartUpgradeBanner
|
|
3131
|
+
suggestion={upgrades.upgrades[item.productId]}
|
|
3132
|
+
cartItem={item}
|
|
3133
|
+
onUpgrade={refreshCart}
|
|
3134
|
+
className="mb-2 ms-24"
|
|
3135
|
+
/>
|
|
3136
|
+
)}
|
|
3137
|
+
</div>
|
|
3019
3138
|
))}
|
|
3020
3139
|
</div>
|
|
3021
3140
|
|
|
3141
|
+
{/* Bundle offers */}
|
|
3142
|
+
{bundles?.bundles && bundles.bundles.length > 0 && (
|
|
3143
|
+
<div className="mt-6 space-y-3">
|
|
3144
|
+
<h3 className="text-foreground text-sm font-semibold">{t('bundleOffers')}</h3>
|
|
3145
|
+
{bundles.bundles.map((offer) => (
|
|
3146
|
+
<CartBundleOfferCard key={offer.id} offer={offer} onAdd={refreshCart} />
|
|
3147
|
+
))}
|
|
3148
|
+
</div>
|
|
3149
|
+
)}
|
|
3150
|
+
|
|
3022
3151
|
{/* Coupon input */}
|
|
3023
3152
|
<div className="border-border mt-6 border-t pt-4">
|
|
3024
3153
|
<CouponInput cart={cart} onUpdate={refreshCart} />
|
|
@@ -3028,6 +3157,7 @@ export default function CartPage() {
|
|
|
3028
3157
|
{/* Summary sidebar */}
|
|
3029
3158
|
<div className="lg:col-span-1">
|
|
3030
3159
|
<div className="bg-muted/50 border-border sticky top-24 rounded-lg border p-6">
|
|
3160
|
+
<FreeShippingBar className="mb-4" />
|
|
3031
3161
|
<CartSummary />
|
|
3032
3162
|
|
|
3033
3163
|
<Link
|
|
@@ -3071,6 +3201,7 @@ import type {
|
|
|
3071
3201
|
SetShippingAddressDto,
|
|
3072
3202
|
ShippingDestinations,
|
|
3073
3203
|
PickupLocation,
|
|
3204
|
+
CheckoutBumpsResponse,
|
|
3074
3205
|
} from 'brainerce';
|
|
3075
3206
|
import { formatPrice } from 'brainerce';
|
|
3076
3207
|
import { getClient } from '@/lib/brainerce';
|
|
@@ -3081,6 +3212,7 @@ import { PaymentStep } from '@/components/checkout/payment-step';
|
|
|
3081
3212
|
import { DeliveryMethodStep } from '@/components/checkout/delivery-method-step';
|
|
3082
3213
|
import { PickupStep } from '@/components/checkout/pickup-step';
|
|
3083
3214
|
import { TaxDisplay } from '@/components/checkout/tax-display';
|
|
3215
|
+
import { OrderBumpCard } from '@/components/checkout/order-bump-card';
|
|
3084
3216
|
import { CouponInput } from '@/components/cart/coupon-input';
|
|
3085
3217
|
import { ReservationCountdown } from '@/components/cart/reservation-countdown';
|
|
3086
3218
|
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
@@ -3117,6 +3249,9 @@ function CheckoutContent() {
|
|
|
3117
3249
|
phone?: string;
|
|
3118
3250
|
} | null>(null);
|
|
3119
3251
|
const [hasSavedAddress, setHasSavedAddress] = useState(false);
|
|
3252
|
+
const [orderBumps, setOrderBumps] = useState<CheckoutBumpsResponse | null>(null);
|
|
3253
|
+
const [addedBumpIds, setAddedBumpIds] = useState<Set<string>>(new Set());
|
|
3254
|
+
const [bumpLoading, setBumpLoading] = useState<string | null>(null);
|
|
3120
3255
|
|
|
3121
3256
|
// Check for returning from canceled payment
|
|
3122
3257
|
const canceled = searchParams.get('canceled') === 'true';
|
|
@@ -3219,9 +3354,59 @@ function CheckoutContent() {
|
|
|
3219
3354
|
};
|
|
3220
3355
|
|
|
3221
3356
|
initCheckout();
|
|
3222
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3223
3357
|
}, [cart?.id, existingCheckoutId]);
|
|
3224
3358
|
|
|
3359
|
+
// Load order bumps when checkout is available
|
|
3360
|
+
useEffect(() => {
|
|
3361
|
+
if (!checkout?.id || storeInfo?.upsell?.checkoutOrderBumpEnabled === false) {
|
|
3362
|
+
setOrderBumps(null);
|
|
3363
|
+
return;
|
|
3364
|
+
}
|
|
3365
|
+
const client = getClient();
|
|
3366
|
+
client
|
|
3367
|
+
.getCheckoutBumps(checkout.id)
|
|
3368
|
+
.then((data) => {
|
|
3369
|
+
setOrderBumps(data);
|
|
3370
|
+
// Detect already-added bumps from cart
|
|
3371
|
+
if (cart?.items) {
|
|
3372
|
+
const existingBumpIds = new Set<string>();
|
|
3373
|
+
for (const item of cart.items) {
|
|
3374
|
+
const meta = item.metadata as Record<string, unknown> | undefined;
|
|
3375
|
+
if (meta?.isOrderBump && meta?.orderBumpId) {
|
|
3376
|
+
existingBumpIds.add(meta.orderBumpId as string);
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
setAddedBumpIds(existingBumpIds);
|
|
3380
|
+
}
|
|
3381
|
+
})
|
|
3382
|
+
.catch(() => {});
|
|
3383
|
+
}, [checkout?.id, storeInfo?.upsell?.checkoutOrderBumpEnabled]);
|
|
3384
|
+
|
|
3385
|
+
// Handle bump toggle
|
|
3386
|
+
async function handleBumpToggle(bumpId: string, add: boolean) {
|
|
3387
|
+
if (!cart?.id || bumpLoading) return;
|
|
3388
|
+
try {
|
|
3389
|
+
setBumpLoading(bumpId);
|
|
3390
|
+
const client = getClient();
|
|
3391
|
+
if (add) {
|
|
3392
|
+
await client.addOrderBump(cart.id, bumpId);
|
|
3393
|
+
setAddedBumpIds((prev) => new Set([...prev, bumpId]));
|
|
3394
|
+
} else {
|
|
3395
|
+
await client.removeOrderBump(cart.id, bumpId);
|
|
3396
|
+
setAddedBumpIds((prev) => {
|
|
3397
|
+
const next = new Set(prev);
|
|
3398
|
+
next.delete(bumpId);
|
|
3399
|
+
return next;
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
await refreshCart();
|
|
3403
|
+
} catch (err) {
|
|
3404
|
+
console.error('Failed to toggle order bump:', err);
|
|
3405
|
+
} finally {
|
|
3406
|
+
setBumpLoading(null);
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3225
3410
|
// Handle shipping address submission
|
|
3226
3411
|
async function handleAddressSubmit(
|
|
3227
3412
|
address: SetShippingAddressDto,
|
|
@@ -3724,6 +3909,24 @@ function CheckoutContent() {
|
|
|
3724
3909
|
)
|
|
3725
3910
|
)}
|
|
3726
3911
|
|
|
3912
|
+
{/* Order bumps */}
|
|
3913
|
+
{orderBumps?.bumps && orderBumps.bumps.length > 0 && (
|
|
3914
|
+
<div className="border-border space-y-2 border-t pt-4">
|
|
3915
|
+
<p className="text-foreground text-xs font-semibold uppercase tracking-wide">
|
|
3916
|
+
{t('addToYourOrder')}
|
|
3917
|
+
</p>
|
|
3918
|
+
{orderBumps.bumps.map((bump) => (
|
|
3919
|
+
<OrderBumpCard
|
|
3920
|
+
key={bump.id}
|
|
3921
|
+
bump={bump}
|
|
3922
|
+
isAdded={addedBumpIds.has(bump.id)}
|
|
3923
|
+
onToggle={handleBumpToggle}
|
|
3924
|
+
loading={bumpLoading === bump.id}
|
|
3925
|
+
/>
|
|
3926
|
+
))}
|
|
3927
|
+
</div>
|
|
3928
|
+
)}
|
|
3929
|
+
|
|
3727
3930
|
{/* Coupon input \u2014 show from shipping/pickup step onwards (or immediately if digital) */}
|
|
3728
3931
|
{cart &&
|
|
3729
3932
|
(isAllDigital || step === 'shipping' || step === 'pickup' || step === 'payment') && (
|
|
@@ -9195,6 +9398,680 @@ export function LoadingSpinner({ size = 'md', className }: LoadingSpinnerProps)
|
|
|
9195
9398
|
</div>
|
|
9196
9399
|
);
|
|
9197
9400
|
}
|
|
9401
|
+
`,
|
|
9402
|
+
"src/components/products/recommendation-section.tsx": `'use client';
|
|
9403
|
+
|
|
9404
|
+
import { useEffect, useState } from 'react';
|
|
9405
|
+
import Link from 'next/link';
|
|
9406
|
+
import Image from 'next/image';
|
|
9407
|
+
import type { ProductRecommendation } from 'brainerce';
|
|
9408
|
+
import { PriceDisplay } from '@/components/shared/price-display';
|
|
9409
|
+
import { cn } from '@/lib/utils';
|
|
9410
|
+
|
|
9411
|
+
interface RecommendationCardProps {
|
|
9412
|
+
item: ProductRecommendation;
|
|
9413
|
+
className?: string;
|
|
9414
|
+
}
|
|
9415
|
+
|
|
9416
|
+
function RecommendationCard({ item, className }: RecommendationCardProps) {
|
|
9417
|
+
const firstImage = item.images?.[0];
|
|
9418
|
+
const imageUrl = typeof firstImage === 'string' ? firstImage : firstImage?.url || null;
|
|
9419
|
+
const slug = item.slug || item.id;
|
|
9420
|
+
const basePrice = parseFloat(item.basePrice);
|
|
9421
|
+
const salePrice = item.salePrice ? parseFloat(item.salePrice) : undefined;
|
|
9422
|
+
const isOnSale = salePrice != null && salePrice < basePrice;
|
|
9423
|
+
|
|
9424
|
+
return (
|
|
9425
|
+
<Link
|
|
9426
|
+
href={\`/products/\${slug}\`}
|
|
9427
|
+
className={cn(
|
|
9428
|
+
'border-border bg-background group block overflow-hidden rounded-lg border transition-shadow hover:shadow-md',
|
|
9429
|
+
className
|
|
9430
|
+
)}
|
|
9431
|
+
>
|
|
9432
|
+
<div className="bg-muted relative aspect-square overflow-hidden">
|
|
9433
|
+
{imageUrl ? (
|
|
9434
|
+
<Image
|
|
9435
|
+
src={imageUrl}
|
|
9436
|
+
alt={item.name}
|
|
9437
|
+
fill
|
|
9438
|
+
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 33vw, 20vw"
|
|
9439
|
+
className="object-cover transition-transform duration-300 group-hover:scale-105"
|
|
9440
|
+
/>
|
|
9441
|
+
) : (
|
|
9442
|
+
<div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
|
|
9443
|
+
<svg className="h-10 w-10" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
9444
|
+
<path
|
|
9445
|
+
strokeLinecap="round"
|
|
9446
|
+
strokeLinejoin="round"
|
|
9447
|
+
strokeWidth={1.5}
|
|
9448
|
+
d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
|
|
9449
|
+
/>
|
|
9450
|
+
</svg>
|
|
9451
|
+
</div>
|
|
9452
|
+
)}
|
|
9453
|
+
</div>
|
|
9454
|
+
<div className="space-y-1.5 p-3">
|
|
9455
|
+
<h3 className="text-foreground group-hover:text-primary line-clamp-2 text-sm font-medium transition-colors">
|
|
9456
|
+
{item.name}
|
|
9457
|
+
</h3>
|
|
9458
|
+
<PriceDisplay price={basePrice} salePrice={isOnSale ? salePrice : undefined} size="sm" />
|
|
9459
|
+
</div>
|
|
9460
|
+
</Link>
|
|
9461
|
+
);
|
|
9462
|
+
}
|
|
9463
|
+
|
|
9464
|
+
interface RecommendationSectionProps {
|
|
9465
|
+
title: string;
|
|
9466
|
+
items: ProductRecommendation[];
|
|
9467
|
+
className?: string;
|
|
9468
|
+
}
|
|
9469
|
+
|
|
9470
|
+
export function RecommendationSection({ title, items, className }: RecommendationSectionProps) {
|
|
9471
|
+
if (items.length === 0) return null;
|
|
9472
|
+
|
|
9473
|
+
return (
|
|
9474
|
+
<div className={cn('', className)}>
|
|
9475
|
+
<h2 className="text-foreground mb-4 text-xl font-semibold">{title}</h2>
|
|
9476
|
+
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4">
|
|
9477
|
+
{items.map((item) => (
|
|
9478
|
+
<RecommendationCard key={item.id} item={item} />
|
|
9479
|
+
))}
|
|
9480
|
+
</div>
|
|
9481
|
+
</div>
|
|
9482
|
+
);
|
|
9483
|
+
}
|
|
9484
|
+
|
|
9485
|
+
interface CartRecommendationSectionProps {
|
|
9486
|
+
title: string;
|
|
9487
|
+
items: ProductRecommendation[];
|
|
9488
|
+
className?: string;
|
|
9489
|
+
}
|
|
9490
|
+
|
|
9491
|
+
export function CartRecommendationSection({
|
|
9492
|
+
title,
|
|
9493
|
+
items,
|
|
9494
|
+
className,
|
|
9495
|
+
}: CartRecommendationSectionProps) {
|
|
9496
|
+
if (items.length === 0) return null;
|
|
9497
|
+
|
|
9498
|
+
return (
|
|
9499
|
+
<div className={cn('', className)}>
|
|
9500
|
+
<h2 className="text-foreground mb-4 text-lg font-semibold">{title}</h2>
|
|
9501
|
+
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
|
|
9502
|
+
{items.map((item) => (
|
|
9503
|
+
<RecommendationCard key={item.id} item={item} />
|
|
9504
|
+
))}
|
|
9505
|
+
</div>
|
|
9506
|
+
</div>
|
|
9507
|
+
);
|
|
9508
|
+
}
|
|
9509
|
+
`,
|
|
9510
|
+
"src/components/products/frequently-bought-together.tsx": `'use client';
|
|
9511
|
+
|
|
9512
|
+
import { useState } from 'react';
|
|
9513
|
+
import Image from 'next/image';
|
|
9514
|
+
import type { Product, ProductRecommendation } from 'brainerce';
|
|
9515
|
+
import { formatPrice } from 'brainerce';
|
|
9516
|
+
import { useCart } from '@/providers/store-provider';
|
|
9517
|
+
import { useStoreInfo } from '@/providers/store-provider';
|
|
9518
|
+
import { useTranslations } from '@/lib/translations';
|
|
9519
|
+
import { cn } from '@/lib/utils';
|
|
9520
|
+
|
|
9521
|
+
interface FrequentlyBoughtTogetherProps {
|
|
9522
|
+
items: ProductRecommendation[];
|
|
9523
|
+
currentProduct: Product;
|
|
9524
|
+
className?: string;
|
|
9525
|
+
}
|
|
9526
|
+
|
|
9527
|
+
function getEffectivePrice(item: { basePrice: string; salePrice?: string | null }): number {
|
|
9528
|
+
const sale = item.salePrice ? parseFloat(item.salePrice) : null;
|
|
9529
|
+
const base = parseFloat(item.basePrice);
|
|
9530
|
+
return sale != null && sale < base ? sale : base;
|
|
9531
|
+
}
|
|
9532
|
+
|
|
9533
|
+
function ProductThumb({
|
|
9534
|
+
name,
|
|
9535
|
+
imageUrl,
|
|
9536
|
+
price,
|
|
9537
|
+
currency,
|
|
9538
|
+
checked,
|
|
9539
|
+
onToggle,
|
|
9540
|
+
disabled,
|
|
9541
|
+
}: {
|
|
9542
|
+
name: string;
|
|
9543
|
+
imageUrl: string | null;
|
|
9544
|
+
price: number;
|
|
9545
|
+
currency: string;
|
|
9546
|
+
checked: boolean;
|
|
9547
|
+
onToggle?: () => void;
|
|
9548
|
+
disabled?: boolean;
|
|
9549
|
+
}) {
|
|
9550
|
+
return (
|
|
9551
|
+
<label
|
|
9552
|
+
className={cn(
|
|
9553
|
+
'border-border bg-background relative flex cursor-pointer flex-col items-center rounded-lg border p-3 transition-all',
|
|
9554
|
+
checked ? 'ring-primary ring-2' : 'opacity-60',
|
|
9555
|
+
disabled && 'pointer-events-none'
|
|
9556
|
+
)}
|
|
9557
|
+
>
|
|
9558
|
+
{onToggle && (
|
|
9559
|
+
<input
|
|
9560
|
+
type="checkbox"
|
|
9561
|
+
checked={checked}
|
|
9562
|
+
onChange={onToggle}
|
|
9563
|
+
className="absolute start-2 top-2 h-4 w-4 rounded"
|
|
9564
|
+
/>
|
|
9565
|
+
)}
|
|
9566
|
+
<div className="bg-muted relative mb-2 h-20 w-20 overflow-hidden rounded">
|
|
9567
|
+
{imageUrl ? (
|
|
9568
|
+
<Image src={imageUrl} alt={name} fill sizes="80px" className="object-cover" />
|
|
9569
|
+
) : (
|
|
9570
|
+
<div className="flex h-full w-full items-center justify-center">
|
|
9571
|
+
<svg className="text-muted-foreground h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
9572
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
|
9573
|
+
</svg>
|
|
9574
|
+
</div>
|
|
9575
|
+
)}
|
|
9576
|
+
</div>
|
|
9577
|
+
<span className="text-foreground line-clamp-2 text-center text-xs font-medium">{name}</span>
|
|
9578
|
+
<span className="text-muted-foreground mt-1 text-xs">
|
|
9579
|
+
{formatPrice(price, { currency }) as string}
|
|
9580
|
+
</span>
|
|
9581
|
+
</label>
|
|
9582
|
+
);
|
|
9583
|
+
}
|
|
9584
|
+
|
|
9585
|
+
export function FrequentlyBoughtTogether({
|
|
9586
|
+
items,
|
|
9587
|
+
currentProduct,
|
|
9588
|
+
className,
|
|
9589
|
+
}: FrequentlyBoughtTogetherProps) {
|
|
9590
|
+
const { storeInfo } = useStoreInfo();
|
|
9591
|
+
const { refreshCart } = useCart();
|
|
9592
|
+
const t = useTranslations('productDetail');
|
|
9593
|
+
|
|
9594
|
+
// Only show up to 3 cross-sells
|
|
9595
|
+
const crossSells = items.slice(0, 3);
|
|
9596
|
+
|
|
9597
|
+
const [selected, setSelected] = useState<Set<string>>(() => new Set(crossSells.map((i) => i.id)));
|
|
9598
|
+
const [adding, setAdding] = useState(false);
|
|
9599
|
+
|
|
9600
|
+
if (!storeInfo?.upsell?.frequentlyBoughtTogetherEnabled) return null;
|
|
9601
|
+
if (crossSells.length === 0) return null;
|
|
9602
|
+
|
|
9603
|
+
const currency = storeInfo.currency || 'USD';
|
|
9604
|
+
|
|
9605
|
+
const currentPrice = getEffectivePrice(currentProduct);
|
|
9606
|
+
const currentImage = currentProduct.images?.[0];
|
|
9607
|
+
const currentImageUrl = currentImage
|
|
9608
|
+
? typeof currentImage === 'string'
|
|
9609
|
+
? currentImage
|
|
9610
|
+
: currentImage.url
|
|
9611
|
+
: null;
|
|
9612
|
+
|
|
9613
|
+
const totalPrice = crossSells
|
|
9614
|
+
.filter((item) => selected.has(item.id))
|
|
9615
|
+
.reduce((sum, item) => sum + getEffectivePrice(item), currentPrice);
|
|
9616
|
+
|
|
9617
|
+
const toggleItem = (id: string) => {
|
|
9618
|
+
setSelected((prev) => {
|
|
9619
|
+
const next = new Set(prev);
|
|
9620
|
+
if (next.has(id)) {
|
|
9621
|
+
next.delete(id);
|
|
9622
|
+
} else {
|
|
9623
|
+
next.add(id);
|
|
9624
|
+
}
|
|
9625
|
+
return next;
|
|
9626
|
+
});
|
|
9627
|
+
};
|
|
9628
|
+
|
|
9629
|
+
async function handleAddAll() {
|
|
9630
|
+
if (adding || selected.size === 0) return;
|
|
9631
|
+
try {
|
|
9632
|
+
setAdding(true);
|
|
9633
|
+
const { getClient } = await import('@/lib/brainerce');
|
|
9634
|
+
const client = getClient();
|
|
9635
|
+
const selectedItems = crossSells.filter((item) => selected.has(item.id));
|
|
9636
|
+
for (const item of selectedItems) {
|
|
9637
|
+
await client.smartAddToCart({ productId: item.id, quantity: 1 });
|
|
9638
|
+
}
|
|
9639
|
+
await refreshCart();
|
|
9640
|
+
} catch (err) {
|
|
9641
|
+
console.error('Failed to add items to cart:', err);
|
|
9642
|
+
} finally {
|
|
9643
|
+
setAdding(false);
|
|
9644
|
+
}
|
|
9645
|
+
}
|
|
9646
|
+
|
|
9647
|
+
return (
|
|
9648
|
+
<div className={cn('border-border rounded-lg border p-6', className)}>
|
|
9649
|
+
<h2 className="text-foreground mb-4 text-xl font-semibold">{t('frequentlyBoughtTogether')}</h2>
|
|
9650
|
+
|
|
9651
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
9652
|
+
{/* Current product (always included, no checkbox) */}
|
|
9653
|
+
<ProductThumb
|
|
9654
|
+
name={currentProduct.name}
|
|
9655
|
+
imageUrl={currentImageUrl}
|
|
9656
|
+
price={currentPrice}
|
|
9657
|
+
currency={currency}
|
|
9658
|
+
checked={true}
|
|
9659
|
+
disabled
|
|
9660
|
+
/>
|
|
9661
|
+
|
|
9662
|
+
{crossSells.map((item) => {
|
|
9663
|
+
const img = item.images?.[0];
|
|
9664
|
+
const imgUrl = img ? (typeof img === 'string' ? img : img.url) : null;
|
|
9665
|
+
return (
|
|
9666
|
+
<div key={item.id} className="flex items-center gap-3">
|
|
9667
|
+
<span className="text-muted-foreground text-lg font-light">+</span>
|
|
9668
|
+
<ProductThumb
|
|
9669
|
+
name={item.name}
|
|
9670
|
+
imageUrl={imgUrl}
|
|
9671
|
+
price={getEffectivePrice(item)}
|
|
9672
|
+
currency={currency}
|
|
9673
|
+
checked={selected.has(item.id)}
|
|
9674
|
+
onToggle={() => toggleItem(item.id)}
|
|
9675
|
+
/>
|
|
9676
|
+
</div>
|
|
9677
|
+
);
|
|
9678
|
+
})}
|
|
9679
|
+
</div>
|
|
9680
|
+
|
|
9681
|
+
{/* Total + Add button */}
|
|
9682
|
+
<div className="mt-4 flex flex-wrap items-center gap-4">
|
|
9683
|
+
<span className="text-foreground text-lg font-semibold">
|
|
9684
|
+
{t('totalPrice', { price: formatPrice(totalPrice, { currency }) as string })}
|
|
9685
|
+
</span>
|
|
9686
|
+
<button
|
|
9687
|
+
onClick={handleAddAll}
|
|
9688
|
+
disabled={adding || selected.size === 0}
|
|
9689
|
+
className={cn(
|
|
9690
|
+
'bg-primary text-primary-foreground rounded px-5 py-2.5 text-sm font-medium transition-opacity hover:opacity-90',
|
|
9691
|
+
'disabled:cursor-not-allowed disabled:opacity-50'
|
|
9692
|
+
)}
|
|
9693
|
+
>
|
|
9694
|
+
{adding ? t('addingAll') : t('addSelectedToCart')}
|
|
9695
|
+
</button>
|
|
9696
|
+
</div>
|
|
9697
|
+
</div>
|
|
9698
|
+
);
|
|
9699
|
+
}
|
|
9700
|
+
`,
|
|
9701
|
+
"src/components/cart/free-shipping-bar.tsx": `'use client';
|
|
9702
|
+
|
|
9703
|
+
import { formatPrice } from 'brainerce';
|
|
9704
|
+
import { useStoreInfo, useCart } from '@/providers/store-provider';
|
|
9705
|
+
import { useTranslations } from '@/lib/translations';
|
|
9706
|
+
import { cn } from '@/lib/utils';
|
|
9707
|
+
|
|
9708
|
+
interface FreeShippingBarProps {
|
|
9709
|
+
className?: string;
|
|
9710
|
+
}
|
|
9711
|
+
|
|
9712
|
+
export function FreeShippingBar({ className }: FreeShippingBarProps) {
|
|
9713
|
+
const t = useTranslations('cart');
|
|
9714
|
+
const { storeInfo } = useStoreInfo();
|
|
9715
|
+
const { totals } = useCart();
|
|
9716
|
+
|
|
9717
|
+
const upsell = storeInfo?.upsell;
|
|
9718
|
+
const threshold = upsell?.freeShippingThreshold;
|
|
9719
|
+
const enabled = upsell?.freeShippingBarEnabled !== false;
|
|
9720
|
+
|
|
9721
|
+
// Don't render if disabled or no threshold configured
|
|
9722
|
+
if (!enabled || !threshold || threshold <= 0) return null;
|
|
9723
|
+
|
|
9724
|
+
const subtotal = totals.subtotal;
|
|
9725
|
+
const remaining = Math.max(0, threshold - subtotal);
|
|
9726
|
+
const progress = Math.min(100, (subtotal / threshold) * 100);
|
|
9727
|
+
const qualified = remaining <= 0;
|
|
9728
|
+
const currency = storeInfo?.currency || 'USD';
|
|
9729
|
+
|
|
9730
|
+
// Don't show if already qualified
|
|
9731
|
+
if (qualified) {
|
|
9732
|
+
return (
|
|
9733
|
+
<div className={cn('rounded-lg border border-green-200 bg-green-50 p-3', className)}>
|
|
9734
|
+
<div className="flex items-center gap-2 text-sm font-medium text-green-700">
|
|
9735
|
+
<svg className="h-4 w-4 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
9736
|
+
<path
|
|
9737
|
+
strokeLinecap="round"
|
|
9738
|
+
strokeLinejoin="round"
|
|
9739
|
+
strokeWidth={2}
|
|
9740
|
+
d="M5 13l4 4L19 7"
|
|
9741
|
+
/>
|
|
9742
|
+
</svg>
|
|
9743
|
+
{t('freeShippingQualified')}
|
|
9744
|
+
</div>
|
|
9745
|
+
</div>
|
|
9746
|
+
);
|
|
9747
|
+
}
|
|
9748
|
+
|
|
9749
|
+
return (
|
|
9750
|
+
<div className={cn('rounded-lg border border-amber-200 bg-amber-50 p-3', className)}>
|
|
9751
|
+
<p className="mb-2 text-sm text-amber-800">
|
|
9752
|
+
{t('freeShippingRemaining', {
|
|
9753
|
+
amount: formatPrice(remaining, { currency }) as string,
|
|
9754
|
+
})}
|
|
9755
|
+
</p>
|
|
9756
|
+
<div className="h-2 w-full overflow-hidden rounded-full bg-amber-200">
|
|
9757
|
+
<div
|
|
9758
|
+
className="h-full rounded-full bg-amber-500 transition-all duration-500 ease-out"
|
|
9759
|
+
style={{ width: \`\${progress}%\` }}
|
|
9760
|
+
/>
|
|
9761
|
+
</div>
|
|
9762
|
+
</div>
|
|
9763
|
+
);
|
|
9764
|
+
}
|
|
9765
|
+
`,
|
|
9766
|
+
"src/components/cart/cart-upgrade-banner.tsx": `'use client';
|
|
9767
|
+
|
|
9768
|
+
import { useState, useEffect } from 'react';
|
|
9769
|
+
import Image from 'next/image';
|
|
9770
|
+
import type { CartUpgradeSuggestion, CartItem as CartItemType } from 'brainerce';
|
|
9771
|
+
import { formatPrice } from 'brainerce';
|
|
9772
|
+
import { getClient } from '@/lib/brainerce';
|
|
9773
|
+
import { useStoreInfo } from '@/providers/store-provider';
|
|
9774
|
+
import { useTranslations } from '@/lib/translations';
|
|
9775
|
+
import { cn } from '@/lib/utils';
|
|
9776
|
+
|
|
9777
|
+
interface CartUpgradeBannerProps {
|
|
9778
|
+
suggestion: CartUpgradeSuggestion;
|
|
9779
|
+
cartItem: CartItemType;
|
|
9780
|
+
onUpgrade: () => void;
|
|
9781
|
+
className?: string;
|
|
9782
|
+
}
|
|
9783
|
+
|
|
9784
|
+
export function CartUpgradeBanner({
|
|
9785
|
+
suggestion,
|
|
9786
|
+
cartItem,
|
|
9787
|
+
onUpgrade,
|
|
9788
|
+
className,
|
|
9789
|
+
}: CartUpgradeBannerProps) {
|
|
9790
|
+
const { storeInfo } = useStoreInfo();
|
|
9791
|
+
const t = useTranslations('cart');
|
|
9792
|
+
const currency = storeInfo?.currency || 'USD';
|
|
9793
|
+
const [upgrading, setUpgrading] = useState(false);
|
|
9794
|
+
const [dismissed, setDismissed] = useState(false);
|
|
9795
|
+
|
|
9796
|
+
const storageKey = \`dismissed_upgrade_\${suggestion.sourceProductId}\`;
|
|
9797
|
+
|
|
9798
|
+
useEffect(() => {
|
|
9799
|
+
try {
|
|
9800
|
+
if (sessionStorage.getItem(storageKey)) {
|
|
9801
|
+
setDismissed(true);
|
|
9802
|
+
}
|
|
9803
|
+
} catch {}
|
|
9804
|
+
}, [storageKey]);
|
|
9805
|
+
|
|
9806
|
+
if (dismissed) return null;
|
|
9807
|
+
|
|
9808
|
+
const target = suggestion.targetProduct;
|
|
9809
|
+
const firstImage = target.images?.[0];
|
|
9810
|
+
const imageUrl = firstImage ? (typeof firstImage === 'string' ? firstImage : firstImage.url) : null;
|
|
9811
|
+
const formattedDelta = formatPrice(parseFloat(suggestion.priceDelta), { currency }) as string;
|
|
9812
|
+
|
|
9813
|
+
function handleDismiss() {
|
|
9814
|
+
try {
|
|
9815
|
+
sessionStorage.setItem(storageKey, '1');
|
|
9816
|
+
} catch {}
|
|
9817
|
+
setDismissed(true);
|
|
9818
|
+
}
|
|
9819
|
+
|
|
9820
|
+
async function handleUpgrade() {
|
|
9821
|
+
if (upgrading) return;
|
|
9822
|
+
try {
|
|
9823
|
+
setUpgrading(true);
|
|
9824
|
+
const client = getClient();
|
|
9825
|
+
await client.smartRemoveFromCart(cartItem.productId, cartItem.variantId || undefined);
|
|
9826
|
+
await client.smartAddToCart({ productId: target.id, quantity: cartItem.quantity });
|
|
9827
|
+
onUpgrade();
|
|
9828
|
+
} catch (err) {
|
|
9829
|
+
console.error('Failed to upgrade cart item:', err);
|
|
9830
|
+
} finally {
|
|
9831
|
+
setUpgrading(false);
|
|
9832
|
+
}
|
|
9833
|
+
}
|
|
9834
|
+
|
|
9835
|
+
return (
|
|
9836
|
+
<div
|
|
9837
|
+
className={cn(
|
|
9838
|
+
'bg-primary/5 border-primary/20 relative flex items-center gap-3 rounded-lg border px-4 py-3',
|
|
9839
|
+
className
|
|
9840
|
+
)}
|
|
9841
|
+
>
|
|
9842
|
+
{/* Dismiss button */}
|
|
9843
|
+
<button
|
|
9844
|
+
type="button"
|
|
9845
|
+
onClick={handleDismiss}
|
|
9846
|
+
className="text-muted-foreground hover:text-foreground absolute end-2 top-2 text-xs"
|
|
9847
|
+
aria-label={t('dismissUpgrade')}
|
|
9848
|
+
>
|
|
9849
|
+
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
9850
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
9851
|
+
</svg>
|
|
9852
|
+
</button>
|
|
9853
|
+
|
|
9854
|
+
{/* Product image */}
|
|
9855
|
+
<div className="bg-muted relative h-12 w-12 flex-shrink-0 overflow-hidden rounded">
|
|
9856
|
+
{imageUrl ? (
|
|
9857
|
+
<Image src={imageUrl} alt={target.name} fill sizes="48px" className="object-cover" />
|
|
9858
|
+
) : (
|
|
9859
|
+
<div className="text-muted-foreground flex h-full w-full items-center justify-center">
|
|
9860
|
+
<svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
9861
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
|
9862
|
+
</svg>
|
|
9863
|
+
</div>
|
|
9864
|
+
)}
|
|
9865
|
+
</div>
|
|
9866
|
+
|
|
9867
|
+
{/* Text */}
|
|
9868
|
+
<div className="min-w-0 flex-1">
|
|
9869
|
+
<p className="text-foreground text-sm font-medium">
|
|
9870
|
+
{t('upgradeFor', { name: target.name, amount: formattedDelta })}
|
|
9871
|
+
</p>
|
|
9872
|
+
</div>
|
|
9873
|
+
|
|
9874
|
+
{/* Upgrade button */}
|
|
9875
|
+
<button
|
|
9876
|
+
type="button"
|
|
9877
|
+
onClick={handleUpgrade}
|
|
9878
|
+
disabled={upgrading}
|
|
9879
|
+
className={cn(
|
|
9880
|
+
'bg-primary text-primary-foreground flex-shrink-0 rounded px-3 py-1.5 text-xs font-medium transition-opacity hover:opacity-90',
|
|
9881
|
+
'disabled:cursor-not-allowed disabled:opacity-50'
|
|
9882
|
+
)}
|
|
9883
|
+
>
|
|
9884
|
+
{upgrading ? t('upgrading') : t('upgrade')}
|
|
9885
|
+
</button>
|
|
9886
|
+
</div>
|
|
9887
|
+
);
|
|
9888
|
+
}
|
|
9889
|
+
`,
|
|
9890
|
+
"src/components/cart/cart-bundle-offer.tsx": `'use client';
|
|
9891
|
+
|
|
9892
|
+
import { useState } from 'react';
|
|
9893
|
+
import Image from 'next/image';
|
|
9894
|
+
import type { CartBundleOffer as CartBundleOfferType } from 'brainerce';
|
|
9895
|
+
import { formatPrice } from 'brainerce';
|
|
9896
|
+
import { getClient } from '@/lib/brainerce';
|
|
9897
|
+
import { useStoreInfo } from '@/providers/store-provider';
|
|
9898
|
+
import { useTranslations } from '@/lib/translations';
|
|
9899
|
+
import { cn } from '@/lib/utils';
|
|
9900
|
+
|
|
9901
|
+
interface CartBundleOfferCardProps {
|
|
9902
|
+
offer: CartBundleOfferType;
|
|
9903
|
+
onAdd: () => void;
|
|
9904
|
+
className?: string;
|
|
9905
|
+
}
|
|
9906
|
+
|
|
9907
|
+
export function CartBundleOfferCard({ offer, onAdd, className }: CartBundleOfferCardProps) {
|
|
9908
|
+
const { storeInfo } = useStoreInfo();
|
|
9909
|
+
const t = useTranslations('cart');
|
|
9910
|
+
const currency = storeInfo?.currency || 'USD';
|
|
9911
|
+
const [adding, setAdding] = useState(false);
|
|
9912
|
+
|
|
9913
|
+
const product = offer.bundleProduct;
|
|
9914
|
+
const firstImage = product.images?.[0];
|
|
9915
|
+
const imageUrl = firstImage ? (typeof firstImage === 'string' ? firstImage : firstImage.url) : null;
|
|
9916
|
+
const originalPrice = parseFloat(offer.originalPrice);
|
|
9917
|
+
const discountedPrice = parseFloat(offer.discountedPrice);
|
|
9918
|
+
const discountLabel =
|
|
9919
|
+
offer.discountType === 'PERCENTAGE'
|
|
9920
|
+
? \`\${offer.discountValue}%\`
|
|
9921
|
+
: formatPrice(parseFloat(offer.discountValue), { currency }) as string;
|
|
9922
|
+
|
|
9923
|
+
async function handleAdd() {
|
|
9924
|
+
if (adding) return;
|
|
9925
|
+
try {
|
|
9926
|
+
setAdding(true);
|
|
9927
|
+
const client = getClient();
|
|
9928
|
+
await client.smartAddToCart({
|
|
9929
|
+
productId: product.id,
|
|
9930
|
+
variantId: offer.bundleVariantId || undefined,
|
|
9931
|
+
quantity: 1,
|
|
9932
|
+
});
|
|
9933
|
+
onAdd();
|
|
9934
|
+
} catch (err) {
|
|
9935
|
+
console.error('Failed to add bundle item:', err);
|
|
9936
|
+
} finally {
|
|
9937
|
+
setAdding(false);
|
|
9938
|
+
}
|
|
9939
|
+
}
|
|
9940
|
+
|
|
9941
|
+
return (
|
|
9942
|
+
<div
|
|
9943
|
+
className={cn(
|
|
9944
|
+
'bg-background border-border flex items-center gap-4 rounded-lg border p-4',
|
|
9945
|
+
className
|
|
9946
|
+
)}
|
|
9947
|
+
>
|
|
9948
|
+
{/* Product image */}
|
|
9949
|
+
<div className="bg-muted relative h-16 w-16 flex-shrink-0 overflow-hidden rounded">
|
|
9950
|
+
{imageUrl ? (
|
|
9951
|
+
<Image src={imageUrl} alt={product.name} fill sizes="64px" className="object-cover" />
|
|
9952
|
+
) : (
|
|
9953
|
+
<div className="text-muted-foreground flex h-full w-full items-center justify-center">
|
|
9954
|
+
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
9955
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
|
9956
|
+
</svg>
|
|
9957
|
+
</div>
|
|
9958
|
+
)}
|
|
9959
|
+
</div>
|
|
9960
|
+
|
|
9961
|
+
{/* Details */}
|
|
9962
|
+
<div className="min-w-0 flex-1">
|
|
9963
|
+
<p className="text-foreground text-sm font-medium">{offer.name}</p>
|
|
9964
|
+
{offer.description && (
|
|
9965
|
+
<p className="text-muted-foreground mt-0.5 text-xs">{offer.description}</p>
|
|
9966
|
+
)}
|
|
9967
|
+
<div className="mt-1 flex items-center gap-2">
|
|
9968
|
+
<span className="text-muted-foreground text-sm line-through">
|
|
9969
|
+
{formatPrice(originalPrice, { currency }) as string}
|
|
9970
|
+
</span>
|
|
9971
|
+
<span className="text-foreground text-sm font-semibold">
|
|
9972
|
+
{formatPrice(discountedPrice, { currency }) as string}
|
|
9973
|
+
</span>
|
|
9974
|
+
<span className="bg-destructive/10 text-destructive rounded px-1.5 py-0.5 text-xs font-medium">
|
|
9975
|
+
-{discountLabel}
|
|
9976
|
+
</span>
|
|
9977
|
+
</div>
|
|
9978
|
+
</div>
|
|
9979
|
+
|
|
9980
|
+
{/* Add button */}
|
|
9981
|
+
<button
|
|
9982
|
+
type="button"
|
|
9983
|
+
onClick={handleAdd}
|
|
9984
|
+
disabled={adding}
|
|
9985
|
+
className={cn(
|
|
9986
|
+
'bg-primary text-primary-foreground flex-shrink-0 rounded px-4 py-2 text-xs font-medium transition-opacity hover:opacity-90',
|
|
9987
|
+
'disabled:cursor-not-allowed disabled:opacity-50'
|
|
9988
|
+
)}
|
|
9989
|
+
>
|
|
9990
|
+
{adding ? t('addingBundle') : t('addBundleItem')}
|
|
9991
|
+
</button>
|
|
9992
|
+
</div>
|
|
9993
|
+
);
|
|
9994
|
+
}
|
|
9995
|
+
`,
|
|
9996
|
+
"src/components/checkout/order-bump-card.tsx": `'use client';
|
|
9997
|
+
|
|
9998
|
+
import Image from 'next/image';
|
|
9999
|
+
import type { OrderBump } from 'brainerce';
|
|
10000
|
+
import { formatPrice } from 'brainerce';
|
|
10001
|
+
import { useStoreInfo } from '@/providers/store-provider';
|
|
10002
|
+
import { useTranslations } from '@/lib/translations';
|
|
10003
|
+
import { cn } from '@/lib/utils';
|
|
10004
|
+
|
|
10005
|
+
interface OrderBumpCardProps {
|
|
10006
|
+
bump: OrderBump;
|
|
10007
|
+
isAdded: boolean;
|
|
10008
|
+
onToggle: (bumpId: string, add: boolean) => void;
|
|
10009
|
+
loading: boolean;
|
|
10010
|
+
className?: string;
|
|
10011
|
+
}
|
|
10012
|
+
|
|
10013
|
+
export function OrderBumpCard({ bump, isAdded, onToggle, loading, className }: OrderBumpCardProps) {
|
|
10014
|
+
const { storeInfo } = useStoreInfo();
|
|
10015
|
+
const t = useTranslations('checkout');
|
|
10016
|
+
const currency = storeInfo?.currency || 'USD';
|
|
10017
|
+
|
|
10018
|
+
const product = bump.bumpProduct;
|
|
10019
|
+
const firstImage = product.images?.[0];
|
|
10020
|
+
const imageUrl = firstImage ? (typeof firstImage === 'string' ? firstImage : firstImage.url) : null;
|
|
10021
|
+
const originalPrice = parseFloat(bump.originalPrice);
|
|
10022
|
+
const hasDiscount = bump.discountedPrice != null;
|
|
10023
|
+
const discountedPrice = hasDiscount ? parseFloat(bump.discountedPrice!) : null;
|
|
10024
|
+
|
|
10025
|
+
return (
|
|
10026
|
+
<label
|
|
10027
|
+
className={cn(
|
|
10028
|
+
'border-border hover:border-primary/50 flex cursor-pointer items-start gap-3 rounded-lg border p-3 transition-colors',
|
|
10029
|
+
isAdded && 'border-primary bg-primary/5',
|
|
10030
|
+
loading && 'pointer-events-none opacity-60',
|
|
10031
|
+
className
|
|
10032
|
+
)}
|
|
10033
|
+
>
|
|
10034
|
+
<input
|
|
10035
|
+
type="checkbox"
|
|
10036
|
+
checked={isAdded}
|
|
10037
|
+
onChange={() => onToggle(bump.id, !isAdded)}
|
|
10038
|
+
disabled={loading}
|
|
10039
|
+
className="mt-1 h-4 w-4 shrink-0 rounded"
|
|
10040
|
+
/>
|
|
10041
|
+
|
|
10042
|
+
{/* Image */}
|
|
10043
|
+
{imageUrl && (
|
|
10044
|
+
<div className="bg-muted relative h-10 w-10 shrink-0 overflow-hidden rounded">
|
|
10045
|
+
<Image src={imageUrl} alt={product.name} fill sizes="40px" className="object-cover" />
|
|
10046
|
+
</div>
|
|
10047
|
+
)}
|
|
10048
|
+
|
|
10049
|
+
{/* Content */}
|
|
10050
|
+
<div className="min-w-0 flex-1">
|
|
10051
|
+
<p className="text-foreground text-sm font-medium">{bump.title}</p>
|
|
10052
|
+
{bump.description && (
|
|
10053
|
+
<p className="text-muted-foreground mt-0.5 text-xs">{bump.description}</p>
|
|
10054
|
+
)}
|
|
10055
|
+
<div className="mt-1 flex items-center gap-2">
|
|
10056
|
+
{hasDiscount ? (
|
|
10057
|
+
<>
|
|
10058
|
+
<span className="text-muted-foreground text-xs line-through">
|
|
10059
|
+
{formatPrice(originalPrice, { currency }) as string}
|
|
10060
|
+
</span>
|
|
10061
|
+
<span className="text-foreground text-sm font-semibold">
|
|
10062
|
+
{formatPrice(discountedPrice!, { currency }) as string}
|
|
10063
|
+
</span>
|
|
10064
|
+
</>
|
|
10065
|
+
) : (
|
|
10066
|
+
<span className="text-foreground text-sm font-semibold">
|
|
10067
|
+
{formatPrice(originalPrice, { currency }) as string}
|
|
10068
|
+
</span>
|
|
10069
|
+
)}
|
|
10070
|
+
</div>
|
|
10071
|
+
</div>
|
|
10072
|
+
</label>
|
|
10073
|
+
);
|
|
10074
|
+
}
|
|
9198
10075
|
`,
|
|
9199
10076
|
"src/hooks/use-search.ts": `'use client';
|
|
9200
10077
|
|