diff -u b/modules/order/src/Adjustment.php b/modules/order/src/Adjustment.php --- b/modules/order/src/Adjustment.php +++ b/modules/order/src/Adjustment.php @@ -197,20 +197,31 @@ } /** + * Returns all storage elements as an array. + * + * @return array + * An associative array of attributes. + */ + public function toArray() { + return [ + 'type' => $this->type, + 'label' => $this->label, + 'amount' => $this->amount->toArray(), + 'percentage' => $this->percentage, + 'sourceId' => $this->sourceId, + 'included' => $this->included, + 'locked' => $this->locked, + ]; + + } + + /** * {@inheritdoc} * * @see \Drupal\serialization\Normalizer\AnyNormalizer */ public function getIterator() { - return new \ArrayIterator([ - 'type' => $this->getType(), - 'label' => $this->getLabel(), - 'amount' => $this->getAmount(), - 'percentage' => $this->getPercentage(), - 'source_id' => $this->getSourceId(), - 'included' => $this->isIncluded(), - 'locked' => $this->isLocked(), - ]); + return new \ArrayIterator($this->toArray()); } } only in patch2: unchanged: --- a/modules/order/src/Plugin/Field/FieldType/AdjustmentItem.php +++ b/modules/order/src/Plugin/Field/FieldType/AdjustmentItem.php @@ -3,6 +3,7 @@ namespace Drupal\commerce_order\Plugin\Field\FieldType; use Drupal\commerce_order\Adjustment; +use Drupal\commerce_price\Price; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; @@ -48,6 +49,11 @@ class AdjustmentItem extends FieldItemBase { // The property definition causes the adjustment to be in 'value' key. $values = reset($values); } + // Used for denormalization. + if (is_array($values)) { + $values['amount'] = new Price($values['amount']['number'], $values['amount']['currency_code']); + $values = new Adjustment($values); + } if (!$values instanceof Adjustment) { $values = NULL; }