🇫🇷France @Agence Web CoherActio

Account created on 6 September 2008, about 16 years ago
#

Recent comments

🇫🇷France Agence Web CoherActio

The last patch caused side-effects (e.g. price substract() method with adjustment).
I ended up extending Drupal TypedDataNormalizer class to support Ajdustment normalizer

namespace Drupal\my_module\Normalizer;

use Drupal\commerce_order\Adjustment;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\serialization\Normalizer\TypedDataNormalizer;

class MyModuleAdjustmentNormalizer extends TypedDataNormalizer {

  /**
   * {@inheritdoc}
   */
  public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
    $this->addCacheableDependency($context, $object);
    $value = $object->getValue();
    // Support for stringable value objects: avoid numerous custom normalizers.
    if (is_object($value) && method_exists($value, '__toString')) {
      $value = (string) $value;
    }
    if ($value instanceof Adjustment) {
      $value = $value->toArray();
    }
    return $value;
  }
}
Production build 0.71.5 2024