116 lines
4.3 KiB
Markdown
116 lines
4.3 KiB
Markdown
# Shopify Price Updater
|
|
|
|
A Node.js script designed to automate the bulk updating and rolling back of Shopify product prices based on specific product tags. This tool is ideal for managing sales, promotions, or price adjustments across a large catalog of products efficiently.
|
|
|
|
## Features
|
|
|
|
- **Bulk Price Updates:** Adjust product prices by a configurable percentage (increase or decrease).
|
|
- **Price Rollback:** Revert product prices to their original "compare-at" price, useful for ending sales or promotions.
|
|
- **Tag-Based Operations:** Target specific groups of products using Shopify product tags.
|
|
- **Scheduled Execution:** Optionally schedule price operations to run at a future date and time.
|
|
- **Comprehensive Logging:** Provides detailed logs of operations, including product counts, successful updates/rollbacks, and any encountered errors.
|
|
- **Graceful Shutdown:** Handles interruptions gracefully, ensuring data integrity.
|
|
|
|
## Installation
|
|
|
|
To get started with the Shopify Price Updater, follow these steps:
|
|
|
|
### Prerequisites
|
|
|
|
- Node.js (version 16.0.0 or higher)
|
|
- Access to a Shopify store with Admin API credentials.
|
|
|
|
### Steps
|
|
|
|
1. **Clone the Repository:**
|
|
|
|
```bash
|
|
git clone https://github.com/your-repo/shopify-price-updater.git
|
|
cd shopify-price-updater
|
|
```
|
|
|
|
_(Note: Replace `https://github.com/your-repo/shopify-price-updater.git` with the actual repository URL if different.)_
|
|
|
|
2. **Install Dependencies:**
|
|
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
3. **Configure Environment Variables:**
|
|
Create a `.env` file in the root directory of the project (same level as `package.json`). Copy the contents from `.env.example` and fill in your Shopify store details and desired configuration.
|
|
|
|
```ini
|
|
# .env example
|
|
# Shopify Store Configuration
|
|
SHOPIFY_SHOP_DOMAIN=your-shop-name.myshopify.com
|
|
SHOPIFY_ACCESS_TOKEN=your-admin-api-access-token
|
|
|
|
# Price Update Configuration
|
|
TARGET_TAG=sale
|
|
OPERATION_MODE=update
|
|
PRICE_ADJUSTMENT_PERCENTAGE=10
|
|
|
|
# Scheduling Configuration (Optional)
|
|
# SCHEDULED_EXECUTION_TIME=2024-12-25T10:30:00
|
|
```
|
|
|
|
- `SHOPIFY_SHOP_DOMAIN`: Your Shopify store's domain (e.g., `your-store.myshopify.com`).
|
|
- `SHOPIFY_ACCESS_TOKEN`: A Shopify Admin API Access Token with `write_products` and `read_products` permissions.
|
|
- `TARGET_TAG`: The Shopify product tag that identifies the products you want to update (e.g., `sale`, `clearance`).
|
|
- `OPERATION_MODE`: Set to `update` for price adjustments or `rollback` to revert prices.
|
|
- `PRICE_ADJUSTMENT_PERCENTAGE`: (Used only in `update` mode) The percentage by which to adjust prices. Use a positive number for an increase (e.g., `10` for +10%) and a negative number for a decrease (e.g., `-15` for -15%).
|
|
- `SCHEDULED_EXECUTION_TIME`: (Optional) An ISO 8601 formatted datetime string (e.g., `YYYY-MM-DDTHH:MM:SS`). If set, the script will wait until this time before executing the operation. Leave commented out or remove to execute immediately.
|
|
|
|
## Usage
|
|
|
|
You can run the application using the following `npm` scripts:
|
|
|
|
### Run in Default Mode (Update)
|
|
|
|
This will run the script in `update` mode with the `TARGET_TAG` and `PRICE_ADJUSTMENT_PERCENTAGE` defined in your `.env` file.
|
|
|
|
```bash
|
|
npm start
|
|
```
|
|
|
|
### ~~Run in Update Mode~~
|
|
|
|
~~Explicitly sets the `OPERATION_MODE` to `update`. This is useful if you want to override the `.env` setting for a single run.~~
|
|
|
|
Doesn't work currently, weird spacing issues in package.json
|
|
|
|
```bash
|
|
npm run update
|
|
```
|
|
|
|
### ~~Run in Rollback Mode~~
|
|
|
|
~~Explicitly sets the `OPERATION_MODE` to `rollback`. This will revert prices of products with the `TARGET_TAG` from their current price to their `compare-at` price.~~
|
|
|
|
Doesn't work currently, weird spacing issues in package.json
|
|
|
|
```bash
|
|
npm run rollback
|
|
```
|
|
|
|
### Debug Tags
|
|
|
|
This script helps in debugging product tags. It's useful for verifying which products are associated with a specific tag without performing any price changes.
|
|
|
|
```bash
|
|
npm run debug-tags
|
|
```
|
|
|
|
### Running Tests
|
|
|
|
To run the automated tests for the application:
|
|
|
|
```bash
|
|
npm test
|
|
```
|
|
|
|
### Scheduled Operations
|
|
|
|
If `SCHEDULED_EXECUTION_TIME` is set in your `.env` file, the script will start and wait until the specified time before initiating the price update or rollback operation. You can use `npm start`, `npm run update`, or `npm run rollback` with the `SCHEDULED_EXECUTION_TIME` variable set.
|