Documentation

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.
hydrate()  : array<string, array{id: string, meta: array, value: mixed}>
Re-attach definitions to stored attributes: `{id, value}` → `{id, meta, value}`.
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.
toReferences()  : array<string, array{id: string, value: mixed}>
Strip the embedded definition down to a reference: `{meta, value}` → `{id, value}`.

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
bool

hydrate()

Re-attach definitions to stored attributes: `{id, value}` → `{id, meta, value}`.

public static hydrate(array<string, array<string|int, mixed>> $attributes, array<string, array<string|int, mixed>> $definitions) : array<string, array{id: string, meta: array, value: mixed}>

Accepts both shapes, so documents written before the switch keep working during the transition (an entry that already carries meta is passed through). An id with no definition — the attribute was removed from PIM after the product was indexed — gets an empty meta: the value stays reachable by key and Attribute's getters fall back to ''.

Parameters
$attributes : array<string, array<string|int, mixed>>

data.attributes as stored in a products document.

$definitions : array<string, array<string|int, mixed>>

Attribute documents keyed by numeric id (AttributesCollection::getIndexedAttributes()).

Return values
array<string, array{id: string, meta: array, value: mixed}>

simplifyGroup()

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).

toReferences()

Strip the embedded definition down to a reference: `{meta, value}` → `{id, value}`.

public static toReferences(array<string, array{meta: array, value: mixed}> $attributes) : array<string, array{id: string, value: mixed}>

meta is the matching document of the global attributes collection, copied verbatim: ~0.8 KB × ~230 attributes per product, half of every products doc and ~800 MB of duplicates across the catalogue. Storing only the id keeps the pretty_id keying (and the additive collision keys) intact; readers re-join the definition with hydrate().

Parameters
$attributes : array<string, array{meta: array, value: mixed}>

Output of buildAttributeMap().

Return values
array<string, array{id: string, value: mixed}>
On this page

Search results