#!/usr/bin/env node /** * Debug script to list all product tags in the Shopify store * This helps identify why the main script might not be finding products */ const ProductService = require("./src/services/product"); const { getConfig } = require("./src/config/environment"); async function debugTags() { try { console.log("šŸ” Debug: Analyzing product tags in your Shopify store...\n"); // Load configuration const config = getConfig(); console.log(`Store: ${config.shopDomain}`); console.log(`Looking for tag: "${config.targetTag}"`); console.log("─".repeat(50)); // Create product service const productService = new ProductService(); // Fetch products and analyze tags const products = await productService.debugFetchAllProductTags(100); // Check if the target tag exists (case-insensitive search) const targetTag = config.targetTag.toLowerCase(); const matchingProducts = products.filter((product) => { if (!product.tags || !Array.isArray(product.tags)) return false; return product.tags.some((tag) => tag.toLowerCase().includes(targetTag)); }); console.log("\nšŸ“Š Analysis Results:"); console.log(`Total products analyzed: ${products.length}`); console.log( `Products with target tag "${config.targetTag}": ${matchingProducts.length}` ); if (matchingProducts.length > 0) { console.log("\nāœ… Found products with matching tags:"); matchingProducts.forEach((product) => { const matchingTags = product.tags.filter((tag) => tag.toLowerCase().includes(targetTag) ); console.log( ` - "${product.title}" has tags: [${matchingTags.join(", ")}]` ); }); } else { console.log("\nāŒ No products found with the target tag."); console.log("\nšŸ’” Suggestions:"); console.log("1. Check if the tag name is spelled correctly"); console.log("2. Tags are case-sensitive - try different capitalization"); console.log( "3. Check if products actually have this tag in Shopify admin" ); console.log( "4. Try a partial match - maybe the tag has additional words" ); // Show similar tags const allTags = new Set(); products.forEach((product) => { if (product.tags && Array.isArray(product.tags)) { product.tags.forEach((tag) => allTags.add(tag)); } }); const similarTags = Array.from(allTags).filter( (tag) => tag.toLowerCase().includes("summer") || tag.toLowerCase().includes("sale") || tag.toLowerCase().includes(targetTag.split("-")[0]) || tag.toLowerCase().includes(targetTag.split("-")[1] || "") ); if (similarTags.length > 0) { console.log(`\nšŸ” Similar tags found: [${similarTags.join(", ")}]`); } } } catch (error) { console.error("āŒ Debug failed:", error.message); process.exit(1); } } // Run the debug function debugTags();