reverted: --- b/commerce.services.yml +++ a/commerce.services.yml @@ -64,10 +64,3 @@ plugin.manager.commerce_entity_trait: class: Drupal\commerce\EntityTraitManager arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@commerce.configurable_field_manager'] - serializer.normalizer.object: - class: Drupal\commerce\Normalizer\ObjectAnyNormalizer - tags: - # This normalizer must be higher than serializer.normalizer.typed_data - # So setting priority as 0 here. - # @see \Drupal\commerce\Normalizer\ObjectAnyNormalizer::supportsNormalization - - { name: normalizer, priority: 0} reverted: --- b/modules/order/src/Adjustment.php +++ a/modules/order/src/Adjustment.php @@ -7,7 +7,7 @@ /** * Represents an adjustment. */ +final class Adjustment { -final class Adjustment implements \IteratorAggregate { /** * The adjustment type. @@ -196,30 +196,4 @@ return $this->locked; } - /** - * 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} - */ - public function getIterator() { - return new \ArrayIterator($this->toArray()); - } - } reverted: --- b/src/Normalizer/ObjectAnyNormalizer.php +++ /dev/null @@ -1,50 +0,0 @@ -getValue(); - if (isset($value) && is_object($value) && $value instanceof Adjustment) { - return TRUE; - } - } - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function normalize($object, $format = NULL, array $context = []) { - $value = $object->getValue(); - // If the value is object or array, return the normalized result, object - // must be typed data or traversable to be normalizable. - if (isset($value) && (is_object($value) || is_array($value))) { - $value = $this->serializer->normalize($value, $format, $context); - } - return $value; - } - -} only in patch2: unchanged: --- a/modules/order/commerce_order.services.yml +++ b/modules/order/commerce_order.services.yml @@ -62,3 +62,10 @@ services: arguments: ['@current_route_match'] tags: - { name: commerce_store.store_resolver, priority: 100 } + serializer.normalizer.any_adjustment: + class: Drupal\commerce_order\Normalizer\AnyAdjustmentNormalizer + tags: + # This normalizer must be higher than serializer.normalizer.typed_data + # So setting priority as 0 here. + # @see \Drupal\commerce\Normalizer\ObjectAnyNormalizer::supportsNormalization + - { name: normalizer, priority: 0} only in patch2: unchanged: --- /dev/null +++ b/modules/order/src/Normalizer/AnyAdjustmentNormalizer.php @@ -0,0 +1,51 @@ +getValue(); + if (isset($value) && is_object($value) && $value instanceof Adjustment) { + return TRUE; + } + } + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function normalize($object, $format = NULL, array $context = []) { + $attributes = []; + /** @var \Drupal\commerce_order\Adjustment $adjustment */ + $adjustment = $object->getValue(); + $attributes['type'] = $adjustment->getType(); + $attributes['label'] = $adjustment->getLabel(); + $attributes['amount'] = $adjustment->getAmount()->toArray(); + $attributes['percentage'] = $adjustment->getPercentage(); + $attributes['sourceId'] = $adjustment->getSourceId(); + $attributes['included'] = $adjustment->isIncluded(); + $attributes['locked'] = $adjustment->isLocked(); + return $attributes; + } + +}