AttributeShape
in package
Pure transforms for the attribute data-shape the datasheet PDF renderer consumes.
Intentionally free of WordPress and TypeSense so the produced shape can be asserted by a fast unit test (see AttributeShapeTest). Both product/attribute collections delegate here.
Table of Contents
Methods
- buildAttributeMap() : array<string, array{meta: array, value: mixed}>
- Build the `data.attributes` map from resolved attributes, keeping colliding `pretty_id`s individually addressable instead of losing all but one to last-write-wins.
- groupNameMatches() : bool
- Locale-tolerant match of a stored group name against a target name.
- simplifyGroup() : stdClass
- Simplify a PIM attribute-group object, storing the group name as a locale map so the PIM stays the single source of truth for localized datasheet section headings.
Methods
buildAttributeMap()
Build the `data.attributes` map from resolved attributes, keeping colliding `pretty_id`s individually addressable instead of losing all but one to last-write-wins.
public
static buildAttributeMap(array<string, array{meta: array, value: mixed}> $resolved) : array<string, array{meta: array, value: mixed}>
The survivor of a pretty_id collision stays at the plain key (last write wins, matching
iteration order) — existing behaviour, untouched. Additionally, and only for collided
families, every non-survivor member is written under <pretty_id>__<numeric_id>. The
survivor is deliberately NOT given an additive key: it already occupies the plain key, so
duplicating it there would make group-iterating consumers (e.g. Product::getAttributesByGroup,
which the theme's spec tables use) render it twice. The result: each colliding member is
reachable exactly once — the survivor via the plain key, the rest via their additive key —
and no existing key is ever changed or removed.
Parameters
- $resolved : array<string, array{meta: array, value: mixed}>
-
Numeric attribute id => {meta, value}.
Return values
array<string, array{meta: array, value: mixed}> —Attributes keyed by pretty_id (+ additive collision keys).
groupNameMatches()
Locale-tolerant match of a stored group name against a target name.
public
static groupNameMatches(mixed $storedName, string $target) : bool
Group names are stored as locale maps (see simplifyGroup). A lookup keyed by the name in
ANY single locale — e.g. an EN-configured block, listing filter, or search-filter setting
rendered on a non-EN site — still matches. A bare-string name (legacy shape) matches
directly. Use this instead of resolveLocalizedValue(...) === $target, which only matches
when the doc happens to resolve to the same locale the target was configured in.
Parameters
- $storedName : mixed
-
The group name as stored (locale map or bare string).
- $target : string
-
The name to match against (in any locale).
Return values
boolsimplifyGroup()
Simplify a PIM attribute-group object, storing the group name as a locale map so the PIM stays the single source of truth for localized datasheet section headings.
public
static simplifyGroup(stdClass $groupObj) : stdClass
The name is stored as a locale => value map (like attribute name/help_text). A
group whose name is already a bare string (e.g. a single-locale source) is passed through
unchanged so the en fallback keeps working.
Parameters
- $groupObj : stdClass
-
The PIM group object (name fetched with
Accept-Language: all).
Return values
stdClass —The simplified group: {id, name, position} with name a locale map (or bare string).