/**
  * @param Price|null $price
  * @return Price|null
  */
 public function reverseTransform($price)
 {
     if (!$price || !$price instanceof Price || filter_var($price->getValue(), FILTER_VALIDATE_FLOAT) === false) {
         return null;
     }
     return $price;
 }
 /**
  * @param Price|null $price
  * @return Price|null
  */
 public function reverseTransform($price)
 {
     if (!$price || !$price instanceof Price || !$price->getValue()) {
         return null;
     }
     return $price;
 }
 /**
  * Formats currency number according to locale settings.
  *
  * Options format:
  * array(
  *     'attributes' => array(
  *          <attribute> => <value>,
  *          ...
  *      ),
  *     'textAttributes' => array(
  *          <attribute> => <value>,
  *          ...
  *      ),
  *     'symbols' => array(
  *          <symbol> => <value>,
  *          ...
  *      ),
  *     'locale' => <locale>
  * )
  *
  * @param Price $price
  * @param array $options
  * @return string
  */
 public function formatPrice(Price $price, array $options = [])
 {
     $value = $price->getValue();
     $currency = $price->getCurrency();
     $attributes = (array) $this->getOption($options, 'attributes', []);
     $textAttributes = (array) $this->getOption($options, 'textAttributes', []);
     $symbols = (array) $this->getOption($options, 'symbols', []);
     $locale = $this->getOption($options, 'locale');
     return $this->formatter->formatCurrency($value, $currency, $attributes, $textAttributes, $symbols, $locale);
 }
Esempio n. 4
0
 /**
  * @ORM\PrePersist
  * @ORM\PreUpdate
  */
 public function updatePrice()
 {
     if ($this->price) {
         $this->value = $this->price->getValue();
         $this->currency = $this->price->getCurrency();
     }
 }
 /**
  * @ORM\PrePersist
  * @ORM\PreUpdate
  */
 public function updatePrice()
 {
     $this->value = $this->price ? $this->price->getValue() : null;
     $this->currency = $this->price ? $this->price->getCurrency() : null;
 }
 /**
  * @param Price $price
  * @param array $options
  * @param string $expected
  * @dataProvider formatCurrencyDataProvider
  */
 public function testFormatCurrency(Price $price, array $options, $expected)
 {
     $this->formatter->expects($this->once())->method('formatCurrency')->with($price->getValue(), $price->getCurrency(), $options['attributes'], $options['textAttributes'], $options['symbols'], $options['locale'])->will($this->returnValue($expected));
     $this->assertEquals($expected, $this->extension->formatPrice($price, $options));
 }