- Full Node.js application with Shopify GraphQL API integration - Compare At price support for promotional pricing - Comprehensive error handling and retry logic - Progress tracking with markdown logging - Complete test suite with unit and integration tests - Production-ready with proper exit codes and signal handling
5.7 KiB
Requirements Document
Introduction
This feature involves creating a Node.js script that connects to Shopify's GraphQL API to update product prices based on specific criteria. The script will filter products by a preset tag and adjust their prices by a configurable percentage (either increase or decrease). The solution will use Shopify's official Node.js API package and store configuration in environment variables for security and flexibility.
Requirements
Requirement 1
User Story: As a store administrator, I want to bulk update product prices for products with specific tags, so that I can efficiently manage pricing across my inventory.
Acceptance Criteria
- WHEN the script is executed THEN the system SHALL connect to Shopify using GraphQL API
- WHEN connecting to Shopify THEN the system SHALL authenticate using API credentials from environment variables
- WHEN querying products THEN the system SHALL filter products by a configurable tag
- WHEN a matching product is found THEN the system SHALL update its price by the specified percentage
- WHEN updating prices THEN the system SHALL support both price increases and decreases based on percentage value
- WHEN updating a product price THEN the system SHALL set the original price as the "Compare At" price
- WHEN the original price exists THEN the system SHALL preserve it as the Compare At price before applying the adjustment
Requirement 2
User Story: As a store administrator, I want to configure the script through environment variables, so that I can easily change settings without modifying code.
Acceptance Criteria
- WHEN the script starts THEN the system SHALL load Shopify API credentials from .env file
- WHEN loading configuration THEN the system SHALL read the target product tag from environment variables
- WHEN loading configuration THEN the system SHALL read the price adjustment percentage from environment variables
- IF required environment variables are missing THEN the system SHALL display an error message and exit gracefully
- WHEN percentage is positive THEN the system SHALL increase prices
- WHEN percentage is negative THEN the system SHALL decrease prices
Requirement 3
User Story: As a store administrator, I want to see detailed feedback about the price update process, so that I can verify the changes were applied correctly.
Acceptance Criteria
- WHEN the script starts THEN the system SHALL display the configuration being used
- WHEN products are found THEN the system SHALL display the count of matching products
- WHEN updating each product THEN the system SHALL log the product name, old price, new price, and Compare At price
- WHEN all updates are complete THEN the system SHALL display a summary of total products updated
- IF errors occur during updates THEN the system SHALL log error details and continue processing other products
Requirement 4
User Story: As a store administrator, I want the script to handle errors gracefully, so that partial failures don't prevent other products from being updated.
Acceptance Criteria
- WHEN API rate limits are encountered THEN the system SHALL implement appropriate retry logic
- WHEN a product update fails THEN the system SHALL log the error and continue with remaining products
- WHEN network errors occur THEN the system SHALL retry the operation with exponential backoff
- WHEN invalid product data is encountered THEN the system SHALL skip the product and log a warning
- WHEN the script completes THEN the system SHALL exit with appropriate status codes
Requirement 5
User Story: As a developer, I want the script to use Shopify's official Node.js package and GraphQL API, so that I can leverage well-maintained and efficient tools.
Acceptance Criteria
- WHEN implementing the solution THEN the system SHALL use Shopify's official Node.js API package
- WHEN querying products THEN the system SHALL use GraphQL queries for efficient data retrieval
- WHEN updating products THEN the system SHALL use GraphQL mutations for price updates
- WHEN handling API responses THEN the system SHALL properly parse GraphQL response structures
- WHEN managing API connections THEN the system SHALL follow Shopify's best practices for authentication and session management
Requirement 6
User Story: As a store administrator, I want the script to set Compare At prices to show customers the original price before adjustment, so that I can create effective promotional pricing displays.
Acceptance Criteria
- WHEN a product price is being updated THEN the system SHALL capture the current price as the Compare At price
- WHEN the Compare At price is set THEN the system SHALL use the original price value before any percentage adjustment
- WHEN updating product variants THEN the system SHALL set both the new price and Compare At price in the same operation
- WHEN a product already has a Compare At price THEN the system SHALL replace it with the current price before adjustment
- WHEN logging price updates THEN the system SHALL include the Compare At price in the progress tracking
Requirement 7
User Story: As a developer, I want the script to maintain a progress log, so that I can track what operations have been completed and reference them later.
Acceptance Criteria
- WHEN the script starts THEN the system SHALL create or append to a Progress.md file
- WHEN each product is processed THEN the system SHALL log the operation details to Progress.md
- WHEN the script completes THEN the system SHALL write a summary to Progress.md with timestamp
- WHEN errors occur THEN the system SHALL log error details to Progress.md for debugging
- WHEN the script runs multiple times THEN the system SHALL append new progress entries without overwriting previous runs