SuperAPI AI 工具集

bagisto-attribute-development

编程与开发

查看项目

更新于 10-15 17:24

技能介绍

用途:面向 Bagisto 的 EAV(实体—属性—值)属性系统开发,适用于新增或修改属性、属性族(attribute family)、属性组(attribute group),以及读取或写入商品属性值。

主要能力与结构:商品数据不存于 products 表的列,而是存于 product_attribute_values,每个属性每个语言每个渠道一行。层级为 attribute_families → attribute_groups → attributes → attribute_options;商品属于一个属性族,由该族决定其拥有哪些属性,相关关系为 AttributeFamily::custom_attributes() 与 AttributeGroup::custom_attributes()。

列映射:属性类型决定值写入哪一列——text、textarea、multiselect、checkbox、file、image 用 text_value;price 用 float_value;boolean 用 boolean_value;select 用 integer_value;date 用 date_value;datetime 用 datetime_value。该映射位于 Attribute::$attributeTypeFields,可用 $attribute->column_name 取得解析后的列名,不要硬编码列。类型清单以 AttributeTypeEnum 为准,ValidationEnum(numeric、email、decimal、url、regex)与 SwatchTypeEnum(dropdown、color、image、text)覆盖其余部分。

作用域:每个属性带 value_per_locale 与 value_per_channel,二者共同决定一个商品该属性有多少行:都为 false 时 1 行;仅 locale 为 true 时每语言一行;仅 channel 为 true 时每渠道一行;都为 true 时每渠道每语言一行。Product::getCustomAttributeValue() 会按请求的渠道与语言解析对应行,为空时回退到默认渠道与语言。表上有 (channel, locale, attribute_id, product_id) 唯一索引,写错作用域组合会触发约束冲突。

必要用法与限制:必须通过仓库操作,如 AttributeRepository、AttributeFamilyRepository、AttributeGroupRepository、AttributeOptionRepository,不要手写 product_attribute_values。写入时同样要遵守 value_per_locale 与 value_per_channel,否则会丢失其他语言的值。select/multiselect 的值是选项 id 而非标签:select 在 integer_value 存一个 id,multiselect 在 text_value 存逗号分隔的 id。选项标签可翻译,存于 attribute_option_translations。更改属性类型会使既有值孤立,应视为数据迁移。影响列表展示的改动需在 flat 索引器运行后生效。资料要求在任何改动完成前使用 bagisto-change-verification 子技能。