Skip to content

Commerce Foundations is our pre-built Craft Commerce store. See what it includes

Craft CMS plugins

Variant Manager

A Craft CMS plugin that imports and exports Craft Commerce product variants from CSV files.

Installation

A Craft CMS plugin that imports and exports Craft Commerce product variants from CSV files.

Requirements#

  • Craft CMS ^5.0
  • Craft Commerce ^5.0
  • PHP ^8.2

Install#

From the Plugin Store, search for Variant Manager in Settings -> Plugins and press Install.

With Composer:

composer require fostercommerce/variant-manager
./craft plugin/install variant-manager

With DDEV:

ddev composer require fostercommerce/variant-manager -w && ddev craft plugin/install variant-manager

After install the CP navigation gets a Variant Manager item with Dashboard and Variants. Variant Attributes and Attribute Options appear for users with variant-manager:manage-attributes.

Configure#

Import and export settings live in a config file. The plugin runs without one. Create config/variant-manager.php to change any of the defaults:

<?php

return [
    'emptyAttributeValue' => '',
    'attributePrefix' => 'Attribute: ',
    'inventoryPrefix' => 'Inventory',
    'activityLogRetention' => '30 days',
    'productFieldMap' => [
        '*' => [
            'title' => 'title',
            'slug' => 'slug',
            'status' => 'status',
        ],
    ],
    'variantFieldMap' => [
        '*' => [
            'title' => 'title',
            'sku' => 'sku',
            'inventoryTracked' => 'inventoryTracked',
            'basePrice' => 'basePrice',
            'height' => 'height',
            'width' => 'width',
            'length' => 'length',
            'weight' => 'weight',
        ],
    ],
];

Those values are the defaults, so the file above changes nothing. See configuration reference for what each key controls.

Attribute display types and field layouts are set in the CP instead, at Settings -> Plugins -> Variant Manager, and stored in project config. See variant attributes.

Add the Variant Attributes field#

The plugin ships a Variant Attributes field type. Add it to every Commerce product type whose variants you want to import or export by attribute.

  1. Settings -> Fields -> New field.
  2. Set the Field Type to Variant Attributes. Give it a name and handle, for example variantAttributes. The field has no settings of its own.
  3. Commerce -> Settings -> Product Types -> {product type} -> Variant Fields and drag the field into the variant field layout.

Only one Variant Attributes field per variant field layout is read by the plugin. Additional copies are ignored.

See Variant Attributes field reference for how the field stores data.

Permissions#

Grant the plugin’s permissions on user groups at Users -> {group} -> Permissions or on individual users. accessPlugin-variant-manager is required to see the plugin’s CP section at all.

See permissions reference for the full list.

Console commands#

./craft variant-manager/activities/clear

Deletes activity log entries older than activityLogRetention. Pass 1 to wipe every entry regardless of age. Craft’s garbage collection runs the same expiry pass automatically. See console commands.

./craft variant-manager/attributes/backfill

Registers an attribute and option for every name and value already stored on a variant. Run this once after installing on a store that already has variant data.

./craft variant-manager/attributes/orphans

Lists attributes and options no longer used by any variant. Pass --prune to delete them.

We can take it from here.

We take on the Craft and Craft Commerce sites you built, so you can get back to building. Introduce a client who signs a management contract and you get a $3,000 partnership fee.

How the Dev Partnership Program works
See if we’re a fit