You are here

class PriceNumberNormalizer in Commerce Core 8.2

Normalizes price field number properties.

MySQL will store the number with trailing zeros, causing comparison problems.

@todo remove after https://www.drupal.org/project/drupal/issues/3163853

Hierarchy

Expanded class hierarchy of PriceNumberNormalizer

1 string reference to 'PriceNumberNormalizer'
commerce_price_test.services.yml in modules/price/tests/modules/commerce_price_test/commerce_price_test.services.yml
modules/price/tests/modules/commerce_price_test/commerce_price_test.services.yml
1 service uses PriceNumberNormalizer
commerce_test.price_number_normalizer in modules/price/tests/modules/commerce_price_test/commerce_price_test.services.yml
Drupal\commerce_price_test\Normalizer\PriceNumberNormalizer

File

modules/price/tests/modules/commerce_price_test/src/Normalizer/PriceNumberNormalizer.php, line 16

Namespace

Drupal\commerce_price_test\Normalizer
View source
class PriceNumberNormalizer extends PrimitiveDataNormalizer {

  /**
   * {@inheritdoc}
   */
  protected $supportedInterfaceOrClass = StringData::class;

  /**
   * {@inheritdoc}
   */
  public function supportsNormalization($data, $format = NULL) {
    $supported = parent::supportsNormalization($data, $format);
    return $supported && $data instanceof StringData && $data
      ->getParent() instanceof PriceItem && $data
      ->getName() === 'number';
  }

  /**
   * {@inheritdoc}
   */
  public function normalize($object, $format = NULL, array $context = []) {
    $data = parent::normalize($object, $format, $context);
    return number_format($data, 2);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 2
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
PriceNumberNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides PrimitiveDataNormalizer::$supportedInterfaceOrClass
PriceNumberNormalizer::normalize public function Normalizes an object into a set of arrays/scalars. Overrides PrimitiveDataNormalizer::normalize
PriceNumberNormalizer::supportsNormalization public function Checks whether the given class is supported for normalization by this normalizer. Overrides NormalizerBase::supportsNormalization
SerializedColumnNormalizerTrait::checkForSerializedStrings protected function Checks if there is a serialized string for a column.
SerializedColumnNormalizerTrait::dataHasStringForSerializeColumn protected function Checks if the data contains string value for serialize column.
SerializedColumnNormalizerTrait::getCustomSerializedPropertyNames protected function Gets the names of all properties the plugin treats as serialized data.
SerializedColumnNormalizerTrait::getSerializedPropertyNames protected function Gets the names of all serialized properties.