From 460aa27198f82ceb81dd8ada075b2b3065ff4b01 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Fri, 30 May 2025 12:38:43 -0600 Subject: [PATCH 01/15] Add Local Development Setup with Docker (#29) --- .gitignore | 14 ++- README.md | 109 ++++++++++++++++++- scripts/magento-auth.template | 9 ++ scripts/setup-first-time.sh | 195 ++++++++++++++++++++++++++++++++++ scripts/start-env.sh | 46 ++++++++ 5 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 scripts/magento-auth.template create mode 100755 scripts/setup-first-time.sh create mode 100755 scripts/start-env.sh diff --git a/.gitignore b/.gitignore index 5657f6e..6ea9cd2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,13 @@ -vendor \ No newline at end of file +vendor + +# Ignore Magento installation +scripts/magento-auth.env +.docker-magento/ + +# Ignore Docker-related files +compose*.yaml +Makefile +bin/ +env/ +template/ + diff --git a/README.md b/README.md index 7bc5570..295c4e4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Grin Module +# Grin Module Influencer marketing for ecommerce. For more information go to https://grin.co/ @@ -55,3 +55,110 @@ Possible solution: in this case, according to Magento documentation, you need to ], ... ``` + +Local Development +- + +This module uses Docker for local development. Follow these steps to set up your development environment: + +### Prerequisites + +1. Docker and Docker Compose installed on your machine +2. Magento Marketplace credentials +3. GitHub Personal Access Token + +### Port Configuration + +The development environment uses custom ports to avoid conflicts with other services: + +| Service | Default Port | Development Port | +|---------|--------------|------------------| +| Web Server | 80 | 8081 | +| HTTPS | 443 | 8443 | +| MySQL | 3306 | 3307 | +| Redis | 6379 | 6380 | +| OpenSearch | 9200 | 9201 | +| RabbitMQ | 5672 | 5673 | +| Mailcatcher | 1025 | 1026 | + +These ports are automatically configured during setup to avoid conflicts with other services like `app.grin.co`. + +### Getting Required Credentials + +1. **Magento Marketplace Credentials**: + - Go to [Magento Marketplace Access Keys](https://marketplace.magento.com/customer/accessKeys/) + - Create a new access key if you don't have one + - Note down your Public Key and Private Key + +2. **GitHub Token**: + - Go to [GitHub Personal Access Tokens](https://github.com/settings/personal-access-tokens) + - Create a new token with `repo` scope + - Note down your token + +### Setup Steps + +1. Copy the auth template file: + ```bash + cp scripts/magento-auth.template scripts/magento-auth.env + ``` + +2. Edit `scripts/magento-auth.env` and add your credentials: + ``` + MAGENTO_MARKETPLACE_PUBLIC_KEY=your_public_key + MAGENTO_MARKETPLACE_PRIVATE_KEY=your_private_key + GITHUB_TOKEN=your_github_token + ``` + +3. **First-time setup only**: Run the setup script: + ```bash + ./scripts/setup-first-time.sh + ``` + This script will: + - Set up a local Magento installation using Docker + - Configure the necessary ports and hosts + - Mount your module code into the Magento installation + - Enable and configure the module + - Start the Docker containers + + > **Note**: This script should only be run once during the initial setup. It already starts the containers, so there's no need to run `start-env.sh` after it. + +4. **For subsequent development sessions**: Start the development environment: + ```bash + ./scripts/start-env.sh + ``` + +### Development Workflow + +- The module code is mounted into the Magento installation, so any changes you make to the code will be immediately reflected +- The Magento installation is available at `https://magento.grin.co.test:8443` +- Admin panel is available at `https://magento.grin.co.test:8443/admin` + - Username: `admin` + - Password: `admin123` + +### Troubleshooting + +If you encounter any issues: + +1. Check if the module is properly enabled: + ```bash + cd .docker-magento + bin/clinotty bin/magento module:status Grin_Module + ``` + +2. If the module is disabled, try re-enabling it: + ```bash + cd .docker-magento + bin/clinotty bin/magento module:enable Grin_Module --force + bin/clinotty bin/magento setup:upgrade + bin/clinotty bin/magento cache:flush + ``` + +3. Check the Magento logs in the container: + ```bash + cd .docker-magento + bin/clinotty tail -f var/log/system.log + ``` + +### Credits + +This local development setup is based on [markshust/docker-magento](https://github.com/markshust/docker-magento). diff --git a/scripts/magento-auth.template b/scripts/magento-auth.template new file mode 100644 index 0000000..dd0b85c --- /dev/null +++ b/scripts/magento-auth.template @@ -0,0 +1,9 @@ +# Magento Marketplace Authentication +# Copy this file to magento-auth.env and fill in your credentials +# You can get these from https://marketplace.magento.com/customer/accessKeys/ + +MAGENTO_MARKETPLACE_PUBLIC_KEY=your_public_key_here +MAGENTO_MARKETPLACE_PRIVATE_KEY=your_private_key_here + +# GitHub token for Composer +GITHUB_TOKEN=your_github_token_here \ No newline at end of file diff --git a/scripts/setup-first-time.sh b/scripts/setup-first-time.sh new file mode 100755 index 0000000..f3ec74f --- /dev/null +++ b/scripts/setup-first-time.sh @@ -0,0 +1,195 @@ +#!/bin/bash + +# Get the root directory (parent of scripts directory) +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# Check if we're in a Magento root directory +if [ -f "$ROOT_DIR/bin/magento" ]; then + echo "Error: You appear to be in a Magento root directory" + echo "Please run this script from a parent directory." + exit 1 +fi + +# Check for magento-auth.env file +AUTH_FILE="$ROOT_DIR/scripts/magento-auth.env" +if [ ! -f "$AUTH_FILE" ]; then + echo "Error: magento-auth.env file not found" + echo "Please copy scripts/magento-auth.template to scripts/magento-auth.env and add your Magento Marketplace credentials" + exit 1 +fi + +# Source the auth file +source "$AUTH_FILE" + +# Validate credentials +if [ -z "$MAGENTO_MARKETPLACE_PUBLIC_KEY" ] || [ -z "$MAGENTO_MARKETPLACE_PRIVATE_KEY" ] || [ -z "$GITHUB_TOKEN" ]; then + echo "Error: Magento Marketplace credentials not found in magento-auth.env" + echo "Please add your public and private keys to the file" + exit 1 +fi + +# Create a directory for the Magento installation +MAGENTO_DIR="$ROOT_DIR/.docker-magento" +if [ -d "$MAGENTO_DIR" ]; then + echo "Error: Directory $MAGENTO_DIR already exists" + echo "Please remove it before running this script." + exit 1 +fi + +mkdir -p $MAGENTO_DIR +cd $MAGENTO_DIR + +# Initialize git and download the templates +git init -qqq +git remote add origin https://github.com/markshust/docker-magento +git fetch origin -qqq +git checkout 51020e8ea366e1bcccc4126c07a13caad5182c15 -- compose # points to origin/master v52.0.1 + +# Check if the compose directory exists +if [ ! -d "compose" ]; then + echo "Error: Failed to download Docker templates" + exit 1 +fi + +# Move the Docker files to our installation directory +mv compose/* . +mv compose/.gitignore . +mv compose/.vscode . +rm -rf compose .git + +# Go back to root directory +cd $ROOT_DIR + +# Update ports in the compose file +COMPOSE_FILE="$MAGENTO_DIR/compose.yaml" + +# Function to replace port mapping +replace_port() { + local service=$1 + local old_port=$2 + local new_port=$3 + + # Handle app service format (e.g., "80:8000") + if [ "$service" = "app" ]; then + # Use a more precise sed command to match the exact line + sed -i '' "/ports:/,/volumes:/ s/\"$old_port:/\"$new_port:/g" "$COMPOSE_FILE" + return + fi + + # Handle standard format (e.g., "6379:6379") + pattern="\"$old_port:$old_port\"" + replacement="\"$new_port:$old_port\"" + sed -i '' "s/$pattern/$replacement/g" "$COMPOSE_FILE" +} + +# Function to update hosts file +update_hosts_file() { + local hosts_entry="127.0.0.1 magento.grin.co.test" + + # Check if the entry already exists + if ! grep -q "$hosts_entry" /etc/hosts; then + echo "Adding magento.grin.co.test to hosts file..." + echo "$hosts_entry" | sudo tee -a /etc/hosts + fi +} + +# Ports have been automatically updated to avoid conflicts with app.grin.co +replace_port "app" "80" "8081" +replace_port "app" "443" "8443" +replace_port "mysql" "3306" "3307" +replace_port "redis" "6379" "6380" +replace_port "opensearch" "9200" "9201" +replace_port "rabbitmq" "5672" "5673" +replace_port "mailcatcher" "1025" "1026" + +# Update hosts file +update_hosts_file + +# Create/overwrite magento.env file +MAGENTO_ENV_FILE="$MAGENTO_DIR/bin/../env/magento.env" +echo "Creating magento.env file at $MAGENTO_ENV_FILE..." +mkdir -p "$(dirname "$MAGENTO_ENV_FILE")" +cat > "$MAGENTO_ENV_FILE" << EOL +MAGENTO_ADMIN_EMAIL=admin@grin.co +MAGENTO_ADMIN_FIRST_NAME=Admin +MAGENTO_ADMIN_LAST_NAME=User +MAGENTO_ADMIN_USER=admin +MAGENTO_ADMIN_PASSWORD=admin123 +MAGENTO_ADMIN_FRONTNAME=admin +MAGENTO_LOCALE=en_US +MAGENTO_CURRENCY=USD +MAGENTO_TIMEZONE=America/New_York +EOL + +# Run the setup script +cd $MAGENTO_DIR + +# Download Magento first +echo "Downloading Magento..." +echo "Note: This may take several minutes to complete..." + +# Set up authentication +export COMPOSER_AUTH="{\"http-basic\":{\"repo.magento.com\":{\"username\":\"$MAGENTO_MARKETPLACE_PUBLIC_KEY\",\"password\":\"$MAGENTO_MARKETPLACE_PRIVATE_KEY\"}},\"github-oauth\":{\"github.com\":\"$GITHUB_TOKEN\"}}" + +# Set up GitHub token in container +bin/clinotty composer config -g github-oauth.github.com "$GITHUB_TOKEN" + +# Patch bin/download to add timeout and other flags to composer create-project +sed -i '' 's|composer create-project --repository-url=https://repo.mage-os.org/ mage-os/project-community-edition="${VERSION}" \.|composer create-project --no-progress --prefer-dist --repository-url=https://repo.mage-os.org/ mage-os/project-community-edition="${VERSION}" .|' "$MAGENTO_DIR/bin/download" +sed -i '' 's|composer create-project --repository=https://repo.magento.com/ magento/project-"${EDITION}"-edition="${VERSION}" \.|composer create-project --no-progress --prefer-dist --repository=https://repo.magento.com/ magento/project-"${EDITION}"-edition="${VERSION}" .|' "$MAGENTO_DIR/bin/download" + +# Set composer timeout +bin/clinotty composer config -g process-timeout 2000 + +# Patch bin/setup to use absolute paths for magento.env +sed -i '' 's|if \[ -f "\.\.\/env\/magento\.env" \]; then|SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" \&\& pwd)"\nif [ -f "$SCRIPT_DIR/../env/magento.env" ]; then|' "$MAGENTO_DIR/bin/setup" +sed -i '' 's|source "\.\.\/env\/magento\.env"|source "$SCRIPT_DIR/../env/magento.env"|' "$MAGENTO_DIR/bin/setup" + +# Patch bin/setup to show correct port in URLs +sed -i '' 's|https://${DOMAIN}/|https://${DOMAIN}:8443/|' "$MAGENTO_DIR/bin/setup" +sed -i '' 's|https://${DOMAIN}/admin/|https://${DOMAIN}:8443/admin/|' "$MAGENTO_DIR/bin/setup" + +# Patch bin/setup-install to set correct base URLs with port +sed -i '' 's|--base-url=https://"$DOMAIN"/|--base-url=https://"$DOMAIN":8443/|' "$MAGENTO_DIR/bin/setup-install" +sed -i '' 's|--base-url-secure=https://"$DOMAIN"/|--base-url-secure=https://"$DOMAIN":8443/|' "$MAGENTO_DIR/bin/setup-install" + +# Run download inside the container +bin/download community 2.4.8 + +# Then run the setup with the domain parameter +bin/setup "magento.grin.co.test" + +# Update web configuration to use correct port +bin/clinotty bin/magento config:set web/secure/base_url "https://magento.grin.co.test:8443/" +bin/clinotty bin/magento config:set web/unsecure/base_url "https://magento.grin.co.test:8443/" +bin/clinotty bin/magento config:set web/secure/use_in_frontend 1 +bin/clinotty bin/magento config:set web/secure/use_in_adminhtml 1 +bin/clinotty bin/magento cache:flush + +# Add module volume mount to Docker Compose +echo "Adding module volume mount to Docker Compose..." +cat << EOF | sed -i '' '/volumes:/r /dev/stdin' "$MAGENTO_DIR/compose.yaml" + - ${ROOT_DIR}:/var/www/html/app/code/Grin/Module:delegated,exclude=.docker-magento +EOF + +# Enable and setup our module +echo "Setting up GRIN module..." +bin/clinotty bin/magento module:enable Grin_Module --force +bin/clinotty bin/magento setup:upgrade +bin/clinotty bin/magento setup:di:compile +bin/clinotty bin/magento setup:static-content:deploy -f +bin/clinotty bin/magento cache:flush +bin/clinotty bin/magento cron:run + +# Verify module installation +echo "Verifying module installation..." +bin/clinotty bin/magento module:status Grin_Module + +# Disable Two-Factor Authentication +echo "Disabling Two-Factor Authentication..." +bin/clinotty bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth +bin/clinotty bin/magento setup:upgrade +bin/clinotty bin/magento cache:flush + +echo "" +echo "Install complete." \ No newline at end of file diff --git a/scripts/start-env.sh b/scripts/start-env.sh new file mode 100755 index 0000000..aa210cb --- /dev/null +++ b/scripts/start-env.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Check if Docker is running +if ! docker info > /dev/null 2>&1; then + echo "Error: Docker is not running" + exit 1 +fi + +# Check if .docker-magento directory exists +if [ ! -d ".docker-magento" ]; then + echo "Error: .docker-magento directory not found" + echo "Please run setup-first-time.sh first" + exit 1 +fi + +# Check if we're in the right directory +if [ ! -f ".docker-magento/compose.yaml" ]; then + echo "Error: Please run this script from the root directory of the module" + exit 1 +fi + +# Stop any existing containers +cd .docker-magento +echo "Stopping any existing containers..." +docker-compose down -v + +# Start the Docker containers +echo "Starting containers..." +docker-compose up -d + +# Wait for services to be ready +echo "Waiting for services to be ready..." +sleep 10 + +# Check if containers are running +if ! docker-compose ps | grep -q "Up"; then + echo "Error: Some containers failed to start. Please check the logs with:" + echo "cd .docker-magento && docker-compose logs" + exit 1 +fi + +echo "Magento environment is starting up!" +echo "You can access Magento at https://magento.grin.co.test:8443" +echo "Admin URL: https://magento.grin.co.test:8443/admin" +echo "Admin credentials: admin/admin123" +echo "" From a7eebcb6c2b707bb17a6403ae1d8edffbb5aa4af Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Mon, 2 Jun 2025 10:22:30 -0600 Subject: [PATCH 02/15] Add sample data installation and unit test configuration (#30) --- README.md | 119 ++++++++++++++++++++++++++++----- phpunit.xml | 26 +++++++ scripts/install-sample-data.sh | 24 +++++++ scripts/run-tests.sh | 21 ++++++ 4 files changed, 174 insertions(+), 16 deletions(-) create mode 100644 phpunit.xml create mode 100755 scripts/install-sample-data.sh create mode 100755 scripts/run-tests.sh diff --git a/README.md b/README.md index 295c4e4..ac192c6 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,25 @@ Influencer marketing for ecommerce. For more information go to https://grin.co/ - -Install -- +## Table of Contents + +- [Install](#install) +- [Update](#update) +- [Some notes](#some-notes) +- [Q&A](#qa) +- [Local Development](#local-development) + - [Prerequisites](#prerequisites) + - [Installation](#installation) + - [Installing Sample Data](#installing-sample-data) + - [Port Configuration](#port-configuration) + - [Getting Required Credentials](#getting-required-credentials) + - [Setup Steps](#setup-steps) + - [Development Workflow](#development-workflow) + - [Troubleshooting](#troubleshooting) + - [Running Unit Tests](#running-unit-tests) +- [Credits](#credits) + +## Install 1. composer config repositories.grin vcs https://github.com/grininc/grin-magento-module 2. composer require grin/module @@ -13,8 +29,7 @@ Install 5. bin/magento setup:static-content:deploy 6. bin/magento cache:flush -Update -- +## Update 1. composer update grin/module 2. bin/magento setup:upgrade @@ -22,16 +37,14 @@ Update 4. bin/magento setup:static-content:deploy 5. bin/magento cache:flush -Some notes -- +## Some notes - Grin uses composer to provide their extension to the end customer. - The extension follows semver principles. - Once the new implementation of Grin_Affiliate is ready to be installed and tested it will get version 2.0.x. - If an end-user has the previous version of the extension installed via https://docs.magento.com/user-guide/v2.3/system/web-setup-wizard.html or manually in app/code, the extension must be removed before new installation. -Q&A -- +## Q&A 1. Issue: I updated the extension, but it seems like the old version is installed despite the fact that in the compose.lock file I see the updated version of the extension. @@ -56,16 +69,59 @@ Possible solution: in this case, according to Magento documentation, you need to ... ``` -Local Development -- +## Local Development This module uses Docker for local development. Follow these steps to set up your development environment: ### Prerequisites -1. Docker and Docker Compose installed on your machine -2. Magento Marketplace credentials -3. GitHub Personal Access Token +- Docker +- Docker Compose +- PHP 8.1 or higher +- Composer + +### Installation + +1. Clone the repository +2. Install dependencies: + ```bash + composer install + ``` +3. Copy the environment file: + ```bash + cp .env.example .env + ``` +4. Start the Docker containers: + ```bash + docker-compose up -d + ``` +5. Install the module: + ```bash + ./scripts/install-module.sh + ``` + +### Installing Sample Data + +To populate your Magento store with sample products, categories, and other content, you can use the provided script: + +```bash +./scripts/install-sample-data.sh +``` + +This script will: +1. Set Magento to developer mode +2. Install the sample data +3. Run setup upgrade +4. Clean and flush the cache + +After running this script, you'll have: +- Sample products to test with +- Categories +- Customer accounts +- Sales rules (including coupon codes) +- And more + +This makes it easier to test functionality like coupon codes and other features that require store content. ### Port Configuration @@ -135,6 +191,19 @@ These ports are automatically configured during setup to avoid conflicts with ot - Username: `admin` - Password: `admin123` +#### After Code Changes + +When you modify plugin code or other PHP files: +1. Clear the Magento cache: + ```bash + cd .docker-magento + bin/clinotty bin/magento cache:clean + bin/clinotty bin/magento cache:flush + ``` +2. Refresh your browser page + +> **Note**: In developer mode, you don't need to run `setup:di:compile` after every change. However, if you're in production mode, you would need to run it. + ### Troubleshooting If you encounter any issues: @@ -159,6 +228,24 @@ If you encounter any issues: bin/clinotty tail -f var/log/system.log ``` -### Credits +### Running Unit Tests + +To run unit tests for this module, use the provided script: + +```bash +./scripts/run-tests.sh +``` + +- This will run all tests in the `Test` directory. + +To run a specific test file, provide the relative path from the module root: + +```bash +./scripts/run-tests.sh Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php +``` + +The script will automatically execute the tests inside the Docker container using the correct environment. + +## Credits -This local development setup is based on [markshust/docker-magento](https://github.com/markshust/docker-magento). +This local development setup is based on [markshust/docker-magento](https://github.com/markshust/docker-magento). diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..acebd62 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + + ./Test/Unit + + + + + ./Test/Unit + + ./Test/Api + ./.docker-magento + + + + + + + + + \ No newline at end of file diff --git a/scripts/install-sample-data.sh b/scripts/install-sample-data.sh new file mode 100755 index 0000000..a6d3212 --- /dev/null +++ b/scripts/install-sample-data.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Exit on error +set -e + +# Change to the Magento root directory +cd .docker-magento + +echo "Setting developer mode..." +bin/magento deploy:mode:set developer + +echo "Installing sample data..." +bin/magento sampledata:deploy + +echo "Running setup upgrade..." +bin/magento setup:upgrade + +echo "Cleaning cache..." +bin/magento cache:clean + +echo "Flushing cache..." +bin/magento cache:flush + +echo "Sample data installation completed!" diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100755 index 0000000..f9d9ab4 --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Get the root directory (parent of scripts directory) +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# Change to .docker-magento directory +cd "$ROOT_DIR/.docker-magento" + +if [ -z "$1" ]; then + # No parameter: run all tests in the Test directory + echo "Listing all tests:" + ./bin/clinotty vendor/bin/phpunit --configuration /var/www/html/app/code/Grin/Module/phpunit.xml --list-tests "/var/www/html/app/code/Grin/Module/Test" + echo -e "\nRunning tests:" + ./bin/clinotty vendor/bin/phpunit --configuration /var/www/html/app/code/Grin/Module/phpunit.xml "/var/www/html/app/code/Grin/Module/Test" +else + # Parameter provided: run the specific test file + echo "Listing tests in file:" + ./bin/clinotty vendor/bin/phpunit --configuration /var/www/html/app/code/Grin/Module/phpunit.xml --list-tests "/var/www/html/app/code/Grin/Module/$1" + echo -e "\nRunning tests:" + ./bin/clinotty vendor/bin/phpunit --configuration /var/www/html/app/code/Grin/Module/phpunit.xml "/var/www/html/app/code/Grin/Module/$1" +fi \ No newline at end of file From 28246b6f232faf2c8f5f7116f32ff027e1392a24 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Wed, 4 Jun 2025 11:08:03 -0600 Subject: [PATCH 03/15] EX-774: convert string coupon code to array for consistent handling (#31) --- .github/workflows/coding-standard.yml | 4 +- .github/workflows/mess-detector.yml | 2 +- .github/workflows/unit-tests.yml | 16 +++ .gitignore | 1 + .../Model/RulesApplier/ValidateByToken.php | 9 +- README.md | 101 +++++++-------- .../RulesApplier/ValidateByTokenTest.php | 115 ++++++++++++++++++ phpunit.xml | 36 +++--- scripts/magento-auth.template | 2 +- scripts/run-coding-standard.sh | 30 +++++ scripts/setup-first-time.sh | 101 +++++++++++---- 11 files changed, 317 insertions(+), 100 deletions(-) create mode 100644 .github/workflows/unit-tests.yml create mode 100644 Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php create mode 100755 scripts/run-coding-standard.sh diff --git a/.github/workflows/coding-standard.yml b/.github/workflows/coding-standard.yml index ab13fa7..5d77360 100644 --- a/.github/workflows/coding-standard.yml +++ b/.github/workflows/coding-standard.yml @@ -6,5 +6,5 @@ jobs: name: M2 Coding Standard runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: extdn/github-actions-m2/magento-coding-standard@master + - uses: actions/checkout@v4 + - uses: extdn/github-actions-m2/magento-coding-standard/8.3@master diff --git a/.github/workflows/mess-detector.yml b/.github/workflows/mess-detector.yml index 9ca60d1..ff60451 100644 --- a/.github/workflows/mess-detector.yml +++ b/.github/workflows/mess-detector.yml @@ -6,5 +6,5 @@ jobs: name: M2 Mess Detector runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: extdn/github-actions-m2/magento-mess-detector@master diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..ca4d6a4 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,16 @@ +name: M2 Unit Tests +on: [push, pull_request] + +jobs: + unit-tests: + name: M2 Unit Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: extdn/github-actions-m2/magento-unit-tests/8.3@master + with: + composer_name: grin/module + module_name: Grin_Module + php_version: 8.3 + magento_version: 2.4.8 + project_name: magento/project-community-edition diff --git a/.gitignore b/.gitignore index 6ea9cd2..f4077c8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ bin/ env/ template/ +.phpunit.result.cache diff --git a/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php b/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php index 381f589..a2fc9c8 100644 --- a/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php +++ b/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php @@ -40,12 +40,15 @@ public function aroundApplyRules( $skipValidation, $couponCode ): array { + // Convert string coupon code to array for consistent handling + $couponCodes = is_array($couponCode) ? $couponCode : [$couponCode]; + foreach ($rules as $rule) { - if (!$this->salesRuleValidator->isValid($rule, $couponCode)) { - return $proceed($item, [], $skipValidation, $couponCode); + if (!$this->salesRuleValidator->isValid($rule, $couponCodes)) { + return $proceed($item, [], $skipValidation, $couponCodes); } } - return $proceed($item, $rules, $skipValidation, $couponCode); + return $proceed($item, $rules, $skipValidation, $couponCodes); } } diff --git a/README.md b/README.md index ac192c6..b76bf1b 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,24 @@ -# Grin Module +# Grin Module Influencer marketing for ecommerce. For more information go to https://grin.co/ -## Table of Contents +## Table of Contents - [Install](#install) - [Update](#update) - [Some notes](#some-notes) -- [Q&A](#qa) +- [Q\&A](#qa) - [Local Development](#local-development) - [Prerequisites](#prerequisites) - - [Installation](#installation) - - [Installing Sample Data](#installing-sample-data) - [Port Configuration](#port-configuration) - [Getting Required Credentials](#getting-required-credentials) - [Setup Steps](#setup-steps) - [Development Workflow](#development-workflow) + - [Installing Sample Data](#installing-sample-data) + - [After Code Changes](#after-code-changes) - [Troubleshooting](#troubleshooting) - [Running Unit Tests](#running-unit-tests) + - [Running Coding Standards](#running-coding-standards) - [Credits](#credits) ## Install @@ -80,49 +81,6 @@ This module uses Docker for local development. Follow these steps to set up your - PHP 8.1 or higher - Composer -### Installation - -1. Clone the repository -2. Install dependencies: - ```bash - composer install - ``` -3. Copy the environment file: - ```bash - cp .env.example .env - ``` -4. Start the Docker containers: - ```bash - docker-compose up -d - ``` -5. Install the module: - ```bash - ./scripts/install-module.sh - ``` - -### Installing Sample Data - -To populate your Magento store with sample products, categories, and other content, you can use the provided script: - -```bash -./scripts/install-sample-data.sh -``` - -This script will: -1. Set Magento to developer mode -2. Install the sample data -3. Run setup upgrade -4. Clean and flush the cache - -After running this script, you'll have: -- Sample products to test with -- Categories -- Customer accounts -- Sales rules (including coupon codes) -- And more - -This makes it easier to test functionality like coupon codes and other features that require store content. - ### Port Configuration The development environment uses custom ports to avoid conflicts with other services: @@ -191,7 +149,30 @@ These ports are automatically configured during setup to avoid conflicts with ot - Username: `admin` - Password: `admin123` -#### After Code Changes +### Installing Sample Data + +To populate your Magento store with sample products, categories, and other content, you can use the provided script: + +```bash +./scripts/install-sample-data.sh +``` + +This script will: +1. Set Magento to developer mode +2. Install the sample data +3. Run setup upgrade +4. Clean and flush the cache + +After running this script, you'll have: +- Sample products to test with +- Categories +- Customer accounts +- Sales rules (including coupon codes) +- And more + +This makes it easier to test functionality like coupon codes and other features that require store content. + +### After Code Changes When you modify plugin code or other PHP files: 1. Clear the Magento cache: @@ -246,6 +227,28 @@ To run a specific test file, provide the relative path from the module root: The script will automatically execute the tests inside the Docker container using the correct environment. +### Running Coding Standards + +To check your code against Magento's coding standards, use the provided script: + +```bash +./scripts/run-coding-standard.sh +``` + +- This will check all files in the module against Magento's coding standards. +- Generated code and Docker-related files are automatically ignored. + +To check a specific file, provide the relative path from the module root: + +```bash +./scripts/run-coding-standard.sh Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php +``` + +The script will: +1. Run the coding standard check inside the Docker container +2. Generate a detailed report +3. Display any warnings or errors found + ## Credits This local development setup is based on [markshust/docker-magento](https://github.com/markshust/docker-magento). diff --git a/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php b/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php new file mode 100644 index 0000000..fb147b6 --- /dev/null +++ b/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php @@ -0,0 +1,115 @@ +salesRuleValidator = $this->createMock(SalesRuleValidator::class); + $this->validateByToken = new ValidateByToken($this->salesRuleValidator); + } + + /** + * @dataProvider couponCodeProvider + */ + public function testAroundApplyRules(mixed $couponCode): void + { + /** @var RulesApplier&MockObject $subject */ + $subject = $this->createMock(RulesApplier::class); + /** @var Rule&MockObject $rule */ + $rule = $this->createMock(Rule::class); + /** @var \Magento\Quote\Model\Quote\Item\AbstractItem&MockObject $item */ + $item = $this->createMock(\Magento\Quote\Model\Quote\Item\AbstractItem::class); + $rules = [$rule]; + + $proceed = function ($item, $rules, $skipValidation, $couponCode) { + return ['result']; + }; + + $this->salesRuleValidator->expects($this->once()) + ->method('isValid') + ->with($rule, is_array($couponCode) ? $couponCode : [$couponCode]) + ->willReturn(true); + + $result = $this->validateByToken->aroundApplyRules( + $subject, + $proceed, + $item, + $rules, + false, + $couponCode + ); + + $this->assertEqualsCanonicalizing(['result'], $result); + } + + /** + * @return array> + */ + public static function couponCodeProvider(): array + { + return [ + 'string coupon code' => ['TEST123'], + 'array coupon code' => [['TEST123', 'TEST456']], + 'empty array' => [[]], + 'null' => [null], + ]; + } + + /** + * @dataProvider couponCodeProvider + */ + public function testAroundApplyRulesWithInvalidRule(mixed $couponCode): void + { + /** @var RulesApplier&MockObject $subject */ + $subject = $this->createMock(RulesApplier::class); + /** @var Rule&MockObject $rule */ + $rule = $this->createMock(Rule::class); + /** @var \Magento\Quote\Model\Quote\Item\AbstractItem&MockObject $item */ + $item = $this->createMock(\Magento\Quote\Model\Quote\Item\AbstractItem::class); + $rules = [$rule]; + + $proceed = function ($item, $rules, $skipValidation, $couponCode) { + return ['result']; + }; + + $this->salesRuleValidator->expects($this->once()) + ->method('isValid') + ->with($rule, is_array($couponCode) ? $couponCode : [$couponCode]) + ->willReturn(false); + + $result = $this->validateByToken->aroundApplyRules( + $subject, + $proceed, + $item, + $rules, + false, + $couponCode + ); + + $this->assertEqualsCanonicalizing(['result'], $result); + } +} diff --git a/phpunit.xml b/phpunit.xml index acebd62..0d3589e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,26 +1,28 @@ + bootstrap="/var/www/html/dev/tests/unit/framework/bootstrap.php" + stderr="true"> - - ./Test/Unit + + ../../../vendor/grin/module/Test/Unit - - - ./Test/Unit - - ./Test/Api - ./.docker-magento - - - + + + ../../../vendor/grin/module + + + ../../../lib/internal/*/*/Test + ../../../lib/internal/*/*/*/Test + ../../../setup/src/*/*/Test + + - - - + + - \ No newline at end of file + + \ No newline at end of file diff --git a/scripts/magento-auth.template b/scripts/magento-auth.template index dd0b85c..5ea8286 100644 --- a/scripts/magento-auth.template +++ b/scripts/magento-auth.template @@ -6,4 +6,4 @@ MAGENTO_MARKETPLACE_PUBLIC_KEY=your_public_key_here MAGENTO_MARKETPLACE_PRIVATE_KEY=your_private_key_here # GitHub token for Composer -GITHUB_TOKEN=your_github_token_here \ No newline at end of file +GITHUB_TOKEN=your_github_token_here diff --git a/scripts/run-coding-standard.sh b/scripts/run-coding-standard.sh new file mode 100755 index 0000000..a5dd165 --- /dev/null +++ b/scripts/run-coding-standard.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Get the root directory (parent of scripts directory) +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# Change to .docker-magento directory +cd "$ROOT_DIR/.docker-magento" + +# Get the file path if provided +FILE_PATH="$1" + +# Define the plugin directory +PLUGIN_DIR="/var/www/html/app/code/Grin/Module" + +# Define patterns to ignore +IGNORE_PATTERNS=".docker-magento/*" + +if [ -z "$FILE_PATH" ]; then + # No parameter: run on entire plugin + echo "Running coding standard check on plugin code..." + ./bin/clinotty vendor/bin/phpcs --standard=Magento2 --colors --no-colors --report=full --report-file=/tmp/phpcs-report.txt --ignore="$IGNORE_PATTERNS" "$PLUGIN_DIR" +else + # Parameter provided: run on specific file + echo "Running coding standard check on file: $FILE_PATH" + ./bin/clinotty vendor/bin/phpcs --standard=Magento2 --colors --no-colors --report=full --report-file=/tmp/phpcs-report.txt --ignore="$IGNORE_PATTERNS" "$PLUGIN_DIR/$FILE_PATH" +fi + +# Display the report +echo -e "\nCoding Standard Report:" +./bin/clinotty cat /tmp/phpcs-report.txt diff --git a/scripts/setup-first-time.sh b/scripts/setup-first-time.sh index f3ec74f..162a7e5 100755 --- a/scripts/setup-first-time.sh +++ b/scripts/setup-first-time.sh @@ -1,8 +1,21 @@ #!/bin/bash +# Exit on any error +set -e + +# Magento version +MAGENTO_VERSION="2.4.8" + # Get the root directory (parent of scripts directory) ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +# Function to handle errors +handle_error() { + echo "Error: Installation failed at step: $1" + echo "Please check the error message above and try again." + exit 1 +} + # Check if we're in a Magento root directory if [ -f "$ROOT_DIR/bin/magento" ]; then echo "Error: You appear to be in a Magento root directory" @@ -43,7 +56,7 @@ cd $MAGENTO_DIR git init -qqq git remote add origin https://github.com/markshust/docker-magento git fetch origin -qqq -git checkout 51020e8ea366e1bcccc4126c07a13caad5182c15 -- compose # points to origin/master v52.0.1 +git checkout 52.0.1 -- compose # Check if the compose directory exists if [ ! -d "compose" ]; then @@ -128,19 +141,10 @@ cd $MAGENTO_DIR echo "Downloading Magento..." echo "Note: This may take several minutes to complete..." -# Set up authentication -export COMPOSER_AUTH="{\"http-basic\":{\"repo.magento.com\":{\"username\":\"$MAGENTO_MARKETPLACE_PUBLIC_KEY\",\"password\":\"$MAGENTO_MARKETPLACE_PRIVATE_KEY\"}},\"github-oauth\":{\"github.com\":\"$GITHUB_TOKEN\"}}" - -# Set up GitHub token in container -bin/clinotty composer config -g github-oauth.github.com "$GITHUB_TOKEN" - # Patch bin/download to add timeout and other flags to composer create-project sed -i '' 's|composer create-project --repository-url=https://repo.mage-os.org/ mage-os/project-community-edition="${VERSION}" \.|composer create-project --no-progress --prefer-dist --repository-url=https://repo.mage-os.org/ mage-os/project-community-edition="${VERSION}" .|' "$MAGENTO_DIR/bin/download" sed -i '' 's|composer create-project --repository=https://repo.magento.com/ magento/project-"${EDITION}"-edition="${VERSION}" \.|composer create-project --no-progress --prefer-dist --repository=https://repo.magento.com/ magento/project-"${EDITION}"-edition="${VERSION}" .|' "$MAGENTO_DIR/bin/download" -# Set composer timeout -bin/clinotty composer config -g process-timeout 2000 - # Patch bin/setup to use absolute paths for magento.env sed -i '' 's|if \[ -f "\.\.\/env\/magento\.env" \]; then|SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" \&\& pwd)"\nif [ -f "$SCRIPT_DIR/../env/magento.env" ]; then|' "$MAGENTO_DIR/bin/setup" sed -i '' 's|source "\.\.\/env\/magento\.env"|source "$SCRIPT_DIR/../env/magento.env"|' "$MAGENTO_DIR/bin/setup" @@ -153,18 +157,50 @@ sed -i '' 's|https://${DOMAIN}/admin/|https://${DOMAIN}:8443/admin/|' "$MAGENTO_ sed -i '' 's|--base-url=https://"$DOMAIN"/|--base-url=https://"$DOMAIN":8443/|' "$MAGENTO_DIR/bin/setup-install" sed -i '' 's|--base-url-secure=https://"$DOMAIN"/|--base-url-secure=https://"$DOMAIN":8443/|' "$MAGENTO_DIR/bin/setup-install" +# Start the containers to inject the environment variables +bin/start --no-dev + +# Wait for containers to be ready +echo "Waiting for containers to be ready..." +sleep 10 + +# Set up authentication in the correct order +echo "Setting up authentication..." + +# Create a temporary Composer home directory in the container +bin/clinotty bash << EOF +set -e + +# Create temporary and permanent Composer directories +mkdir -p /var/www/.composer-temp +mkdir -p /var/www/.composer + +# Set up temporary Composer home +export COMPOSER_HOME=/var/www/.composer-temp + +# Set up GitHub token +composer config --global github-oauth.github.com "${GITHUB_TOKEN}" || exit 1 + +# Set up Magento Marketplace credentials +composer config --global http-basic.repo.magento.com "${MAGENTO_MARKETPLACE_PUBLIC_KEY}" "${MAGENTO_MARKETPLACE_PRIVATE_KEY}" || exit 1 + +# Copy the auth.json to the correct location +cp /var/www/.composer-temp/auth.json /var/www/.composer/auth.json || exit 1 +EOF +[ $? -eq 0 ] || handle_error "Setting up authentication" + # Run download inside the container -bin/download community 2.4.8 +bin/download community "$MAGENTO_VERSION" || handle_error "Downloading Magento" # Then run the setup with the domain parameter -bin/setup "magento.grin.co.test" +bin/setup "magento.grin.co.test" || handle_error "Setting up Magento" # Update web configuration to use correct port -bin/clinotty bin/magento config:set web/secure/base_url "https://magento.grin.co.test:8443/" -bin/clinotty bin/magento config:set web/unsecure/base_url "https://magento.grin.co.test:8443/" -bin/clinotty bin/magento config:set web/secure/use_in_frontend 1 -bin/clinotty bin/magento config:set web/secure/use_in_adminhtml 1 -bin/clinotty bin/magento cache:flush +bin/clinotty bin/magento config:set web/secure/base_url "https://magento.grin.co.test:8443/" || handle_error "Setting secure base URL" +bin/clinotty bin/magento config:set web/unsecure/base_url "https://magento.grin.co.test:8443/" || handle_error "Setting unsecure base URL" +bin/clinotty bin/magento config:set web/secure/use_in_frontend 1 || handle_error "Setting secure frontend" +bin/clinotty bin/magento config:set web/secure/use_in_adminhtml 1 || handle_error "Setting secure admin" +bin/clinotty bin/magento cache:flush || handle_error "Flushing cache" # Add module volume mount to Docker Compose echo "Adding module volume mount to Docker Compose..." @@ -172,24 +208,35 @@ cat << EOF | sed -i '' '/volumes:/r /dev/stdin' "$MAGENTO_DIR/compose.yaml" - ${ROOT_DIR}:/var/www/html/app/code/Grin/Module:delegated,exclude=.docker-magento EOF +# Restart containers to apply volume mount +bin/restart + +# Wait for containers to be ready +echo "Waiting for containers to be ready..." +sleep 10 + # Enable and setup our module echo "Setting up GRIN module..." -bin/clinotty bin/magento module:enable Grin_Module --force -bin/clinotty bin/magento setup:upgrade -bin/clinotty bin/magento setup:di:compile -bin/clinotty bin/magento setup:static-content:deploy -f -bin/clinotty bin/magento cache:flush -bin/clinotty bin/magento cron:run +bin/clinotty bin/magento module:enable Grin_Module --force || handle_error "Enabling module" +bin/clinotty bin/magento setup:upgrade || handle_error "Running setup:upgrade" +bin/clinotty bin/magento setup:di:compile || handle_error "Running setup:di:compile" +bin/clinotty bin/magento setup:static-content:deploy -f || handle_error "Deploying static content" +bin/clinotty bin/magento cache:flush || handle_error "Flushing cache" +bin/clinotty bin/magento cron:run || handle_error "Running cron" + +# Install Magento coding standard +echo "Installing Magento coding standard..." +bin/clinotty composer require --dev magento/magento-coding-standard || handle_error "Installing coding standard" # Verify module installation echo "Verifying module installation..." -bin/clinotty bin/magento module:status Grin_Module +bin/clinotty bin/magento module:status Grin_Module || handle_error "Verifying module status" # Disable Two-Factor Authentication echo "Disabling Two-Factor Authentication..." -bin/clinotty bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth -bin/clinotty bin/magento setup:upgrade -bin/clinotty bin/magento cache:flush +bin/clinotty bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth || handle_error "Disabling 2FA" +bin/clinotty bin/magento setup:upgrade || handle_error "Running setup:upgrade after 2FA" +bin/clinotty bin/magento cache:flush || handle_error "Final cache flush" echo "" echo "Install complete." \ No newline at end of file From 693c35eb91b74c75d7d6bdbe41fd386707c051f9 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 12:29:57 -0600 Subject: [PATCH 04/15] refactor: move Magento module code into src/ to prevent Docker volume conflicts (#32) --- .github/workflows/unit-tests.yml | 3 ++- scripts/setup-first-time.sh | 8 ++++++-- {Api => src/Api}/Data/RequestInterface.php | 0 {Api => src/Api}/Data/RuleStagingInterface.php | 0 {Api => src/Api}/Data/StagingDataInterface.php | 0 {Api => src/Api}/GrinServiceInterface.php | 0 {Api => src/Api}/PublisherInterface.php | 0 {Api => src/Api}/RuleStagingRepositoryInterface.php | 0 {Api => src/Api}/StockItemsInterface.php | 0 {Block => src/Block}/Checkout/CartWidget.php | 0 {Block => src/Block}/Checkout/Success.php | 0 {Block => src/Block}/Footer/FooterScript.php | 0 {Block => src/Block}/System/Version.php | 0 .../Controller}/Adminhtml/Queue/Messages.php | 0 {Model => src/Model}/Carrier/Method.php | 0 {Model => src/Model}/Data/Request.php | 0 {Model => src/Model}/Data/RuleStaging.php | 0 {Model => src/Model}/Data/StagingData.php | 0 {Model => src/Model}/Grid/Source/MessageStatus.php | 0 {Model => src/Model}/GrinService.php | 0 .../Model}/Http/Client/Adapter/CurlFactory.php | 0 {Model => src/Model}/Http/UriFactory.php | 0 {Model => src/Model}/Message/Invalid.php | 0 {Model => src/Model}/OrderTracker.php | 0 {Model => src/Model}/Queue/Consumer.php | 0 {Model => src/Model}/Queue/ConsumerHandler.php | 0 {Model => src/Model}/Queue/InvokerFactory.php | 0 {Model => src/Model}/Queue/Publisher.php | 0 .../Model}/Queue/ResourceModel/ResponseHandler.php | 0 {Model => src/Model}/Queue/StoreIdsManager.php | 0 {Model => src/Model}/RuleStagingRepository.php | 0 {Model => src/Model}/SalesRuleValidator.php | 0 {Model => src/Model}/StockItems.php | 0 {Model => src/Model}/SystemConfig.php | 0 {Model => src/Model}/WebhookStateInterface.php | 0 {Observer => src/Observer}/CategoryWebhook.php | 0 {Observer => src/Observer}/OrderState.php | 0 {Observer => src/Observer}/OrderWebhook.php | 0 {Observer => src/Observer}/ProductWebhook.php | 0 {Observer => src/Observer}/SalesRule.php | 0 {Observer => src/Observer}/StockItemWebhook.php | 0 {Plugin => src/Plugin}/AttributeData.php | 0 .../SalesRule/Model/RulesApplier/ValidateByToken.php | 0 {Test => src/Test}/Api/StockItemsTest.php | 0 .../Test}/Integration/CategoryPublisherTest.php | 0 {Test => src/Test}/Integration/Fixture/Category.php | 0 {Test => src/Test}/Integration/Fixture/Order.php | 0 {Test => src/Test}/Integration/Fixture/Product.php | 0 {Test => src/Test}/Integration/GrinServiceTest.php | 0 .../Integration/Model/MysqlQueueMessageManager.php | 0 {Test => src/Test}/Integration/Model/OrderManager.php | 0 {Test => src/Test}/Integration/OrderPublisherTest.php | 0 .../Test}/Integration/ProductPublisherTest.php | 0 .../Model/RulesApplier/ValidateByTokenTest.php | 0 .../DataProvider/MessageQueue/ListingDataProvider.php | 0 composer.json => src/composer.json | 5 ++++- composer.lock => src/composer.lock | 0 {etc => src/etc}/acl.xml | 0 {etc => src/etc}/adminhtml/di.xml | 0 {etc => src/etc}/adminhtml/menu.xml | 0 {etc => src/etc}/adminhtml/routes.xml | 0 {etc => src/etc}/adminhtml/system.xml | 0 {etc => src/etc}/communication.xml | 0 {etc => src/etc}/config.xml | 0 {etc => src/etc}/db_schema.xml | 0 {etc => src/etc}/db_schema_whitelist.json | 0 {etc => src/etc}/di.xml | 0 {etc => src/etc}/events.xml | 0 {etc => src/etc}/extension_attributes.xml | 0 {etc => src/etc}/module.xml | 0 {etc => src/etc}/queue.xml | 0 {etc => src/etc}/queue_consumer.xml | 0 {etc => src/etc}/queue_publisher.xml | 0 {etc => src/etc}/queue_topology.xml | 0 {etc => src/etc}/webapi.xml | 0 {etc => src/etc}/webapi_rest/di.xml | 0 {i18n => src/i18n}/en_US.csv | 0 phpunit.xml => src/phpunit.xml | 10 +++++----- registration.php => src/registration.php | 0 .../adminhtml/layout/grin_module_queue_messages.xml | 0 .../ui_component/grin_module_queue_messages.xml | 0 .../view}/adminhtml/ui_component/sales_rule_form.xml | 0 .../view}/frontend/layout/checkout_cart_index.xml | 0 .../view}/frontend/layout/checkout_onepage_success.xml | 0 {view => src/view}/frontend/layout/default.xml | 0 .../view}/frontend/templates/affiliate/footer.phtml | 0 .../view}/frontend/templates/affiliate/success.phtml | 0 .../view}/frontend/templates/checkout/cart-id.phtml | 0 .../view}/frontend/web/css/source/_module.less | 0 89 files changed, 17 insertions(+), 9 deletions(-) rename {Api => src/Api}/Data/RequestInterface.php (100%) rename {Api => src/Api}/Data/RuleStagingInterface.php (100%) rename {Api => src/Api}/Data/StagingDataInterface.php (100%) rename {Api => src/Api}/GrinServiceInterface.php (100%) rename {Api => src/Api}/PublisherInterface.php (100%) rename {Api => src/Api}/RuleStagingRepositoryInterface.php (100%) rename {Api => src/Api}/StockItemsInterface.php (100%) rename {Block => src/Block}/Checkout/CartWidget.php (100%) rename {Block => src/Block}/Checkout/Success.php (100%) rename {Block => src/Block}/Footer/FooterScript.php (100%) rename {Block => src/Block}/System/Version.php (100%) rename {Controller => src/Controller}/Adminhtml/Queue/Messages.php (100%) rename {Model => src/Model}/Carrier/Method.php (100%) rename {Model => src/Model}/Data/Request.php (100%) rename {Model => src/Model}/Data/RuleStaging.php (100%) rename {Model => src/Model}/Data/StagingData.php (100%) rename {Model => src/Model}/Grid/Source/MessageStatus.php (100%) rename {Model => src/Model}/GrinService.php (100%) rename {Model => src/Model}/Http/Client/Adapter/CurlFactory.php (100%) rename {Model => src/Model}/Http/UriFactory.php (100%) rename {Model => src/Model}/Message/Invalid.php (100%) rename {Model => src/Model}/OrderTracker.php (100%) rename {Model => src/Model}/Queue/Consumer.php (100%) rename {Model => src/Model}/Queue/ConsumerHandler.php (100%) rename {Model => src/Model}/Queue/InvokerFactory.php (100%) rename {Model => src/Model}/Queue/Publisher.php (100%) rename {Model => src/Model}/Queue/ResourceModel/ResponseHandler.php (100%) rename {Model => src/Model}/Queue/StoreIdsManager.php (100%) rename {Model => src/Model}/RuleStagingRepository.php (100%) rename {Model => src/Model}/SalesRuleValidator.php (100%) rename {Model => src/Model}/StockItems.php (100%) rename {Model => src/Model}/SystemConfig.php (100%) rename {Model => src/Model}/WebhookStateInterface.php (100%) rename {Observer => src/Observer}/CategoryWebhook.php (100%) rename {Observer => src/Observer}/OrderState.php (100%) rename {Observer => src/Observer}/OrderWebhook.php (100%) rename {Observer => src/Observer}/ProductWebhook.php (100%) rename {Observer => src/Observer}/SalesRule.php (100%) rename {Observer => src/Observer}/StockItemWebhook.php (100%) rename {Plugin => src/Plugin}/AttributeData.php (100%) rename {Plugin => src/Plugin}/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php (100%) rename {Test => src/Test}/Api/StockItemsTest.php (100%) rename {Test => src/Test}/Integration/CategoryPublisherTest.php (100%) rename {Test => src/Test}/Integration/Fixture/Category.php (100%) rename {Test => src/Test}/Integration/Fixture/Order.php (100%) rename {Test => src/Test}/Integration/Fixture/Product.php (100%) rename {Test => src/Test}/Integration/GrinServiceTest.php (100%) rename {Test => src/Test}/Integration/Model/MysqlQueueMessageManager.php (100%) rename {Test => src/Test}/Integration/Model/OrderManager.php (100%) rename {Test => src/Test}/Integration/OrderPublisherTest.php (100%) rename {Test => src/Test}/Integration/ProductPublisherTest.php (100%) rename {Test => src/Test}/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php (100%) rename {Ui => src/Ui}/DataProvider/MessageQueue/ListingDataProvider.php (100%) rename composer.json => src/composer.json (86%) rename composer.lock => src/composer.lock (100%) rename {etc => src/etc}/acl.xml (100%) rename {etc => src/etc}/adminhtml/di.xml (100%) rename {etc => src/etc}/adminhtml/menu.xml (100%) rename {etc => src/etc}/adminhtml/routes.xml (100%) rename {etc => src/etc}/adminhtml/system.xml (100%) rename {etc => src/etc}/communication.xml (100%) rename {etc => src/etc}/config.xml (100%) rename {etc => src/etc}/db_schema.xml (100%) rename {etc => src/etc}/db_schema_whitelist.json (100%) rename {etc => src/etc}/di.xml (100%) rename {etc => src/etc}/events.xml (100%) rename {etc => src/etc}/extension_attributes.xml (100%) rename {etc => src/etc}/module.xml (100%) rename {etc => src/etc}/queue.xml (100%) rename {etc => src/etc}/queue_consumer.xml (100%) rename {etc => src/etc}/queue_publisher.xml (100%) rename {etc => src/etc}/queue_topology.xml (100%) rename {etc => src/etc}/webapi.xml (100%) rename {etc => src/etc}/webapi_rest/di.xml (100%) rename {i18n => src/i18n}/en_US.csv (100%) rename phpunit.xml => src/phpunit.xml (66%) rename registration.php => src/registration.php (100%) rename {view => src/view}/adminhtml/layout/grin_module_queue_messages.xml (100%) rename {view => src/view}/adminhtml/ui_component/grin_module_queue_messages.xml (100%) rename {view => src/view}/adminhtml/ui_component/sales_rule_form.xml (100%) rename {view => src/view}/frontend/layout/checkout_cart_index.xml (100%) rename {view => src/view}/frontend/layout/checkout_onepage_success.xml (100%) rename {view => src/view}/frontend/layout/default.xml (100%) rename {view => src/view}/frontend/templates/affiliate/footer.phtml (100%) rename {view => src/view}/frontend/templates/affiliate/success.phtml (100%) rename {view => src/view}/frontend/templates/checkout/cart-id.phtml (100%) rename {view => src/view}/frontend/web/css/source/_module.less (100%) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ca4d6a4..10b5613 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -10,7 +10,8 @@ jobs: - uses: extdn/github-actions-m2/magento-unit-tests/8.3@master with: composer_name: grin/module + magento_version: 2.4.8 module_name: Grin_Module + module_source: src php_version: 8.3 - magento_version: 2.4.8 project_name: magento/project-community-edition diff --git a/scripts/setup-first-time.sh b/scripts/setup-first-time.sh index 162a7e5..5f54847 100755 --- a/scripts/setup-first-time.sh +++ b/scripts/setup-first-time.sh @@ -205,7 +205,7 @@ bin/clinotty bin/magento cache:flush || handle_error "Flushing cache" # Add module volume mount to Docker Compose echo "Adding module volume mount to Docker Compose..." cat << EOF | sed -i '' '/volumes:/r /dev/stdin' "$MAGENTO_DIR/compose.yaml" - - ${ROOT_DIR}:/var/www/html/app/code/Grin/Module:delegated,exclude=.docker-magento + - ${ROOT_DIR}/src:/var/www/html/app/code/Grin/Module:delegated EOF # Restart containers to apply volume mount @@ -239,4 +239,8 @@ bin/clinotty bin/magento setup:upgrade || handle_error "Running setup:upgrade af bin/clinotty bin/magento cache:flush || handle_error "Final cache flush" echo "" -echo "Install complete." \ No newline at end of file +echo "Install complete." +echo "You can access Magento at https://magento.grin.co.test:8443" +echo "Admin URL: https://magento.grin.co.test:8443/admin" +echo "Admin credentials: admin/admin123" +echo "" diff --git a/Api/Data/RequestInterface.php b/src/Api/Data/RequestInterface.php similarity index 100% rename from Api/Data/RequestInterface.php rename to src/Api/Data/RequestInterface.php diff --git a/Api/Data/RuleStagingInterface.php b/src/Api/Data/RuleStagingInterface.php similarity index 100% rename from Api/Data/RuleStagingInterface.php rename to src/Api/Data/RuleStagingInterface.php diff --git a/Api/Data/StagingDataInterface.php b/src/Api/Data/StagingDataInterface.php similarity index 100% rename from Api/Data/StagingDataInterface.php rename to src/Api/Data/StagingDataInterface.php diff --git a/Api/GrinServiceInterface.php b/src/Api/GrinServiceInterface.php similarity index 100% rename from Api/GrinServiceInterface.php rename to src/Api/GrinServiceInterface.php diff --git a/Api/PublisherInterface.php b/src/Api/PublisherInterface.php similarity index 100% rename from Api/PublisherInterface.php rename to src/Api/PublisherInterface.php diff --git a/Api/RuleStagingRepositoryInterface.php b/src/Api/RuleStagingRepositoryInterface.php similarity index 100% rename from Api/RuleStagingRepositoryInterface.php rename to src/Api/RuleStagingRepositoryInterface.php diff --git a/Api/StockItemsInterface.php b/src/Api/StockItemsInterface.php similarity index 100% rename from Api/StockItemsInterface.php rename to src/Api/StockItemsInterface.php diff --git a/Block/Checkout/CartWidget.php b/src/Block/Checkout/CartWidget.php similarity index 100% rename from Block/Checkout/CartWidget.php rename to src/Block/Checkout/CartWidget.php diff --git a/Block/Checkout/Success.php b/src/Block/Checkout/Success.php similarity index 100% rename from Block/Checkout/Success.php rename to src/Block/Checkout/Success.php diff --git a/Block/Footer/FooterScript.php b/src/Block/Footer/FooterScript.php similarity index 100% rename from Block/Footer/FooterScript.php rename to src/Block/Footer/FooterScript.php diff --git a/Block/System/Version.php b/src/Block/System/Version.php similarity index 100% rename from Block/System/Version.php rename to src/Block/System/Version.php diff --git a/Controller/Adminhtml/Queue/Messages.php b/src/Controller/Adminhtml/Queue/Messages.php similarity index 100% rename from Controller/Adminhtml/Queue/Messages.php rename to src/Controller/Adminhtml/Queue/Messages.php diff --git a/Model/Carrier/Method.php b/src/Model/Carrier/Method.php similarity index 100% rename from Model/Carrier/Method.php rename to src/Model/Carrier/Method.php diff --git a/Model/Data/Request.php b/src/Model/Data/Request.php similarity index 100% rename from Model/Data/Request.php rename to src/Model/Data/Request.php diff --git a/Model/Data/RuleStaging.php b/src/Model/Data/RuleStaging.php similarity index 100% rename from Model/Data/RuleStaging.php rename to src/Model/Data/RuleStaging.php diff --git a/Model/Data/StagingData.php b/src/Model/Data/StagingData.php similarity index 100% rename from Model/Data/StagingData.php rename to src/Model/Data/StagingData.php diff --git a/Model/Grid/Source/MessageStatus.php b/src/Model/Grid/Source/MessageStatus.php similarity index 100% rename from Model/Grid/Source/MessageStatus.php rename to src/Model/Grid/Source/MessageStatus.php diff --git a/Model/GrinService.php b/src/Model/GrinService.php similarity index 100% rename from Model/GrinService.php rename to src/Model/GrinService.php diff --git a/Model/Http/Client/Adapter/CurlFactory.php b/src/Model/Http/Client/Adapter/CurlFactory.php similarity index 100% rename from Model/Http/Client/Adapter/CurlFactory.php rename to src/Model/Http/Client/Adapter/CurlFactory.php diff --git a/Model/Http/UriFactory.php b/src/Model/Http/UriFactory.php similarity index 100% rename from Model/Http/UriFactory.php rename to src/Model/Http/UriFactory.php diff --git a/Model/Message/Invalid.php b/src/Model/Message/Invalid.php similarity index 100% rename from Model/Message/Invalid.php rename to src/Model/Message/Invalid.php diff --git a/Model/OrderTracker.php b/src/Model/OrderTracker.php similarity index 100% rename from Model/OrderTracker.php rename to src/Model/OrderTracker.php diff --git a/Model/Queue/Consumer.php b/src/Model/Queue/Consumer.php similarity index 100% rename from Model/Queue/Consumer.php rename to src/Model/Queue/Consumer.php diff --git a/Model/Queue/ConsumerHandler.php b/src/Model/Queue/ConsumerHandler.php similarity index 100% rename from Model/Queue/ConsumerHandler.php rename to src/Model/Queue/ConsumerHandler.php diff --git a/Model/Queue/InvokerFactory.php b/src/Model/Queue/InvokerFactory.php similarity index 100% rename from Model/Queue/InvokerFactory.php rename to src/Model/Queue/InvokerFactory.php diff --git a/Model/Queue/Publisher.php b/src/Model/Queue/Publisher.php similarity index 100% rename from Model/Queue/Publisher.php rename to src/Model/Queue/Publisher.php diff --git a/Model/Queue/ResourceModel/ResponseHandler.php b/src/Model/Queue/ResourceModel/ResponseHandler.php similarity index 100% rename from Model/Queue/ResourceModel/ResponseHandler.php rename to src/Model/Queue/ResourceModel/ResponseHandler.php diff --git a/Model/Queue/StoreIdsManager.php b/src/Model/Queue/StoreIdsManager.php similarity index 100% rename from Model/Queue/StoreIdsManager.php rename to src/Model/Queue/StoreIdsManager.php diff --git a/Model/RuleStagingRepository.php b/src/Model/RuleStagingRepository.php similarity index 100% rename from Model/RuleStagingRepository.php rename to src/Model/RuleStagingRepository.php diff --git a/Model/SalesRuleValidator.php b/src/Model/SalesRuleValidator.php similarity index 100% rename from Model/SalesRuleValidator.php rename to src/Model/SalesRuleValidator.php diff --git a/Model/StockItems.php b/src/Model/StockItems.php similarity index 100% rename from Model/StockItems.php rename to src/Model/StockItems.php diff --git a/Model/SystemConfig.php b/src/Model/SystemConfig.php similarity index 100% rename from Model/SystemConfig.php rename to src/Model/SystemConfig.php diff --git a/Model/WebhookStateInterface.php b/src/Model/WebhookStateInterface.php similarity index 100% rename from Model/WebhookStateInterface.php rename to src/Model/WebhookStateInterface.php diff --git a/Observer/CategoryWebhook.php b/src/Observer/CategoryWebhook.php similarity index 100% rename from Observer/CategoryWebhook.php rename to src/Observer/CategoryWebhook.php diff --git a/Observer/OrderState.php b/src/Observer/OrderState.php similarity index 100% rename from Observer/OrderState.php rename to src/Observer/OrderState.php diff --git a/Observer/OrderWebhook.php b/src/Observer/OrderWebhook.php similarity index 100% rename from Observer/OrderWebhook.php rename to src/Observer/OrderWebhook.php diff --git a/Observer/ProductWebhook.php b/src/Observer/ProductWebhook.php similarity index 100% rename from Observer/ProductWebhook.php rename to src/Observer/ProductWebhook.php diff --git a/Observer/SalesRule.php b/src/Observer/SalesRule.php similarity index 100% rename from Observer/SalesRule.php rename to src/Observer/SalesRule.php diff --git a/Observer/StockItemWebhook.php b/src/Observer/StockItemWebhook.php similarity index 100% rename from Observer/StockItemWebhook.php rename to src/Observer/StockItemWebhook.php diff --git a/Plugin/AttributeData.php b/src/Plugin/AttributeData.php similarity index 100% rename from Plugin/AttributeData.php rename to src/Plugin/AttributeData.php diff --git a/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php b/src/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php similarity index 100% rename from Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php rename to src/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php diff --git a/Test/Api/StockItemsTest.php b/src/Test/Api/StockItemsTest.php similarity index 100% rename from Test/Api/StockItemsTest.php rename to src/Test/Api/StockItemsTest.php diff --git a/Test/Integration/CategoryPublisherTest.php b/src/Test/Integration/CategoryPublisherTest.php similarity index 100% rename from Test/Integration/CategoryPublisherTest.php rename to src/Test/Integration/CategoryPublisherTest.php diff --git a/Test/Integration/Fixture/Category.php b/src/Test/Integration/Fixture/Category.php similarity index 100% rename from Test/Integration/Fixture/Category.php rename to src/Test/Integration/Fixture/Category.php diff --git a/Test/Integration/Fixture/Order.php b/src/Test/Integration/Fixture/Order.php similarity index 100% rename from Test/Integration/Fixture/Order.php rename to src/Test/Integration/Fixture/Order.php diff --git a/Test/Integration/Fixture/Product.php b/src/Test/Integration/Fixture/Product.php similarity index 100% rename from Test/Integration/Fixture/Product.php rename to src/Test/Integration/Fixture/Product.php diff --git a/Test/Integration/GrinServiceTest.php b/src/Test/Integration/GrinServiceTest.php similarity index 100% rename from Test/Integration/GrinServiceTest.php rename to src/Test/Integration/GrinServiceTest.php diff --git a/Test/Integration/Model/MysqlQueueMessageManager.php b/src/Test/Integration/Model/MysqlQueueMessageManager.php similarity index 100% rename from Test/Integration/Model/MysqlQueueMessageManager.php rename to src/Test/Integration/Model/MysqlQueueMessageManager.php diff --git a/Test/Integration/Model/OrderManager.php b/src/Test/Integration/Model/OrderManager.php similarity index 100% rename from Test/Integration/Model/OrderManager.php rename to src/Test/Integration/Model/OrderManager.php diff --git a/Test/Integration/OrderPublisherTest.php b/src/Test/Integration/OrderPublisherTest.php similarity index 100% rename from Test/Integration/OrderPublisherTest.php rename to src/Test/Integration/OrderPublisherTest.php diff --git a/Test/Integration/ProductPublisherTest.php b/src/Test/Integration/ProductPublisherTest.php similarity index 100% rename from Test/Integration/ProductPublisherTest.php rename to src/Test/Integration/ProductPublisherTest.php diff --git a/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php b/src/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php similarity index 100% rename from Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php rename to src/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php diff --git a/Ui/DataProvider/MessageQueue/ListingDataProvider.php b/src/Ui/DataProvider/MessageQueue/ListingDataProvider.php similarity index 100% rename from Ui/DataProvider/MessageQueue/ListingDataProvider.php rename to src/Ui/DataProvider/MessageQueue/ListingDataProvider.php diff --git a/composer.json b/src/composer.json similarity index 86% rename from composer.json rename to src/composer.json index 3f5badc..65938ea 100755 --- a/composer.json +++ b/src/composer.json @@ -19,6 +19,9 @@ ], "psr-4": { "Grin\\Module\\": "" - } + }, + "exclude-from-classmap": [ + "/Test/" + ] } } diff --git a/composer.lock b/src/composer.lock similarity index 100% rename from composer.lock rename to src/composer.lock diff --git a/etc/acl.xml b/src/etc/acl.xml similarity index 100% rename from etc/acl.xml rename to src/etc/acl.xml diff --git a/etc/adminhtml/di.xml b/src/etc/adminhtml/di.xml similarity index 100% rename from etc/adminhtml/di.xml rename to src/etc/adminhtml/di.xml diff --git a/etc/adminhtml/menu.xml b/src/etc/adminhtml/menu.xml similarity index 100% rename from etc/adminhtml/menu.xml rename to src/etc/adminhtml/menu.xml diff --git a/etc/adminhtml/routes.xml b/src/etc/adminhtml/routes.xml similarity index 100% rename from etc/adminhtml/routes.xml rename to src/etc/adminhtml/routes.xml diff --git a/etc/adminhtml/system.xml b/src/etc/adminhtml/system.xml similarity index 100% rename from etc/adminhtml/system.xml rename to src/etc/adminhtml/system.xml diff --git a/etc/communication.xml b/src/etc/communication.xml similarity index 100% rename from etc/communication.xml rename to src/etc/communication.xml diff --git a/etc/config.xml b/src/etc/config.xml similarity index 100% rename from etc/config.xml rename to src/etc/config.xml diff --git a/etc/db_schema.xml b/src/etc/db_schema.xml similarity index 100% rename from etc/db_schema.xml rename to src/etc/db_schema.xml diff --git a/etc/db_schema_whitelist.json b/src/etc/db_schema_whitelist.json similarity index 100% rename from etc/db_schema_whitelist.json rename to src/etc/db_schema_whitelist.json diff --git a/etc/di.xml b/src/etc/di.xml similarity index 100% rename from etc/di.xml rename to src/etc/di.xml diff --git a/etc/events.xml b/src/etc/events.xml similarity index 100% rename from etc/events.xml rename to src/etc/events.xml diff --git a/etc/extension_attributes.xml b/src/etc/extension_attributes.xml similarity index 100% rename from etc/extension_attributes.xml rename to src/etc/extension_attributes.xml diff --git a/etc/module.xml b/src/etc/module.xml similarity index 100% rename from etc/module.xml rename to src/etc/module.xml diff --git a/etc/queue.xml b/src/etc/queue.xml similarity index 100% rename from etc/queue.xml rename to src/etc/queue.xml diff --git a/etc/queue_consumer.xml b/src/etc/queue_consumer.xml similarity index 100% rename from etc/queue_consumer.xml rename to src/etc/queue_consumer.xml diff --git a/etc/queue_publisher.xml b/src/etc/queue_publisher.xml similarity index 100% rename from etc/queue_publisher.xml rename to src/etc/queue_publisher.xml diff --git a/etc/queue_topology.xml b/src/etc/queue_topology.xml similarity index 100% rename from etc/queue_topology.xml rename to src/etc/queue_topology.xml diff --git a/etc/webapi.xml b/src/etc/webapi.xml similarity index 100% rename from etc/webapi.xml rename to src/etc/webapi.xml diff --git a/etc/webapi_rest/di.xml b/src/etc/webapi_rest/di.xml similarity index 100% rename from etc/webapi_rest/di.xml rename to src/etc/webapi_rest/di.xml diff --git a/i18n/en_US.csv b/src/i18n/en_US.csv similarity index 100% rename from i18n/en_US.csv rename to src/i18n/en_US.csv diff --git a/phpunit.xml b/src/phpunit.xml similarity index 66% rename from phpunit.xml rename to src/phpunit.xml index 0d3589e..6150d23 100644 --- a/phpunit.xml +++ b/src/phpunit.xml @@ -7,17 +7,17 @@ stderr="true"> - ../../../vendor/grin/module/Test/Unit + app/code/Grin/Module/Test/Unit - ../../../vendor/grin/module + app/code/Grin/Module - ../../../lib/internal/*/*/Test - ../../../lib/internal/*/*/*/Test - ../../../setup/src/*/*/Test + lib/internal/*/*/Test + lib/internal/*/*/*/Test + setup/src/*/*/Test diff --git a/registration.php b/src/registration.php similarity index 100% rename from registration.php rename to src/registration.php diff --git a/view/adminhtml/layout/grin_module_queue_messages.xml b/src/view/adminhtml/layout/grin_module_queue_messages.xml similarity index 100% rename from view/adminhtml/layout/grin_module_queue_messages.xml rename to src/view/adminhtml/layout/grin_module_queue_messages.xml diff --git a/view/adminhtml/ui_component/grin_module_queue_messages.xml b/src/view/adminhtml/ui_component/grin_module_queue_messages.xml similarity index 100% rename from view/adminhtml/ui_component/grin_module_queue_messages.xml rename to src/view/adminhtml/ui_component/grin_module_queue_messages.xml diff --git a/view/adminhtml/ui_component/sales_rule_form.xml b/src/view/adminhtml/ui_component/sales_rule_form.xml similarity index 100% rename from view/adminhtml/ui_component/sales_rule_form.xml rename to src/view/adminhtml/ui_component/sales_rule_form.xml diff --git a/view/frontend/layout/checkout_cart_index.xml b/src/view/frontend/layout/checkout_cart_index.xml similarity index 100% rename from view/frontend/layout/checkout_cart_index.xml rename to src/view/frontend/layout/checkout_cart_index.xml diff --git a/view/frontend/layout/checkout_onepage_success.xml b/src/view/frontend/layout/checkout_onepage_success.xml similarity index 100% rename from view/frontend/layout/checkout_onepage_success.xml rename to src/view/frontend/layout/checkout_onepage_success.xml diff --git a/view/frontend/layout/default.xml b/src/view/frontend/layout/default.xml similarity index 100% rename from view/frontend/layout/default.xml rename to src/view/frontend/layout/default.xml diff --git a/view/frontend/templates/affiliate/footer.phtml b/src/view/frontend/templates/affiliate/footer.phtml similarity index 100% rename from view/frontend/templates/affiliate/footer.phtml rename to src/view/frontend/templates/affiliate/footer.phtml diff --git a/view/frontend/templates/affiliate/success.phtml b/src/view/frontend/templates/affiliate/success.phtml similarity index 100% rename from view/frontend/templates/affiliate/success.phtml rename to src/view/frontend/templates/affiliate/success.phtml diff --git a/view/frontend/templates/checkout/cart-id.phtml b/src/view/frontend/templates/checkout/cart-id.phtml similarity index 100% rename from view/frontend/templates/checkout/cart-id.phtml rename to src/view/frontend/templates/checkout/cart-id.phtml diff --git a/view/frontend/web/css/source/_module.less b/src/view/frontend/web/css/source/_module.less similarity index 100% rename from view/frontend/web/css/source/_module.less rename to src/view/frontend/web/css/source/_module.less From c75c7a0e3bc6fcedee328d0a7b2a5ab379cd3873 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 13:17:34 -0600 Subject: [PATCH 05/15] add deploy to staging GH action (#33) --- .github/workflows/deploy-module-staging.yml | 31 +++++++++++++++++++++ README.md | 9 ++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy-module-staging.yml diff --git a/.github/workflows/deploy-module-staging.yml b/.github/workflows/deploy-module-staging.yml new file mode 100644 index 0000000..9e57bfb --- /dev/null +++ b/.github/workflows/deploy-module-staging.yml @@ -0,0 +1,31 @@ +name: Deploy Magento Module to Staging via Composer + +on: + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install sshpass + run: sudo apt-get update && sudo apt-get install -y sshpass + + - name: Deploy and update module on Magento server + env: + SSH_USER: ${{ secrets.MAGENTO_DEPLOY_USER }} + SSH_PASS: ${{ secrets.MAGENTO_DEPLOY_PASSWORD }} + SSH_HOST: ${{ secrets.MAGENTO_DEPLOY_HOST }} + SSH_PATH: ${{ secrets.MAGENTO_APP_PATH }} + run: | + sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST " + cd $SSH_PATH && + composer update grin/module --ignore-platform-reqs && + bin/magento setup:upgrade && + bin/magento setup:di:compile && + bin/magento setup:static-content:deploy && + bin/magento cache:flush + " diff --git a/README.md b/README.md index b76bf1b..978e519 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Influencer marketing for ecommerce. For more information go to https://grin.co/ - [Install](#install) - [Update](#update) +- [Deploy to Staging via GitHub Actions](#deploy-to-staging-via-github-actions) - [Some notes](#some-notes) - [Q\&A](#qa) - [Local Development](#local-development) @@ -19,7 +20,7 @@ Influencer marketing for ecommerce. For more information go to https://grin.co/ - [Troubleshooting](#troubleshooting) - [Running Unit Tests](#running-unit-tests) - [Running Coding Standards](#running-coding-standards) -- [Credits](#credits) + - [Credits](#credits) ## Install @@ -38,6 +39,10 @@ Influencer marketing for ecommerce. For more information go to https://grin.co/ 4. bin/magento setup:static-content:deploy 5. bin/magento cache:flush +## Deploy to Staging via GitHub Actions + +This repository includes a GitHub Actions workflow (.github/workflows/deploy-module-staging.yml) that automates deployment of the latest code from the main branch to staging by connecting via SSH using stored credentials, updating the module via Composer, and running required Magento deployment commands. + ## Some notes - Grin uses composer to provide their extension to the end customer. @@ -249,6 +254,6 @@ The script will: 2. Generate a detailed report 3. Display any warnings or errors found -## Credits +### Credits This local development setup is based on [markshust/docker-magento](https://github.com/markshust/docker-magento). From b57a46ab9a4b9853249090e2f3781ca5f76a2156 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 13:26:23 -0600 Subject: [PATCH 06/15] feat: allow deployment of any branch to staging via workflow_dispatch input --- .github/workflows/deploy-module-staging.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-module-staging.yml b/.github/workflows/deploy-module-staging.yml index 9e57bfb..702a271 100644 --- a/.github/workflows/deploy-module-staging.yml +++ b/.github/workflows/deploy-module-staging.yml @@ -2,6 +2,11 @@ name: Deploy Magento Module to Staging via Composer on: workflow_dispatch: + inputs: + branch: + description: 'Branch to deploy' + required: true + default: 'main' jobs: deploy: @@ -23,7 +28,7 @@ jobs: run: | sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST " cd $SSH_PATH && - composer update grin/module --ignore-platform-reqs && + composer update grin/module:dev-${{ github.event.inputs.branch }} --ignore-platform-reqs && bin/magento setup:upgrade && bin/magento setup:di:compile && bin/magento setup:static-content:deploy && From 8f59dc28de25fa05b4cec71047fd93f0cb9966d9 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 13:29:55 -0600 Subject: [PATCH 07/15] feat: use GitHub Actions branch selector for staging deployments --- .github/workflows/deploy-module-staging.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-module-staging.yml b/.github/workflows/deploy-module-staging.yml index 702a271..7adba4b 100644 --- a/.github/workflows/deploy-module-staging.yml +++ b/.github/workflows/deploy-module-staging.yml @@ -2,11 +2,6 @@ name: Deploy Magento Module to Staging via Composer on: workflow_dispatch: - inputs: - branch: - description: 'Branch to deploy' - required: true - default: 'main' jobs: deploy: @@ -25,10 +20,11 @@ jobs: SSH_PASS: ${{ secrets.MAGENTO_DEPLOY_PASSWORD }} SSH_HOST: ${{ secrets.MAGENTO_DEPLOY_HOST }} SSH_PATH: ${{ secrets.MAGENTO_APP_PATH }} + BRANCH: ${{ github.ref_name }} run: | sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST " cd $SSH_PATH && - composer update grin/module:dev-${{ github.event.inputs.branch }} --ignore-platform-reqs && + composer update grin/module:dev-$BRANCH --ignore-platform-reqs && bin/magento setup:upgrade && bin/magento setup:di:compile && bin/magento setup:static-content:deploy && From 12a22a232d507c27a93b47c8c4559459de2afb39 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 14:11:51 -0600 Subject: [PATCH 08/15] Fix VCS installation --- .gitignore | 3 +++ composer.json | 27 +++++++++++++++++++++++++++ composer.lock | 20 ++++++++++++++++++++ scripts/setup-first-time.sh | 7 +++++++ 4 files changed, 57 insertions(+) create mode 100755 composer.json create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index f4077c8..1a49820 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ env/ template/ .phpunit.result.cache + +src/composer.json +src/composer.lock diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..80d9030 --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "grin/module", + "description": "Grin (https://grin.co/) extension for magento 2", + "require": { + "php": "^7.2|^7.4|^8.0|^8.1" + }, + "type": "magento2-module", + "version": "2.1.9", + "license": "proprietary", + "authors": [ + { + "name": "Grin dev team", + "email": "support@grin.co" + } + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Grin\\Module\\": "src/" + }, + "exclude-from-classmap": [ + "/Test/" + ] + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..4eb007d --- /dev/null +++ b/composer.lock @@ -0,0 +1,20 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "dda710bff08582ceed3e28d2723622fc", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "^7.4|^8.0|^8.1" + }, + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/scripts/setup-first-time.sh b/scripts/setup-first-time.sh index 5f54847..4715908 100755 --- a/scripts/setup-first-time.sh +++ b/scripts/setup-first-time.sh @@ -208,6 +208,13 @@ cat << EOF | sed -i '' '/volumes:/r /dev/stdin' "$MAGENTO_DIR/compose.yaml" - ${ROOT_DIR}/src:/var/www/html/app/code/Grin/Module:delegated EOF +# After mounting the module volume, copy composer.json and composer.lock into the container +cp ${ROOT_DIR}/composer.json ${ROOT_DIR}/src/composer.json +cp ${ROOT_DIR}/composer.lock ${ROOT_DIR}/src/composer.lock + +# Update the autoload psr-4 path in the module's composer.json from 'src/' to '' +sed -i '' 's|"Grin\\\\Module\\\\\": \"src/\"|"Grin\\\\Module\\\\\": \"\"|g' ${ROOT_DIR}/src/composer.json + # Restart containers to apply volume mount bin/restart From 4626e39c2ab53c6751d35271079df3c72cd60237 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 14:34:12 -0600 Subject: [PATCH 09/15] use composer require to install in staging --- .github/workflows/deploy-module-staging.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-module-staging.yml b/.github/workflows/deploy-module-staging.yml index 7adba4b..fa4cef0 100644 --- a/.github/workflows/deploy-module-staging.yml +++ b/.github/workflows/deploy-module-staging.yml @@ -24,7 +24,7 @@ jobs: run: | sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST " cd $SSH_PATH && - composer update grin/module:dev-$BRANCH --ignore-platform-reqs && + composer require grin/module:dev-$BRANCH --ignore-platform-reqs && bin/magento setup:upgrade && bin/magento setup:di:compile && bin/magento setup:static-content:deploy && From 42881f12cfb85492af68054dc782b4cc10d805cf Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 14:49:34 -0600 Subject: [PATCH 10/15] rollback: move Magento module code from src/ to prevent vcs installation issues --- {src/Api => Api}/Data/RequestInterface.php | 0 .../Api => Api}/Data/RuleStagingInterface.php | 0 .../Api => Api}/Data/StagingDataInterface.php | 0 {src/Api => Api}/GrinServiceInterface.php | 0 {src/Api => Api}/PublisherInterface.php | 0 .../RuleStagingRepositoryInterface.php | 0 {src/Api => Api}/StockItemsInterface.php | 0 {src/Block => Block}/Checkout/Success.php | 0 {src/Block => Block}/Footer/FooterScript.php | 0 {src/Block => Block}/System/Version.php | 0 .../Adminhtml/Queue/Messages.php | 0 {src/Model => Model}/Carrier/Method.php | 0 {src/Model => Model}/Data/Request.php | 0 {src/Model => Model}/Data/RuleStaging.php | 0 {src/Model => Model}/Data/StagingData.php | 0 .../Grid/Source/MessageStatus.php | 0 {src/Model => Model}/GrinService.php | 0 .../Http/Client/Adapter/CurlFactory.php | 0 {src/Model => Model}/Http/UriFactory.php | 0 {src/Model => Model}/Message/Invalid.php | 0 {src/Model => Model}/OrderTracker.php | 0 {src/Model => Model}/Queue/Consumer.php | 0 .../Model => Model}/Queue/ConsumerHandler.php | 0 {src/Model => Model}/Queue/InvokerFactory.php | 0 {src/Model => Model}/Queue/Publisher.php | 0 .../Queue/ResourceModel/ResponseHandler.php | 0 .../Model => Model}/Queue/StoreIdsManager.php | 0 .../Model => Model}/RuleStagingRepository.php | 0 {src/Model => Model}/SalesRuleValidator.php | 0 {src/Model => Model}/StockItems.php | 0 {src/Model => Model}/SystemConfig.php | 0 .../Model => Model}/WebhookStateInterface.php | 0 .../Observer => Observer}/CategoryWebhook.php | 0 {src/Observer => Observer}/OrderState.php | 0 {src/Observer => Observer}/OrderWebhook.php | 0 {src/Observer => Observer}/ProductWebhook.php | 0 {src/Observer => Observer}/SalesRule.php | 0 .../StockItemWebhook.php | 0 {src/Plugin => Plugin}/AttributeData.php | 0 .../Model/RulesApplier/ValidateByToken.php | 0 {src/Test => Test}/Api/StockItemsTest.php | 0 .../Integration/CategoryPublisherTest.php | 0 .../Integration/Fixture/Category.php | 0 .../Integration/Fixture/Order.php | 0 .../Integration/Fixture/Product.php | 0 .../Integration/GrinServiceTest.php | 0 .../Model/MysqlQueueMessageManager.php | 0 .../Integration/Model/OrderManager.php | 0 .../Integration/OrderPublisherTest.php | 0 .../Integration/ProductPublisherTest.php | 0 .../RulesApplier/ValidateByTokenTest.php | 0 .../MessageQueue/ListingDataProvider.php | 0 {src/etc => etc}/acl.xml | 0 {src/etc => etc}/adminhtml/di.xml | 0 {src/etc => etc}/adminhtml/menu.xml | 0 {src/etc => etc}/adminhtml/routes.xml | 0 {src/etc => etc}/adminhtml/system.xml | 0 {src/etc => etc}/communication.xml | 0 {src/etc => etc}/config.xml | 0 {src/etc => etc}/db_schema.xml | 0 {src/etc => etc}/db_schema_whitelist.json | 0 {src/etc => etc}/di.xml | 0 {src/etc => etc}/events.xml | 0 {src/etc => etc}/extension_attributes.xml | 0 {src/etc => etc}/module.xml | 0 {src/etc => etc}/queue.xml | 0 {src/etc => etc}/queue_consumer.xml | 0 {src/etc => etc}/queue_publisher.xml | 0 {src/etc => etc}/queue_topology.xml | 0 {src/etc => etc}/webapi.xml | 0 {src/etc => etc}/webapi_rest/di.xml | 0 {src/i18n => i18n}/en_US.csv | 0 src/phpunit.xml => phpunit.xml | 0 src/registration.php => registration.php | 0 scripts/setup-first-time.sh | 9 +-- src/Block/Checkout/CartWidget.php | 60 ------------------- src/composer.json | 27 --------- src/composer.lock | 20 ------- .../layout/grin_module_queue_messages.xml | 0 .../grin_module_queue_messages.xml | 0 .../ui_component/sales_rule_form.xml | 0 .../frontend/layout/checkout_cart_index.xml | 0 .../layout/checkout_onepage_success.xml | 0 .../view => view}/frontend/layout/default.xml | 0 .../frontend/templates/affiliate/footer.phtml | 0 .../templates/affiliate/success.phtml | 0 .../frontend/templates/checkout/cart-id.phtml | 0 .../frontend/web/css/source/_module.less | 0 88 files changed, 1 insertion(+), 115 deletions(-) rename {src/Api => Api}/Data/RequestInterface.php (100%) rename {src/Api => Api}/Data/RuleStagingInterface.php (100%) rename {src/Api => Api}/Data/StagingDataInterface.php (100%) rename {src/Api => Api}/GrinServiceInterface.php (100%) rename {src/Api => Api}/PublisherInterface.php (100%) rename {src/Api => Api}/RuleStagingRepositoryInterface.php (100%) rename {src/Api => Api}/StockItemsInterface.php (100%) rename {src/Block => Block}/Checkout/Success.php (100%) rename {src/Block => Block}/Footer/FooterScript.php (100%) rename {src/Block => Block}/System/Version.php (100%) rename {src/Controller => Controller}/Adminhtml/Queue/Messages.php (100%) rename {src/Model => Model}/Carrier/Method.php (100%) rename {src/Model => Model}/Data/Request.php (100%) rename {src/Model => Model}/Data/RuleStaging.php (100%) rename {src/Model => Model}/Data/StagingData.php (100%) rename {src/Model => Model}/Grid/Source/MessageStatus.php (100%) rename {src/Model => Model}/GrinService.php (100%) rename {src/Model => Model}/Http/Client/Adapter/CurlFactory.php (100%) rename {src/Model => Model}/Http/UriFactory.php (100%) rename {src/Model => Model}/Message/Invalid.php (100%) rename {src/Model => Model}/OrderTracker.php (100%) rename {src/Model => Model}/Queue/Consumer.php (100%) rename {src/Model => Model}/Queue/ConsumerHandler.php (100%) rename {src/Model => Model}/Queue/InvokerFactory.php (100%) rename {src/Model => Model}/Queue/Publisher.php (100%) rename {src/Model => Model}/Queue/ResourceModel/ResponseHandler.php (100%) rename {src/Model => Model}/Queue/StoreIdsManager.php (100%) rename {src/Model => Model}/RuleStagingRepository.php (100%) rename {src/Model => Model}/SalesRuleValidator.php (100%) rename {src/Model => Model}/StockItems.php (100%) rename {src/Model => Model}/SystemConfig.php (100%) rename {src/Model => Model}/WebhookStateInterface.php (100%) rename {src/Observer => Observer}/CategoryWebhook.php (100%) rename {src/Observer => Observer}/OrderState.php (100%) rename {src/Observer => Observer}/OrderWebhook.php (100%) rename {src/Observer => Observer}/ProductWebhook.php (100%) rename {src/Observer => Observer}/SalesRule.php (100%) rename {src/Observer => Observer}/StockItemWebhook.php (100%) rename {src/Plugin => Plugin}/AttributeData.php (100%) rename {src/Plugin => Plugin}/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php (100%) rename {src/Test => Test}/Api/StockItemsTest.php (100%) rename {src/Test => Test}/Integration/CategoryPublisherTest.php (100%) rename {src/Test => Test}/Integration/Fixture/Category.php (100%) rename {src/Test => Test}/Integration/Fixture/Order.php (100%) rename {src/Test => Test}/Integration/Fixture/Product.php (100%) rename {src/Test => Test}/Integration/GrinServiceTest.php (100%) rename {src/Test => Test}/Integration/Model/MysqlQueueMessageManager.php (100%) rename {src/Test => Test}/Integration/Model/OrderManager.php (100%) rename {src/Test => Test}/Integration/OrderPublisherTest.php (100%) rename {src/Test => Test}/Integration/ProductPublisherTest.php (100%) rename {src/Test => Test}/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php (100%) rename {src/Ui => Ui}/DataProvider/MessageQueue/ListingDataProvider.php (100%) rename {src/etc => etc}/acl.xml (100%) rename {src/etc => etc}/adminhtml/di.xml (100%) rename {src/etc => etc}/adminhtml/menu.xml (100%) rename {src/etc => etc}/adminhtml/routes.xml (100%) rename {src/etc => etc}/adminhtml/system.xml (100%) rename {src/etc => etc}/communication.xml (100%) rename {src/etc => etc}/config.xml (100%) rename {src/etc => etc}/db_schema.xml (100%) rename {src/etc => etc}/db_schema_whitelist.json (100%) rename {src/etc => etc}/di.xml (100%) rename {src/etc => etc}/events.xml (100%) rename {src/etc => etc}/extension_attributes.xml (100%) rename {src/etc => etc}/module.xml (100%) rename {src/etc => etc}/queue.xml (100%) rename {src/etc => etc}/queue_consumer.xml (100%) rename {src/etc => etc}/queue_publisher.xml (100%) rename {src/etc => etc}/queue_topology.xml (100%) rename {src/etc => etc}/webapi.xml (100%) rename {src/etc => etc}/webapi_rest/di.xml (100%) rename {src/i18n => i18n}/en_US.csv (100%) rename src/phpunit.xml => phpunit.xml (100%) rename src/registration.php => registration.php (100%) delete mode 100755 src/Block/Checkout/CartWidget.php delete mode 100755 src/composer.json delete mode 100644 src/composer.lock rename {src/view => view}/adminhtml/layout/grin_module_queue_messages.xml (100%) rename {src/view => view}/adminhtml/ui_component/grin_module_queue_messages.xml (100%) rename {src/view => view}/adminhtml/ui_component/sales_rule_form.xml (100%) rename {src/view => view}/frontend/layout/checkout_cart_index.xml (100%) rename {src/view => view}/frontend/layout/checkout_onepage_success.xml (100%) rename {src/view => view}/frontend/layout/default.xml (100%) rename {src/view => view}/frontend/templates/affiliate/footer.phtml (100%) rename {src/view => view}/frontend/templates/affiliate/success.phtml (100%) rename {src/view => view}/frontend/templates/checkout/cart-id.phtml (100%) rename {src/view => view}/frontend/web/css/source/_module.less (100%) diff --git a/src/Api/Data/RequestInterface.php b/Api/Data/RequestInterface.php similarity index 100% rename from src/Api/Data/RequestInterface.php rename to Api/Data/RequestInterface.php diff --git a/src/Api/Data/RuleStagingInterface.php b/Api/Data/RuleStagingInterface.php similarity index 100% rename from src/Api/Data/RuleStagingInterface.php rename to Api/Data/RuleStagingInterface.php diff --git a/src/Api/Data/StagingDataInterface.php b/Api/Data/StagingDataInterface.php similarity index 100% rename from src/Api/Data/StagingDataInterface.php rename to Api/Data/StagingDataInterface.php diff --git a/src/Api/GrinServiceInterface.php b/Api/GrinServiceInterface.php similarity index 100% rename from src/Api/GrinServiceInterface.php rename to Api/GrinServiceInterface.php diff --git a/src/Api/PublisherInterface.php b/Api/PublisherInterface.php similarity index 100% rename from src/Api/PublisherInterface.php rename to Api/PublisherInterface.php diff --git a/src/Api/RuleStagingRepositoryInterface.php b/Api/RuleStagingRepositoryInterface.php similarity index 100% rename from src/Api/RuleStagingRepositoryInterface.php rename to Api/RuleStagingRepositoryInterface.php diff --git a/src/Api/StockItemsInterface.php b/Api/StockItemsInterface.php similarity index 100% rename from src/Api/StockItemsInterface.php rename to Api/StockItemsInterface.php diff --git a/src/Block/Checkout/Success.php b/Block/Checkout/Success.php similarity index 100% rename from src/Block/Checkout/Success.php rename to Block/Checkout/Success.php diff --git a/src/Block/Footer/FooterScript.php b/Block/Footer/FooterScript.php similarity index 100% rename from src/Block/Footer/FooterScript.php rename to Block/Footer/FooterScript.php diff --git a/src/Block/System/Version.php b/Block/System/Version.php similarity index 100% rename from src/Block/System/Version.php rename to Block/System/Version.php diff --git a/src/Controller/Adminhtml/Queue/Messages.php b/Controller/Adminhtml/Queue/Messages.php similarity index 100% rename from src/Controller/Adminhtml/Queue/Messages.php rename to Controller/Adminhtml/Queue/Messages.php diff --git a/src/Model/Carrier/Method.php b/Model/Carrier/Method.php similarity index 100% rename from src/Model/Carrier/Method.php rename to Model/Carrier/Method.php diff --git a/src/Model/Data/Request.php b/Model/Data/Request.php similarity index 100% rename from src/Model/Data/Request.php rename to Model/Data/Request.php diff --git a/src/Model/Data/RuleStaging.php b/Model/Data/RuleStaging.php similarity index 100% rename from src/Model/Data/RuleStaging.php rename to Model/Data/RuleStaging.php diff --git a/src/Model/Data/StagingData.php b/Model/Data/StagingData.php similarity index 100% rename from src/Model/Data/StagingData.php rename to Model/Data/StagingData.php diff --git a/src/Model/Grid/Source/MessageStatus.php b/Model/Grid/Source/MessageStatus.php similarity index 100% rename from src/Model/Grid/Source/MessageStatus.php rename to Model/Grid/Source/MessageStatus.php diff --git a/src/Model/GrinService.php b/Model/GrinService.php similarity index 100% rename from src/Model/GrinService.php rename to Model/GrinService.php diff --git a/src/Model/Http/Client/Adapter/CurlFactory.php b/Model/Http/Client/Adapter/CurlFactory.php similarity index 100% rename from src/Model/Http/Client/Adapter/CurlFactory.php rename to Model/Http/Client/Adapter/CurlFactory.php diff --git a/src/Model/Http/UriFactory.php b/Model/Http/UriFactory.php similarity index 100% rename from src/Model/Http/UriFactory.php rename to Model/Http/UriFactory.php diff --git a/src/Model/Message/Invalid.php b/Model/Message/Invalid.php similarity index 100% rename from src/Model/Message/Invalid.php rename to Model/Message/Invalid.php diff --git a/src/Model/OrderTracker.php b/Model/OrderTracker.php similarity index 100% rename from src/Model/OrderTracker.php rename to Model/OrderTracker.php diff --git a/src/Model/Queue/Consumer.php b/Model/Queue/Consumer.php similarity index 100% rename from src/Model/Queue/Consumer.php rename to Model/Queue/Consumer.php diff --git a/src/Model/Queue/ConsumerHandler.php b/Model/Queue/ConsumerHandler.php similarity index 100% rename from src/Model/Queue/ConsumerHandler.php rename to Model/Queue/ConsumerHandler.php diff --git a/src/Model/Queue/InvokerFactory.php b/Model/Queue/InvokerFactory.php similarity index 100% rename from src/Model/Queue/InvokerFactory.php rename to Model/Queue/InvokerFactory.php diff --git a/src/Model/Queue/Publisher.php b/Model/Queue/Publisher.php similarity index 100% rename from src/Model/Queue/Publisher.php rename to Model/Queue/Publisher.php diff --git a/src/Model/Queue/ResourceModel/ResponseHandler.php b/Model/Queue/ResourceModel/ResponseHandler.php similarity index 100% rename from src/Model/Queue/ResourceModel/ResponseHandler.php rename to Model/Queue/ResourceModel/ResponseHandler.php diff --git a/src/Model/Queue/StoreIdsManager.php b/Model/Queue/StoreIdsManager.php similarity index 100% rename from src/Model/Queue/StoreIdsManager.php rename to Model/Queue/StoreIdsManager.php diff --git a/src/Model/RuleStagingRepository.php b/Model/RuleStagingRepository.php similarity index 100% rename from src/Model/RuleStagingRepository.php rename to Model/RuleStagingRepository.php diff --git a/src/Model/SalesRuleValidator.php b/Model/SalesRuleValidator.php similarity index 100% rename from src/Model/SalesRuleValidator.php rename to Model/SalesRuleValidator.php diff --git a/src/Model/StockItems.php b/Model/StockItems.php similarity index 100% rename from src/Model/StockItems.php rename to Model/StockItems.php diff --git a/src/Model/SystemConfig.php b/Model/SystemConfig.php similarity index 100% rename from src/Model/SystemConfig.php rename to Model/SystemConfig.php diff --git a/src/Model/WebhookStateInterface.php b/Model/WebhookStateInterface.php similarity index 100% rename from src/Model/WebhookStateInterface.php rename to Model/WebhookStateInterface.php diff --git a/src/Observer/CategoryWebhook.php b/Observer/CategoryWebhook.php similarity index 100% rename from src/Observer/CategoryWebhook.php rename to Observer/CategoryWebhook.php diff --git a/src/Observer/OrderState.php b/Observer/OrderState.php similarity index 100% rename from src/Observer/OrderState.php rename to Observer/OrderState.php diff --git a/src/Observer/OrderWebhook.php b/Observer/OrderWebhook.php similarity index 100% rename from src/Observer/OrderWebhook.php rename to Observer/OrderWebhook.php diff --git a/src/Observer/ProductWebhook.php b/Observer/ProductWebhook.php similarity index 100% rename from src/Observer/ProductWebhook.php rename to Observer/ProductWebhook.php diff --git a/src/Observer/SalesRule.php b/Observer/SalesRule.php similarity index 100% rename from src/Observer/SalesRule.php rename to Observer/SalesRule.php diff --git a/src/Observer/StockItemWebhook.php b/Observer/StockItemWebhook.php similarity index 100% rename from src/Observer/StockItemWebhook.php rename to Observer/StockItemWebhook.php diff --git a/src/Plugin/AttributeData.php b/Plugin/AttributeData.php similarity index 100% rename from src/Plugin/AttributeData.php rename to Plugin/AttributeData.php diff --git a/src/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php b/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php similarity index 100% rename from src/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php rename to Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php diff --git a/src/Test/Api/StockItemsTest.php b/Test/Api/StockItemsTest.php similarity index 100% rename from src/Test/Api/StockItemsTest.php rename to Test/Api/StockItemsTest.php diff --git a/src/Test/Integration/CategoryPublisherTest.php b/Test/Integration/CategoryPublisherTest.php similarity index 100% rename from src/Test/Integration/CategoryPublisherTest.php rename to Test/Integration/CategoryPublisherTest.php diff --git a/src/Test/Integration/Fixture/Category.php b/Test/Integration/Fixture/Category.php similarity index 100% rename from src/Test/Integration/Fixture/Category.php rename to Test/Integration/Fixture/Category.php diff --git a/src/Test/Integration/Fixture/Order.php b/Test/Integration/Fixture/Order.php similarity index 100% rename from src/Test/Integration/Fixture/Order.php rename to Test/Integration/Fixture/Order.php diff --git a/src/Test/Integration/Fixture/Product.php b/Test/Integration/Fixture/Product.php similarity index 100% rename from src/Test/Integration/Fixture/Product.php rename to Test/Integration/Fixture/Product.php diff --git a/src/Test/Integration/GrinServiceTest.php b/Test/Integration/GrinServiceTest.php similarity index 100% rename from src/Test/Integration/GrinServiceTest.php rename to Test/Integration/GrinServiceTest.php diff --git a/src/Test/Integration/Model/MysqlQueueMessageManager.php b/Test/Integration/Model/MysqlQueueMessageManager.php similarity index 100% rename from src/Test/Integration/Model/MysqlQueueMessageManager.php rename to Test/Integration/Model/MysqlQueueMessageManager.php diff --git a/src/Test/Integration/Model/OrderManager.php b/Test/Integration/Model/OrderManager.php similarity index 100% rename from src/Test/Integration/Model/OrderManager.php rename to Test/Integration/Model/OrderManager.php diff --git a/src/Test/Integration/OrderPublisherTest.php b/Test/Integration/OrderPublisherTest.php similarity index 100% rename from src/Test/Integration/OrderPublisherTest.php rename to Test/Integration/OrderPublisherTest.php diff --git a/src/Test/Integration/ProductPublisherTest.php b/Test/Integration/ProductPublisherTest.php similarity index 100% rename from src/Test/Integration/ProductPublisherTest.php rename to Test/Integration/ProductPublisherTest.php diff --git a/src/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php b/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php similarity index 100% rename from src/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php rename to Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php diff --git a/src/Ui/DataProvider/MessageQueue/ListingDataProvider.php b/Ui/DataProvider/MessageQueue/ListingDataProvider.php similarity index 100% rename from src/Ui/DataProvider/MessageQueue/ListingDataProvider.php rename to Ui/DataProvider/MessageQueue/ListingDataProvider.php diff --git a/src/etc/acl.xml b/etc/acl.xml similarity index 100% rename from src/etc/acl.xml rename to etc/acl.xml diff --git a/src/etc/adminhtml/di.xml b/etc/adminhtml/di.xml similarity index 100% rename from src/etc/adminhtml/di.xml rename to etc/adminhtml/di.xml diff --git a/src/etc/adminhtml/menu.xml b/etc/adminhtml/menu.xml similarity index 100% rename from src/etc/adminhtml/menu.xml rename to etc/adminhtml/menu.xml diff --git a/src/etc/adminhtml/routes.xml b/etc/adminhtml/routes.xml similarity index 100% rename from src/etc/adminhtml/routes.xml rename to etc/adminhtml/routes.xml diff --git a/src/etc/adminhtml/system.xml b/etc/adminhtml/system.xml similarity index 100% rename from src/etc/adminhtml/system.xml rename to etc/adminhtml/system.xml diff --git a/src/etc/communication.xml b/etc/communication.xml similarity index 100% rename from src/etc/communication.xml rename to etc/communication.xml diff --git a/src/etc/config.xml b/etc/config.xml similarity index 100% rename from src/etc/config.xml rename to etc/config.xml diff --git a/src/etc/db_schema.xml b/etc/db_schema.xml similarity index 100% rename from src/etc/db_schema.xml rename to etc/db_schema.xml diff --git a/src/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json similarity index 100% rename from src/etc/db_schema_whitelist.json rename to etc/db_schema_whitelist.json diff --git a/src/etc/di.xml b/etc/di.xml similarity index 100% rename from src/etc/di.xml rename to etc/di.xml diff --git a/src/etc/events.xml b/etc/events.xml similarity index 100% rename from src/etc/events.xml rename to etc/events.xml diff --git a/src/etc/extension_attributes.xml b/etc/extension_attributes.xml similarity index 100% rename from src/etc/extension_attributes.xml rename to etc/extension_attributes.xml diff --git a/src/etc/module.xml b/etc/module.xml similarity index 100% rename from src/etc/module.xml rename to etc/module.xml diff --git a/src/etc/queue.xml b/etc/queue.xml similarity index 100% rename from src/etc/queue.xml rename to etc/queue.xml diff --git a/src/etc/queue_consumer.xml b/etc/queue_consumer.xml similarity index 100% rename from src/etc/queue_consumer.xml rename to etc/queue_consumer.xml diff --git a/src/etc/queue_publisher.xml b/etc/queue_publisher.xml similarity index 100% rename from src/etc/queue_publisher.xml rename to etc/queue_publisher.xml diff --git a/src/etc/queue_topology.xml b/etc/queue_topology.xml similarity index 100% rename from src/etc/queue_topology.xml rename to etc/queue_topology.xml diff --git a/src/etc/webapi.xml b/etc/webapi.xml similarity index 100% rename from src/etc/webapi.xml rename to etc/webapi.xml diff --git a/src/etc/webapi_rest/di.xml b/etc/webapi_rest/di.xml similarity index 100% rename from src/etc/webapi_rest/di.xml rename to etc/webapi_rest/di.xml diff --git a/src/i18n/en_US.csv b/i18n/en_US.csv similarity index 100% rename from src/i18n/en_US.csv rename to i18n/en_US.csv diff --git a/src/phpunit.xml b/phpunit.xml similarity index 100% rename from src/phpunit.xml rename to phpunit.xml diff --git a/src/registration.php b/registration.php similarity index 100% rename from src/registration.php rename to registration.php diff --git a/scripts/setup-first-time.sh b/scripts/setup-first-time.sh index 4715908..bcf49f1 100755 --- a/scripts/setup-first-time.sh +++ b/scripts/setup-first-time.sh @@ -205,16 +205,9 @@ bin/clinotty bin/magento cache:flush || handle_error "Flushing cache" # Add module volume mount to Docker Compose echo "Adding module volume mount to Docker Compose..." cat << EOF | sed -i '' '/volumes:/r /dev/stdin' "$MAGENTO_DIR/compose.yaml" - - ${ROOT_DIR}/src:/var/www/html/app/code/Grin/Module:delegated + - ${ROOT_DIR}:/var/www/html/app/code/Grin/Module:delegated EOF -# After mounting the module volume, copy composer.json and composer.lock into the container -cp ${ROOT_DIR}/composer.json ${ROOT_DIR}/src/composer.json -cp ${ROOT_DIR}/composer.lock ${ROOT_DIR}/src/composer.lock - -# Update the autoload psr-4 path in the module's composer.json from 'src/' to '' -sed -i '' 's|"Grin\\\\Module\\\\\": \"src/\"|"Grin\\\\Module\\\\\": \"\"|g' ${ROOT_DIR}/src/composer.json - # Restart containers to apply volume mount bin/restart diff --git a/src/Block/Checkout/CartWidget.php b/src/Block/Checkout/CartWidget.php deleted file mode 100755 index 816e76d..0000000 --- a/src/Block/Checkout/CartWidget.php +++ /dev/null @@ -1,60 +0,0 @@ -configProvider = $configProvider; - $this->systemConfig = $systemConfig; - } - - /** - * @return string - */ - public function toHtml(): string - { - if (!$this->systemConfig->isGrinCartWidgetActive()) { - return ''; - } - - return parent::toHtml(); - } - - /** - * @return string - */ - public function getQuoteId(): string - { - return (string) ($this->configProvider->getConfig()['quoteData']['entity_id'] ?? ''); - } -} diff --git a/src/composer.json b/src/composer.json deleted file mode 100755 index 65938ea..0000000 --- a/src/composer.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "grin/module", - "description": "Grin (https://grin.co/) extension for magento 2", - "require": { - "php": "^7.2|^7.4|^8.0|^8.1" - }, - "type": "magento2-module", - "version": "2.1.9", - "license": "proprietary", - "authors": [ - { - "name": "Grin dev team", - "email": "support@grin.co" - } - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Grin\\Module\\": "" - }, - "exclude-from-classmap": [ - "/Test/" - ] - } -} diff --git a/src/composer.lock b/src/composer.lock deleted file mode 100644 index 4eb007d..0000000 --- a/src/composer.lock +++ /dev/null @@ -1,20 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "dda710bff08582ceed3e28d2723622fc", - "packages": [], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": "^7.4|^8.0|^8.1" - }, - "platform-dev": [], - "plugin-api-version": "2.3.0" -} diff --git a/src/view/adminhtml/layout/grin_module_queue_messages.xml b/view/adminhtml/layout/grin_module_queue_messages.xml similarity index 100% rename from src/view/adminhtml/layout/grin_module_queue_messages.xml rename to view/adminhtml/layout/grin_module_queue_messages.xml diff --git a/src/view/adminhtml/ui_component/grin_module_queue_messages.xml b/view/adminhtml/ui_component/grin_module_queue_messages.xml similarity index 100% rename from src/view/adminhtml/ui_component/grin_module_queue_messages.xml rename to view/adminhtml/ui_component/grin_module_queue_messages.xml diff --git a/src/view/adminhtml/ui_component/sales_rule_form.xml b/view/adminhtml/ui_component/sales_rule_form.xml similarity index 100% rename from src/view/adminhtml/ui_component/sales_rule_form.xml rename to view/adminhtml/ui_component/sales_rule_form.xml diff --git a/src/view/frontend/layout/checkout_cart_index.xml b/view/frontend/layout/checkout_cart_index.xml similarity index 100% rename from src/view/frontend/layout/checkout_cart_index.xml rename to view/frontend/layout/checkout_cart_index.xml diff --git a/src/view/frontend/layout/checkout_onepage_success.xml b/view/frontend/layout/checkout_onepage_success.xml similarity index 100% rename from src/view/frontend/layout/checkout_onepage_success.xml rename to view/frontend/layout/checkout_onepage_success.xml diff --git a/src/view/frontend/layout/default.xml b/view/frontend/layout/default.xml similarity index 100% rename from src/view/frontend/layout/default.xml rename to view/frontend/layout/default.xml diff --git a/src/view/frontend/templates/affiliate/footer.phtml b/view/frontend/templates/affiliate/footer.phtml similarity index 100% rename from src/view/frontend/templates/affiliate/footer.phtml rename to view/frontend/templates/affiliate/footer.phtml diff --git a/src/view/frontend/templates/affiliate/success.phtml b/view/frontend/templates/affiliate/success.phtml similarity index 100% rename from src/view/frontend/templates/affiliate/success.phtml rename to view/frontend/templates/affiliate/success.phtml diff --git a/src/view/frontend/templates/checkout/cart-id.phtml b/view/frontend/templates/checkout/cart-id.phtml similarity index 100% rename from src/view/frontend/templates/checkout/cart-id.phtml rename to view/frontend/templates/checkout/cart-id.phtml diff --git a/src/view/frontend/web/css/source/_module.less b/view/frontend/web/css/source/_module.less similarity index 100% rename from src/view/frontend/web/css/source/_module.less rename to view/frontend/web/css/source/_module.less From d370d350e68fbc113db9fa3fd129ab147172d328 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 14:54:05 -0600 Subject: [PATCH 11/15] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 80d9030..65938ea 100755 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "registration.php" ], "psr-4": { - "Grin\\Module\\": "src/" + "Grin\\Module\\": "" }, "exclude-from-classmap": [ "/Test/" From 95ab0c2e7a1cb662d33277b174f9a67c455678ee Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 15:04:02 -0600 Subject: [PATCH 12/15] Update unit-tests.yml --- .github/workflows/unit-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 10b5613..94c5ce3 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -12,6 +12,5 @@ jobs: composer_name: grin/module magento_version: 2.4.8 module_name: Grin_Module - module_source: src php_version: 8.3 project_name: magento/project-community-edition From b766c7d5ea85f5435fb02a54e0c2446957cd8174 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 15:40:28 -0600 Subject: [PATCH 13/15] add docs for local clean up --- README.md | 19 +++++++++++++++++++ scripts/install-sample-data.sh | 2 +- scripts/run-coding-standard.sh | 5 +---- scripts/run-tests.sh | 7 ++----- scripts/setup-first-time.sh | 2 +- scripts/start-env.sh | 11 ++++------- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 978e519..daf9ed4 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Influencer marketing for ecommerce. For more information go to https://grin.co/ - [Troubleshooting](#troubleshooting) - [Running Unit Tests](#running-unit-tests) - [Running Coding Standards](#running-coding-standards) + - [Cleanup](#cleanup) - [Credits](#credits) ## Install @@ -254,6 +255,24 @@ The script will: 2. Generate a detailed report 3. Display any warnings or errors found +### Cleanup + +If you want to completely remove your local Magento development environment, follow these steps: + +1. **Stop and remove Docker containers and volumes:** + ```bash + docker compose -f $HOME/.docker-magento/compose.yaml down -v + ``` + This will stop and remove all containers and associated Docker volumes for your Magento environment. + +2. **Remove the Docker Magento workspace directory:** + ```bash + rm -rf $HOME/.docker-magento + ``` + This will delete all files related to the local Docker Magento environment, including configuration, data, and any persistent files. + +> **Note:** This process will remove your local Magento instance, database, and all related data. Only do this if you are sure you want a full reset. + ### Credits This local development setup is based on [markshust/docker-magento](https://github.com/markshust/docker-magento). diff --git a/scripts/install-sample-data.sh b/scripts/install-sample-data.sh index a6d3212..e996c5d 100755 --- a/scripts/install-sample-data.sh +++ b/scripts/install-sample-data.sh @@ -4,7 +4,7 @@ set -e # Change to the Magento root directory -cd .docker-magento +cd "$HOME/.docker-magento" echo "Setting developer mode..." bin/magento deploy:mode:set developer diff --git a/scripts/run-coding-standard.sh b/scripts/run-coding-standard.sh index a5dd165..679b7ff 100755 --- a/scripts/run-coding-standard.sh +++ b/scripts/run-coding-standard.sh @@ -1,10 +1,7 @@ #!/bin/bash -# Get the root directory (parent of scripts directory) -ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" - # Change to .docker-magento directory -cd "$ROOT_DIR/.docker-magento" +cd "$HOME/.docker-magento" # Get the file path if provided FILE_PATH="$1" diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index f9d9ab4..486a9e2 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -1,10 +1,7 @@ #!/bin/bash -# Get the root directory (parent of scripts directory) -ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" - # Change to .docker-magento directory -cd "$ROOT_DIR/.docker-magento" +cd "$HOME/.docker-magento" if [ -z "$1" ]; then # No parameter: run all tests in the Test directory @@ -18,4 +15,4 @@ else ./bin/clinotty vendor/bin/phpunit --configuration /var/www/html/app/code/Grin/Module/phpunit.xml --list-tests "/var/www/html/app/code/Grin/Module/$1" echo -e "\nRunning tests:" ./bin/clinotty vendor/bin/phpunit --configuration /var/www/html/app/code/Grin/Module/phpunit.xml "/var/www/html/app/code/Grin/Module/$1" -fi \ No newline at end of file +fi diff --git a/scripts/setup-first-time.sh b/scripts/setup-first-time.sh index bcf49f1..aec6108 100755 --- a/scripts/setup-first-time.sh +++ b/scripts/setup-first-time.sh @@ -42,7 +42,7 @@ if [ -z "$MAGENTO_MARKETPLACE_PUBLIC_KEY" ] || [ -z "$MAGENTO_MARKETPLACE_PRIVAT fi # Create a directory for the Magento installation -MAGENTO_DIR="$ROOT_DIR/.docker-magento" +MAGENTO_DIR="$HOME/.docker-magento" if [ -d "$MAGENTO_DIR" ]; then echo "Error: Directory $MAGENTO_DIR already exists" echo "Please remove it before running this script." diff --git a/scripts/start-env.sh b/scripts/start-env.sh index aa210cb..c6390a4 100755 --- a/scripts/start-env.sh +++ b/scripts/start-env.sh @@ -7,26 +7,23 @@ if ! docker info > /dev/null 2>&1; then fi # Check if .docker-magento directory exists -if [ ! -d ".docker-magento" ]; then +if [ ! -d "$HOME/.docker-magento" ]; then echo "Error: .docker-magento directory not found" echo "Please run setup-first-time.sh first" exit 1 fi # Check if we're in the right directory -if [ ! -f ".docker-magento/compose.yaml" ]; then +if [ ! -f "$HOME/.docker-magento/compose.yaml" ]; then echo "Error: Please run this script from the root directory of the module" exit 1 fi # Stop any existing containers -cd .docker-magento -echo "Stopping any existing containers..." -docker-compose down -v +cd "$HOME/.docker-magento" # Start the Docker containers -echo "Starting containers..." -docker-compose up -d +bin/restart # Wait for services to be ready echo "Waiting for services to be ready..." From d54cd139503fefba38ad5d8ab178529a7dc3615c Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Thu, 5 Jun 2025 16:21:39 -0600 Subject: [PATCH 14/15] fix: handle coupon code type compatibility between Magento 2.4.4 and 2.4.8 --- Model/SalesRuleValidator.php | 7 +- .../Model/RulesApplier/ValidateByToken.php | 9 +- Test/Unit/Model/SalesRuleValidatorTest.php | 185 ++++++++++++++++++ .../RulesApplier/ValidateByTokenTest.php | 4 +- 4 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 Test/Unit/Model/SalesRuleValidatorTest.php diff --git a/Model/SalesRuleValidator.php b/Model/SalesRuleValidator.php index d40d25b..0128a05 100644 --- a/Model/SalesRuleValidator.php +++ b/Model/SalesRuleValidator.php @@ -33,14 +33,15 @@ public function __construct(Request $request, SystemConfig $systemConfig) /** * @param Rule $rule - * @param array $couponCode + * @param string|array $couponCode * @return bool */ - public function isValid(Rule $rule, array $couponCode): bool + public function isValid(Rule $rule, $couponCode): bool { $code = $rule->getPrimaryCoupon()->getCode(); + $couponCodes = is_array($couponCode) ? $couponCode : [$couponCode]; - if ($code !== null && $rule->getData('is_grin_only') && in_array($code, $couponCode)) { + if ($code !== null && $rule->getData('is_grin_only') && in_array($code, $couponCodes)) { return $this->request->getHeader(self::TOKEN_HEADER) === $this->systemConfig->getSalesRuleToken(); } diff --git a/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php b/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php index a2fc9c8..381f589 100644 --- a/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php +++ b/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByToken.php @@ -40,15 +40,12 @@ public function aroundApplyRules( $skipValidation, $couponCode ): array { - // Convert string coupon code to array for consistent handling - $couponCodes = is_array($couponCode) ? $couponCode : [$couponCode]; - foreach ($rules as $rule) { - if (!$this->salesRuleValidator->isValid($rule, $couponCodes)) { - return $proceed($item, [], $skipValidation, $couponCodes); + if (!$this->salesRuleValidator->isValid($rule, $couponCode)) { + return $proceed($item, [], $skipValidation, $couponCode); } } - return $proceed($item, $rules, $skipValidation, $couponCodes); + return $proceed($item, $rules, $skipValidation, $couponCode); } } diff --git a/Test/Unit/Model/SalesRuleValidatorTest.php b/Test/Unit/Model/SalesRuleValidatorTest.php new file mode 100644 index 0000000..b813215 --- /dev/null +++ b/Test/Unit/Model/SalesRuleValidatorTest.php @@ -0,0 +1,185 @@ +request = $this->createMock(Request::class); + $this->systemConfig = $this->createMock(SystemConfig::class); + $this->salesRuleValidator = new SalesRuleValidator($this->request, $this->systemConfig); + } + + /** + * @dataProvider couponCodeProvider + */ + public function testIsValidWithNonGrinRule(mixed $couponCode): void + { + /** @var Rule&MockObject $rule */ + $rule = $this->createMock(Rule::class); + /** @var Coupon&MockObject $coupon */ + $coupon = $this->createMock(Coupon::class); + + $rule->expects($this->once()) + ->method('getPrimaryCoupon') + ->willReturn($coupon); + + $coupon->expects($this->once()) + ->method('getCode') + ->willReturn('TEST123'); + + $rule->expects($this->once()) + ->method('getData') + ->with('is_grin_only') + ->willReturn(0); + + $this->assertTrue($this->salesRuleValidator->isValid($rule, $couponCode)); + } + + /** + * @dataProvider couponCodeProvider + */ + public function testIsValidWithGrinRuleAndValidToken(mixed $couponCode): void + { + /** @var Rule&MockObject $rule */ + $rule = $this->createMock(Rule::class); + /** @var Coupon&MockObject $coupon */ + $coupon = $this->createMock(Coupon::class); + + $rule->expects($this->once()) + ->method('getPrimaryCoupon') + ->willReturn($coupon); + + $coupon->expects($this->once()) + ->method('getCode') + ->willReturn('TEST123'); + + $rule->expects($this->once()) + ->method('getData') + ->with('is_grin_only') + ->willReturn(1); + + $this->request->expects($this->once()) + ->method('getHeader') + ->with('Validation-Grin-Token') + ->willReturn('valid-token'); + + $this->systemConfig->expects($this->once()) + ->method('getSalesRuleToken') + ->willReturn('valid-token'); + + $this->assertTrue($this->salesRuleValidator->isValid($rule, $couponCode)); + } + + /** + * @dataProvider couponCodeProvider + */ + public function testIsValidWithGrinRuleAndInvalidToken(mixed $couponCode): void + { + /** @var Rule&MockObject $rule */ + $rule = $this->createMock(Rule::class); + /** @var Coupon&MockObject $coupon */ + $coupon = $this->createMock(Coupon::class); + + $rule->expects($this->once()) + ->method('getPrimaryCoupon') + ->willReturn($coupon); + + $coupon->expects($this->once()) + ->method('getCode') + ->willReturn('TEST123'); + + $rule->expects($this->once()) + ->method('getData') + ->with('is_grin_only') + ->willReturn(1); + + $this->request->expects($this->once()) + ->method('getHeader') + ->with('Validation-Grin-Token') + ->willReturn('invalid-token'); + + $this->systemConfig->expects($this->once()) + ->method('getSalesRuleToken') + ->willReturn('valid-token'); + + $this->assertFalse($this->salesRuleValidator->isValid($rule, $couponCode)); + } + + /** + * @dataProvider emptyCouponCodeProvider + */ + public function testIsValidWithEmptyCouponCode(mixed $couponCode): void + { + /** @var Rule&MockObject $rule */ + $rule = $this->createMock(Rule::class); + /** @var Coupon&MockObject $coupon */ + $coupon = $this->createMock(Coupon::class); + + $rule->expects($this->once()) + ->method('getPrimaryCoupon') + ->willReturn($coupon); + + $coupon->expects($this->once()) + ->method('getCode') + ->willReturn('TEST123'); + + $rule->expects($this->once()) + ->method('getData') + ->with('is_grin_only') + ->willReturn(1); + + $this->assertTrue($this->salesRuleValidator->isValid($rule, $couponCode)); + } + + /** + * @return array> + */ + public static function couponCodeProvider(): array + { + return [ + 'string coupon code' => ['TEST123'], + 'array coupon code' => [['TEST123', 'TEST456']], + ]; + } + + /** + * @return array> + */ + public static function emptyCouponCodeProvider(): array + { + return [ + 'empty array' => [[]], + 'null' => [null], + ]; + } +} \ No newline at end of file diff --git a/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php b/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php index fb147b6..fafab0c 100644 --- a/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php +++ b/Test/Unit/Plugin/Magento/SalesRule/Model/RulesApplier/ValidateByTokenTest.php @@ -51,7 +51,7 @@ public function testAroundApplyRules(mixed $couponCode): void $this->salesRuleValidator->expects($this->once()) ->method('isValid') - ->with($rule, is_array($couponCode) ? $couponCode : [$couponCode]) + ->with($rule, $couponCode) ->willReturn(true); $result = $this->validateByToken->aroundApplyRules( @@ -98,7 +98,7 @@ public function testAroundApplyRulesWithInvalidRule(mixed $couponCode): void $this->salesRuleValidator->expects($this->once()) ->method('isValid') - ->with($rule, is_array($couponCode) ? $couponCode : [$couponCode]) + ->with($rule, $couponCode) ->willReturn(false); $result = $this->validateByToken->aroundApplyRules( From 3e7dff38e101ce799da086573d68adf49ac9b023 Mon Sep 17 00:00:00 2001 From: "raul.madrigal" Date: Fri, 13 Jun 2025 09:10:58 -0600 Subject: [PATCH 15/15] bump version 2.1.10 for release --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 65938ea..9e58059 100755 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "php": "^7.2|^7.4|^8.0|^8.1" }, "type": "magento2-module", - "version": "2.1.9", + "version": "2.1.10", "license": "proprietary", "authors": [ {