findPhysicalQuantityByType.php
Table of Contents
Functions
- findPhysicalQuantityByType() : PhysicalQuantity|null
- Walk a packaging chain and hand back the level whose `additionalType` matches, as a {@see PhysicalQuantity} — so the level found keeps what it weighs and what it occupies.
Functions
findPhysicalQuantityByType()
Walk a packaging chain and hand back the level whose `additionalType` matches, as a {@see PhysicalQuantity} — so the level found keeps what it weighs and what it occupies.
findPhysicalQuantityByType(string $type[, array<string|int, mixed>|QuantitativeValue|null $tree = null ]) : PhysicalQuantity|null
🔑 The level found is typed, and so is the chain below it. A consumer that
walks on from the level it asked for reads ->weight at every depth, never
['weight'] one step down : the walk hands back the same shape
Reflection::hydrate() builds, not a typed head sitting
over raw rows.
The chain is read one level at a time, valueReference after
valueReference, until the type is met or the chain stops.
🔑 The tree is a parameter, not a property. The walk belongs to whoever holds a chain, and a chain is not always reachable from the product that defined it : it is built at import time, copied onto the offers, and it is that copy which is stored — so a product read back from a base has none, while the offer beside it does. Left private on the product, the walk had to be written a second time by anyone holding the offer's tree, and a walk written by hand rebuilds the levels as plain QuantitativeValue : that class declares neither weight nor volume, and a class discards the keys it does not declare. Both would leave without an error and without a trace. Exposing the walk is what makes that loss impossible rather than repairable.
⚠️ Schema.org lets valueReference hold things that are not quantities at
all — a bare code, an enumeration. Anything that is neither an array nor a
QuantitativeValue ends the walk instead of being read as a level.
Example:
$parcel = findPhysicalQuantityByType( UnitOfSaleType::PARCEL , $offer->eligibleQuantity ) ;
$parcel?->weight ; // 245.1456
Parameters
- $type : string
-
One of the UnitOfSaleType constants.
- $tree : array<string|int, mixed>|QuantitativeValue|null = null
-
The chain to walk — a typed level, or the raw rows a base read leaves.
Tags
Return values
PhysicalQuantity|null —The matching level, or null when the chain holds none.