changes: Remove default SKU hardcoded to show real data
This commit is contained in:
@@ -362,7 +362,10 @@ function HomePageContent() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleHistoryItemClick = () => {
|
||||
const handleHistoryItemClick = (shoe: Shoe) => {
|
||||
console.log('📜 Click en historial:', shoe.name, '- SKU:', shoe.sku);
|
||||
// Update detectedSKU with the shoe's SKU from history
|
||||
setDetectedSKU(shoe.sku || null);
|
||||
setHistoryOpen(false);
|
||||
setPopupOpen(true);
|
||||
};
|
||||
|
||||
@@ -31,11 +31,28 @@ export default function ShoeResultsPopup({ isOpen, onOpenChange, detectedSKU }:
|
||||
const [lastPromptTime, setLastPromptTime] = useState(0);
|
||||
const [wasPopupOpenBeforeChat, setWasPopupOpenBeforeChat] = useState(false);
|
||||
|
||||
// Reset product when detectedSKU changes
|
||||
useEffect(() => {
|
||||
if (detectedSKU) {
|
||||
console.log('🔄 SKU cambió, reseteando producto...');
|
||||
setProduct(null);
|
||||
setSelectedVariant('');
|
||||
setSelectedSize('');
|
||||
}
|
||||
}, [detectedSKU]);
|
||||
|
||||
// Fetch product data when popup opens
|
||||
useEffect(() => {
|
||||
if (isOpen && !product) {
|
||||
setLoading(true);
|
||||
fetchProduct().then((data) => {
|
||||
// Extract productId from detectedSKU (first 6 characters)
|
||||
// Example: "18047409" → "180474"
|
||||
const productId = detectedSKU?.substring(0, 6);
|
||||
|
||||
console.log('🔍 ShoeResultsPopup: Buscando producto con SKU:', detectedSKU);
|
||||
console.log('📦 ProductId extraído:', productId);
|
||||
|
||||
fetchProduct(productId).then((data) => {
|
||||
if (data) {
|
||||
setProduct(data);
|
||||
const images = getProductImages(data);
|
||||
@@ -54,7 +71,7 @@ export default function ShoeResultsPopup({ isOpen, onOpenChange, detectedSKU }:
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
}, [isOpen, product]);
|
||||
}, [isOpen, product, detectedSKU]);
|
||||
|
||||
// Show chat prompt when popup opens (contextual message)
|
||||
useEffect(() => {
|
||||
|
||||
@@ -92,6 +92,8 @@ export interface Product {
|
||||
Disciplina?: string[];
|
||||
}
|
||||
|
||||
// Fallback product ID used only when no productId is provided
|
||||
// This should rarely happen - normally productId comes from SKU detection or history
|
||||
const FIXED_PRODUCT_ID = '180474';
|
||||
|
||||
export async function fetchProduct(productId: string = FIXED_PRODUCT_ID): Promise<Product | null> {
|
||||
|
||||
Reference in New Issue
Block a user