LokiCheckout_AbTesting

PHP 8.1 - 8.4
Magento 2.4.7 | 2.4.8
CSP Yes
PHPStan 5
Magento PHPCS 6
Latest Release 1.0.1

A/B testing module for Loki Checkout skins, allowing merchants to test multiple checkout skins automatically.

Features

  • Multi-skin selection: Select 2 or more Loki Checkout skins for A/B testing
  • Two algorithms:
    • Sequential: Cycles through skins consistently per checkout session
    • Random: Randomly selects a skin for each checkout session
  • Automatic activation: Enables when 2+ skins are configured
  • Store-view specific: Different A/B tests per store view
  • Graceful fallbacks: Returns to standard skin selection if configuration is invalid

JavaScript adaption

Note that this module allows for changing the skin dynamically in the frontend. It does not provide tracking of the actual skin used, for further analysis. For this, a JavaScript mechanism like Google Analytics can be applied, which should be configured to track the skin used. The current skin can be accessed via Alpine.js:

Alpine.store('LokiCheckout').currentSkin

Configuration

Navigate to: Stores → Configuration → Loki → Loki Checkout → A/B Testing

Configuration Options

  1. Loki Checkout Skins (multiselect)

    • Select at least 2 skins to activate A/B testing
    • Available skins are pulled from loki_checkout.xml configurations
    • Config path: loki_checkout/ab_testing/skins
  2. Skin Selection Algorithm (dropdown)

    • Sequential: Cycles through skins per checkout session (quote-based)
    • Random: Randomly selects skin each time
    • Config path: loki_checkout/ab_testing/algorithm
    • Default: Sequential

How It Works

Plugin Architecture

The module uses a DI plugin on LokiCheckout\Core\Config\Config::getSkin():

  • Target: LokiCheckout\Core\Config\Config::getSkin()
  • Type: Around plugin
  • Sort order: 10

Skin Selection Logic

  1. Check if enabled: Requires 2+ skins configured
  2. Get skins & algorithm from configuration
  3. Apply algorithm:
    • Sequential: Uses checkout session to maintain consistency
      • First access: calculates index using quoteId % skinCount
      • Stores in session as loki_ab_testing_skin_index
      • Subsequent calls in same session return same skin
    • Random: Uses array_rand() to select random skin
  4. Validate skin: Checks skin exists in XmlConfig::getSkins()
  5. Fallback: Returns original Config::getSkin() result if any issues

Session Storage

  • Key: loki_ab_testing_skin_index
  • Scope: Checkout session (Magento\Checkout\Model\Session)
  • Type: Integer (array index)
  • Purpose: Maintains skin consistency within checkout session

File Structure

app/code/LokiCheckout/AbTesting/
├── registration.php                       # Module registration
├── etc/
│   ├── module.xml                        # Module declaration (depends on LokiCheckout_Core)
│   ├── di.xml                            # Plugin configuration
│   └── adminhtml/
│       └── system.xml                    # Admin configuration UI
├── Config/
│   ├── Config.php                        # Config helper class
│   └── Source/
│       └── AlgorithmOptions.php          # Algorithm dropdown options
└── Plugin/
    └── ConfigSkinPlugin.php             # Around plugin for Config::getSkin()

Installation

The module was installed on 2026-05-18:

cd /data/html/m2-loki-hyva
docker-compose exec -T php-fpm bin/magento module:enable LokiCheckout_AbTesting
docker-compose exec -T php-fpm bin/magento setup:upgrade
docker-compose exec -T php-fpm bin/magento cache:flush

Dependencies

  • LokiCheckout_Core: Required (provides Config class, SkinOptions, XmlConfig)
  • Magento_Checkout: Required (provides CheckoutSession)
  • Magento_Store: Required (provides ScopeConfigInterface)

Usage Example

Admin Configuration

  1. Navigate to: Stores → Configuration → Loki → Loki Checkout → A/B Testing
  2. In "Loki Checkout Skins", select 2+ skins (e.g., "default" and "onestep")
  3. In "Skin Selection Algorithm", choose "Sequential" or "Random"
  4. Save configuration
  5. Clear cache

Expected Behavior

With Sequential Algorithm:

  • Customer 1 (quote ID 1): Gets skin at index 1 % 2 = 1 (e.g., "onestep")
  • Customer 1 (continues session): Still gets "onestep"
  • Customer 2 (quote ID 2): Gets skin at index 2 % 2 = 0 (e.g., "default")
  • Customer 3 (quote ID 3): Gets skin at index 3 % 2 = 1 (e.g., "onestep")

With Random Algorithm:

  • Each checkout session gets a random skin from the configured list
  • Skin changes randomly between sessions

Disabling A/B Testing

To disable A/B testing:

  • Select fewer than 2 skins in the configuration, OR
  • Clear the "Loki Checkout Skins" field entirely

The module will automatically fall back to the standard skin selection from loki_checkout/general/theme.

Technical Details

Configuration Paths

| Setting | Path | Type | Scope | |-----------|--------------------------------------|------|-------| | Skins | loki_checkout/ab_testing/skins | multiselect (comma-separated) | Store view | | Algorithm | loki_checkout/ab_testing/algorithm | select | Store view |

Constants

AlgorithmOptions.php:

  • ALGORITHM_SEQUENTIAL = 'sequential'
  • ALGORITHM_RANDOM = 'random'

ConfigSkinPlugin.php:

  • SESSION_KEY_SKIN_INDEX = 'loki_ab_testing_skin_index'

Error Handling

The plugin includes multiple fallback layers:

  1. Not enabled (< 2 skins): Returns $proceed() (original skin)
  2. Invalid skin selected: Returns $proceed() (original skin)
  3. Session exception: Falls back to first skin in list
  4. Any other error: Returns $proceed() (original skin)

Testing Scenarios

Test Case 1: Disabled (< 2 skins)

  • Config: 0 or 1 skin selected
  • Expected: Original skin from loki_checkout/general/theme

Test Case 2: Sequential Algorithm

  • Config: 2+ skins, algorithm = "sequential"
  • Expected: Skin consistent within same checkout session

Test Case 3: Random Algorithm

  • Config: 2+ skins, algorithm = "random"
  • Expected: Different skins across different sessions

Test Case 4: Invalid Skin

  • Config: 2 skins, one doesn't exist in loki_checkout.xml
  • Expected: Falls back to original skin (no errors)

Future Enhancements

Possible v2 features (not implemented):

  • Analytics tracking (which skin per order)
  • Weighted distribution (e.g., 70% skin A, 30% skin B)
  • Time-based rotation
  • User segment-based testing (logged-in vs guest)
  • A/B test management dashboard
  • Statistical significance calculation

Support

For getting support, create an Issue under the following project URL:

https://gitlab.yireo.com/loki-checkout/LokiCheckout_AbTesting.git

Configuration Options

The following options of this module can be configured via the Store Configuration:

A/B Testing > Enable A/B Testing
loki_checkout/ab_testing/enabled
A/B Testing > Loki Checkout Skins
loki_checkout/ab_testing/skins
Select at least 2 skins to activate A/B testing. Each checkout session will see a skin based on your selected algorithm.
A/B Testing > Skin Selection Algorithm
loki_checkout/ab_testing/algorithm
Sequential: Cycles through skins in order per checkout session. Random: Randomly selects a skin each time.
Module Dependencies

The following dependencies are declared in the module its `etc/module.xml` file:

LokiCheckout_Core Loki_Base Loki_Components Loki_CssUtils Loki_FieldComponents Loki_MapComponents Magento_Backend Magento_Catalog Magento_CatalogInventory Magento_Checkout Magento_CheckoutAgreements Magento_Config Magento_Customer Magento_Directory Magento_Eav Magento_Newsletter Magento_Payment Magento_Quote Magento_Sales Magento_SalesRule Magento_Shipping Magento_Store Magento_Tax Magento_Theme Magento_Vault Yireo_CspUtilities
Composer details
Magento module name
LokiCheckout_AbTesting
Composer name
loki-checkout/magento2-ab-testing
Composer version
1.0.1
Default branch
main
Requirements
loki-checkout/magento2-core: ^2.3
magento/framework: ^103.0
magento/module-backend: ^102.0
magento/module-checkout: ^100.4
magento/module-config: ^101.2
magento/module-store: ^101.1
Releases
1.0.1 24 June 2026
1.0.0 24 June 2026
Changelog

[1.0.1] - 01 June 2026

Fixed

  • Add enabled flag to configuration
  • Rename theme to skin
  • Add JS API to README

[1.0.0] - 18 May 2026

  • Initial version

Last modified: June 1, 2026