aichouchm/magento2-module-attribute-import 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aichouchm/magento2-module-attribute-import

Composer 安装命令:

composer require aichouchm/magento2-module-attribute-import

包简介

Magento 2 module for bulk importing product attribute options from CSV files via the admin panel

README 文档

README

Magento 2 module for bulk importing product attribute options from CSV files via the Admin Panel.

Overview

Magento 2 has no native way to bulk-import attribute options (the selectable values of a select or multiselect attribute, such as colors, sizes, or materials). The only built-in approach is clicking "Add Option" dozens of times in the admin UI — one row at a time.

This module adds a dedicated page under Stores → Attributes → Import Attributes that lets an admin:

  1. Select an attribute (e.g. color)
  2. Upload a CSV file containing all desired option values, their translations per store view, and (optionally) swatch data
  3. Preview and validate the file before committing
  4. Import with one click — new options are created, duplicates are logged and skipped
  5. Review the import log directly in the admin panel

Requirements

Dependency Version
PHP ≥ 8.1
Magento Open Source / Adobe Commerce 2.4.x
magento/module-swatches bundled with Magento

Installation

composer require aichouchm/magento2-module-attribute-import
bin/magento module:enable Aichouchm_AttributeImport
bin/magento setup:upgrade
bin/magento cache:flush

Admin Panel Location

Stores → Attributes → Import Attributes

A View Log button on the import page opens the log viewer directly.

CSV Format

All attributes use the same 6-column format regardless of type:

attribute_code,store_view,value,hex_code,sort_order,is_default

Plain select attribute (no swatch) — leave hex_code empty

attribute_code,store_view,value,hex_code,sort_order,is_default
size,default,Small,,1,1
size,fr,Petite,,1,1
size,en,Small,,1,1
size,default,Medium,,2,0
size,fr,Moyenne,,2,0
size,en,Medium,,2,0

Visual swatch attribute — provide #RRGGBB in hex_code

attribute_code,store_view,value,hex_code,sort_order,is_default
color,default,Red,#FF0000,1,1
color,fr,Rouge,#FF0000,1,1
color,en,Red,#FF0000,1,1
color,default,Blue,#0000FF,2,0
color,fr,Bleu,#0000FF,2,0
color,en,Blue,#0000FF,2,0

Column Reference

Column Required Description
attribute_code Yes Must match the attribute you selected in the form. Every row must have the same value.
store_view Yes default or admin = global label (store_id=0). Any other value must be a valid Magento store code (e.g. fr, en).
value Yes The option label for this store view.
hex_code Yes (visual swatch only) Hex colour (#RRGGBB). Leave empty for plain select and multiselect attributes.
sort_order Yes (admin row only) Integer. Controls the display order of the option in dropdowns.
is_default Yes (admin row only) 1 = this option is the default selected value. Only one option may have is_default=1.

Row Grouping Rules

Each option is defined as a group of rows:

  • The first row of a group has store_view = default (or admin) — this is the global (admin-store) label.
  • Subsequent rows have other store view codes — these are translations.
  • A new group begins at the next default/admin row.
color,default,Red,#FF0000,1,1   ← start of group 1 (sort_order and is_default set here)
color,fr,Rouge,#FF0000,1,1      ← translation for "fr" store
color,en,Red,#FF0000,1,1        ← translation for "en" store
color,default,Blue,#0000FF,2,0  ← start of group 2
color,fr,Bleu,#0000FF,2,0
color,en,Blue,#0000FF,2,0

Validation Rules

The Check Data button validates the file before any data is written:

Rule Severity
sort_order must be a number Error — blocks import
is_default must be 0 or 1 Error — blocks import
Only one option may have is_default=1 Error — blocks import
No duplicate values within the same default/admin store in the CSV Error — blocks import
hex_code must be a valid #RRGGBB colour for visual swatch attributes Error — blocks import
Option value already exists in the database Warning — logs and skips

Duplicate Handling

If an option value already exists in the database for the selected attribute, the module skips it silently (logs a warning) instead of overwriting it. This is intentional — it protects options that have been manually adjusted by an admin.

Skipped values appear in the import result message and in the log file.

Logging

Every import action is logged to:

var/log/attribute_import.log

Each entry includes a timestamp, log level, and a message. Entries are visible from Stores → Attributes → Import Attributes → View Log without needing server access.

Log levels used:

Level When
INFO Import started, import completed with summary
WARNING Option skipped because it already exists
ERROR Validation failure, unexpected exception

Architecture Summary

CSV upload
    │
    ▼
StreamingReader        ← fgetcsv generator — O(1) memory per row
    │
    ▼
Validator              ← stateless, returns error list — no DB writes
    │
    ▼  (only if valid)
ImportService          ← groups rows by option, pre-loads existing options once
    │
    ▼
OptionProcessor        ← bulk DB writes: insertOnDuplicate for labels and swatches
    │
    ▼
CacheManager           ← clears eav + full_page caches
    │
    ▼
Logger                 ← writes to var/log/attribute_import.log

ACL / Permissions

The module registers one ACL resource:

Magento_Backend::stores
  └── Magento_Backend::stores_attributes
        └── Aichouchm_AttributeImport::import_attributes   ← "Import Attributes"

Assign this resource to any admin role that needs access to the import page.

Supported Attribute Types

Frontend Input Supported
select Yes
multiselect Yes
swatch_visual Yes (hex + image URL)
swatch_text Yes
boolean, date, text, etc. No — these have no options

System attributes (is_user_defined = false) are excluded from the attribute selector to prevent accidental modification of core Magento configuration.

Compatibility

  • Tested with Magento 2.4.6 and 2.4.7
  • Compatible with Varnish full-page caching (module clears eav and full_page cache tags after import)
  • Compatible with Redis page cache

License

MIT — see LICENSE file.

aichouchm/magento2-module-attribute-import 适用场景与选型建议

aichouchm/magento2-module-attribute-import 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 aichouchm/magento2-module-attribute-import 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aichouchm/magento2-module-attribute-import 我们能提供哪些服务?
定制开发 / 二次开发

基于 aichouchm/magento2-module-attribute-import 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 24
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 43
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-14