2025-08-14 16:36:12 -05:00
2025-08-14 16:36:12 -05:00
2025-08-14 16:36:12 -05:00
2025-08-14 16:36:12 -05:00
2025-08-10 14:54:47 -05:00
2025-08-07 15:29:23 -05:00
2025-08-06 16:00:31 -05:00
2025-08-14 16:36:12 -05:00
2025-08-14 16:36:12 -05:00
2025-08-14 16:36:12 -05:00
2025-08-14 16:36:12 -05:00
2025-08-14 16:36:12 -05:00
2025-08-14 16:36:12 -05:00

Shopify Price Updater

A Node.js application that bulk updates product prices in your Shopify store based on product tags using Shopify's GraphQL Admin API. Features both command-line interface (CLI) and an interactive Terminal User Interface (TUI) for enhanced user experience.

Features

  • Tag-based filtering: Update prices only for products with specific tags
  • Percentage-based adjustments: Increase or decrease prices by a configurable percentage
  • Interactive TUI: Modern React-based terminal interface with Windows compatibility
  • Batch processing: Handles large inventories with automatic pagination
  • Error resilience: Continues processing even if individual products fail
  • Rate limit handling: Automatic retry logic for API rate limits
  • Progress tracking: Detailed logging to both console and Progress.md file
  • Environment-based configuration: Secure credential management via .env file
  • Cross-platform support: Optimized for Windows, macOS, and Linux terminals

Prerequisites

  • Node.js (version 16 or higher)
  • A Shopify store with Admin API access
  • Shopify Private App or Custom App with the following permissions:
    • read_products
    • write_products
  • Modern terminal with Unicode support (recommended: Windows Terminal, iTerm2, or similar)

Installation

  1. Clone or download this repository
  2. Install dependencies:
    npm install
    
  3. Copy the environment template:
    copy .env.example .env
    
  4. Configure your environment variables (see Configuration section)

Configuration

Edit the .env file with your Shopify store details:

# Your Shopify store domain (without https://)
SHOPIFY_SHOP_DOMAIN=your-store.myshopify.com

# Your Shopify Admin API access token
SHOPIFY_ACCESS_TOKEN=shpat_your_access_token_here

# The product tag to filter by
TARGET_TAG=sale

# Price adjustment percentage (positive for increase, negative for decrease)
# Examples: 10 (increase by 10%), -15 (decrease by 15%), 5.5 (increase by 5.5%)
# Note: Only used in "update" mode, ignored in "rollback" mode
PRICE_ADJUSTMENT_PERCENTAGE=10

# Operation mode - determines whether to update prices or rollback to compare-at prices
# Options: "update" (default) or "rollback"
# When not specified, defaults to "update" for backward compatibility
OPERATION_MODE=update

Operation Mode Configuration

The OPERATION_MODE environment variable controls the application behavior:

  • update (default): Performs price adjustments using PRICE_ADJUSTMENT_PERCENTAGE
  • rollback: Sets prices to compare-at price values and removes compare-at prices

When OPERATION_MODE is not specified, the application defaults to update mode for backward compatibility.

Getting Your Shopify Credentials

  1. Go to your Shopify Admin → Apps → App and sales channel settings
  2. Click "Develop apps" → "Create an app"
  3. Configure Admin API access with read_products and write_products permissions
  4. Install the app and copy the Admin API access token

For Custom Apps:

  1. Go to your Shopify Admin → Settings → Apps and sales channels
  2. Click "Develop apps" → "Create an app"
  3. Configure the required API permissions
  4. Generate and copy the access token

Usage

Launch the interactive Terminal User Interface for a guided experience:

npm run tui

The TUI provides:

  • Interactive configuration management
  • Real-time progress visualization
  • Operation scheduling
  • Log viewing and analysis
  • Tag analysis tools
  • Windows-optimized interface

Command Line Interface

Run the script directly with your configured environment:

npm start

or

node src/index.js

Operation Modes

The application supports two operation modes:

Update Mode (Default)

Adjusts product prices by a percentage:

npm run update

This performs the standard price adjustment functionality using the PRICE_ADJUSTMENT_PERCENTAGE setting.

Rollback Mode

Reverts prices by setting the main price to the compare-at price and removing the compare-at price:

npm run rollback

This is useful for reverting promotional pricing back to original prices. Products without compare-at prices will be skipped.

Operation Mode Indicators:

  • The console output clearly displays which operation mode is active
  • Progress.md logs distinguish between "Price Update Operation" and "Price Rollback Operation"
  • Configuration summary shows the operation mode being used

Debug Mode

Before running the main script, you can use the debug mode to see what tags exist in your store and verify your target tag:

npm run debug-tags

This will:

  • Show all products and their tags in your store
  • Check if your target tag exists
  • Suggest similar tags if exact match isn't found
  • Help troubleshoot tag-related issues

Example Scenarios

Increase prices by 10% for sale items:

TARGET_TAG=sale
PRICE_ADJUSTMENT_PERCENTAGE=10

Decrease prices by 15% for clearance items:

TARGET_TAG=clearance
PRICE_ADJUSTMENT_PERCENTAGE=-15

Apply a 5.5% increase to seasonal products:

TARGET_TAG=seasonal
PRICE_ADJUSTMENT_PERCENTAGE=5.5

Output and Logging

The script provides detailed feedback in two ways:

Console Output

  • Configuration summary at startup
  • Real-time progress updates
  • Product-by-product price changes
  • Final summary with success/failure counts

Progress.md File

  • Persistent log of all operations
  • Timestamps for each run
  • Detailed error information for debugging
  • Historical record of price changes

Example console output:

🚀 Starting Shopify Price Updater
📋 Configuration:
   Store: your-store.myshopify.com
   Tag: sale
   Adjustment: +10%

🔍 Found 25 products with tag 'sale'
✅ Updated Product A: $19.99 → $21.99
✅ Updated Product B: $29.99 → $32.99
⚠️  Skipped Product C: Invalid price data
...
📊 Summary: 23 products updated, 2 skipped, 0 errors

Error Handling

The script is designed to be resilient:

  • Rate Limits: Automatically retries with exponential backoff
  • Network Issues: Retries failed requests up to 3 times
  • Invalid Data: Skips problematic products and continues
  • API Errors: Logs errors and continues with remaining products
  • Missing Environment Variables: Validates configuration before starting

Testing

Before Running on Production

  1. Test with a development store or backup your data
  2. Start with a small subset by using a specific tag with few products
  3. Verify the percentage calculation with known product prices
  4. Check the Progress.md file to ensure logging works correctly
  1. Create a test tag (e.g., "price-test") on a few products
  2. Set TARGET_TAG=price-test in your .env
  3. Run the script with a small percentage (e.g., 1%)
  4. Verify the changes in your Shopify admin
  5. Once satisfied, update your configuration for the actual run

Troubleshooting

Common Issues

"Authentication failed"

  • Verify your SHOPIFY_ACCESS_TOKEN is correct
  • Ensure your app has read_products and write_products permissions

"No products found"

  • Run npm run debug-tags to see all available tags in your store
  • Check that products actually have the specified tag
  • Tag matching is case-sensitive
  • Verify the tag format (some tags may have spaces, hyphens, or different capitalization)

"Rate limit exceeded"

  • The script handles this automatically, but you can reduce load by processing smaller batches

"Invalid percentage"

  • Ensure PRICE_ADJUSTMENT_PERCENTAGE is a valid number
  • Use negative values for price decreases

Debugging Steps

  1. Run the debug script first: npm run debug-tags to see what tags exist in your store
  2. Check the Progress.md file for detailed error information
  3. Verify your .env configuration matches the required format
  4. Test with a small subset of products first
  5. Ensure your Shopify app has the necessary permissions

Debug Scripts

The project includes debugging tools:

  • npm run debug-tags - Analyze all product tags in your store
  • debug-tags.js - Standalone script to check tag availability and troubleshoot tag-related issues

Security Notes

  • Never commit your .env file to version control
  • Use environment-specific access tokens
  • Regularly rotate your API credentials
  • Test changes in a development environment first

File Structure

shopify-price-updater/
├── src/
│   ├── config/
│   │   └── environment.js     # Environment configuration
│   ├── services/
│   │   ├── shopify.js         # Shopify API client
│   │   ├── product.js         # Product operations
│   │   └── progress.js        # Progress logging
│   ├── tui/                   # Terminal User Interface (Ink-based)
│   │   ├── components/
│   │   │   ├── common/        # Reusable UI components
│   │   │   └── screens/       # Screen components
│   │   ├── hooks/             # Custom React hooks
│   │   ├── providers/         # Context providers
│   │   ├── utils/             # TUI utilities
│   │   └── TuiApplication.jsx # Main TUI component
│   ├── utils/
│   │   ├── price.js           # Price calculations
│   │   └── logger.js          # Logging utilities
│   ├── index.js               # CLI entry point
│   └── tui-entry.js           # TUI entry point
├── tests/                    # Unit tests for the application
├── docs/                     # Documentation
│   ├── windows-compatibility-summary.md
│   └── performance-optimization-summary.md
├── debug-tags.js            # Debug script to analyze store tags
├── .env                     # Your configuration (create from .env.example)
├── .env.example            # Configuration template
├── package.json            # Dependencies and scripts
├── Progress.md             # Generated progress log
└── README.md               # This file

Terminal User Interface (TUI)

TUI Features

The interactive Terminal User Interface provides a modern, user-friendly way to manage your Shopify price updates:

  • Main Menu: Central navigation hub with keyboard shortcuts
  • Configuration Screen: Interactive form for environment settings with real-time validation
  • Operation Screen: Live progress tracking with visual indicators
  • Scheduling Screen: Date/time picker for automated operations
  • Log Viewer: Paginated log display with search and filtering
  • Tag Analysis: Product tag statistics and recommendations

TUI Architecture

Built with Ink (React for CLI) for superior cross-platform compatibility:

  • Component-based: Modern React architecture with reusable components
  • State Management: React Context API with custom hooks
  • Windows Optimized: Enhanced compatibility with Windows Terminal, Command Prompt, and PowerShell
  • Responsive Design: Adapts to different terminal sizes and orientations
  • Accessibility: Screen reader support and high contrast mode compatibility
  • Performance: Optimized rendering with virtual scrolling and memory management

TUI Components

  • ProgressBar: Visual progress indicators with color coding
  • InputField: Form inputs with real-time validation
  • MenuList: Keyboard-navigable menus with selection highlighting
  • StatusBar: Real-time system status and connection information
  • ErrorBoundary: Graceful error handling and recovery

Keyboard Navigation

  • Arrow Keys: Navigate menus and options
  • Enter: Select/confirm actions
  • Escape/q: Go back or quit
  • Tab: Move between form fields
  • Ctrl+C: Exit application
  • ?: Show help overlay

Technical Details

API Implementation

  • Uses Shopify's GraphQL Admin API (version 2024-01)
  • Implements productVariantsBulkUpdate mutation for price updates
  • Built-in HTTPS client using Node.js native modules (no external HTTP dependencies)
  • Automatic tag formatting (handles both "tag" and "tag:tagname" formats)

Rate Limiting

  • Implements exponential backoff for rate limit handling
  • Maximum 3 retry attempts with increasing delays (1s, 2s, 4s)
  • Respects Shopify's API rate limits automatically

Error Recovery

  • Continues processing even if individual products fail
  • Comprehensive error categorization and reporting
  • Non-retryable errors are identified and logged appropriately

Available Scripts

Interactive Interface

  • npm run tui - Launch the interactive Terminal User Interface (recommended)

Immediate Execution Scripts

  • npm start - Run the price updater (defaults to update mode for backward compatibility)
  • npm run update - Run the price update script (explicitly set to update mode)
  • npm run rollback - Run the price rollback script (set prices to compare-at prices)
  • npm run debug-tags - Analyze all product tags in your store
  • npm test - Run the test suite

Scheduled Execution Scripts

  • npm run schedule-update - Run scheduled price update (requires SCHEDULED_EXECUTION_TIME environment variable)
  • npm run schedule-rollback - Run scheduled price rollback (requires SCHEDULED_EXECUTION_TIME environment variable)

Scheduling Examples

Schedule a sale to start at 10:30 AM on December 25th:

# Set environment variable and run
set SCHEDULED_EXECUTION_TIME=2024-12-25T10:30:00 && npm run schedule-update

Schedule a sale to end (rollback) at midnight on January 1st:

# Set environment variable and run
set SCHEDULED_EXECUTION_TIME=2025-01-01T00:00:00 && npm run schedule-rollback

Schedule with specific timezone (EST):

# Set environment variable with timezone and run
set SCHEDULED_EXECUTION_TIME=2024-12-25T10:30:00-05:00 && npm run schedule-update

Using .env file for scheduling:

# Add to your .env file
SCHEDULED_EXECUTION_TIME=2024-12-25T10:30:00
OPERATION_MODE=update
TARGET_TAG=sale
PRICE_ADJUSTMENT_PERCENTAGE=10

Then run: npm run schedule-update

Common scheduling scenarios:

  • Black Friday sale start: Schedule price decreases for Friday morning
  • Sale end: Schedule rollback to original prices after promotion period
  • Seasonal pricing: Schedule price adjustments for seasonal campaigns
  • Flash sales: Schedule short-term promotional pricing
  • Holiday promotions: Schedule price changes for specific holidays

Note: When using scheduled execution, the script will display a countdown and wait until the specified time before executing the price updates. You can cancel the scheduled operation by pressing Ctrl+C during the waiting period.

License

This project is provided as-is for educational and commercial use. Please test thoroughly before using in production environments.

Description
No description provided
Readme 751 KiB
Languages
JavaScript 100%