Пример #1
0
 /**
  * Add the meta information.
  *
  * @param SeoPageInterface $seoPage
  * @param ProductInterface $product
  */
 public function alterPage(SeoPageInterface $seoPage, ProductInterface $product)
 {
     $seoPage->addMeta('name', 'twitter:card', 'product')->addMeta('name', 'twitter:title', $product->getName())->addMeta('name', 'twitter:description', substr($product->getDescription(), 0, 200))->addMeta('name', 'twitter:label1', 'Price')->addMeta('name', 'twitter:data1', $this->numberHelper->formatCurrency($product->getPrice(), $this->currencyDetector->getCurrency()))->addMeta('name', 'twitter:label2', 'SKU')->addMeta('name', 'twitter:data2', $product->getSku())->addMeta('name', 'twitter:site', $this->site)->addMeta('name', 'twitter:creator', $this->creator)->addMeta('name', 'twitter:domain', $this->domain);
     if ($image = $product->getImage()) {
         $provider = $this->mediaPool->getProvider($image->getProviderName());
         $seoPage->addMeta('property', 'twitter:image:src', $provider->generatePublicUrl($image, $this->mediaFormat));
     }
 }
Пример #2
0
 public function testLocale()
 {
     $localeDetector = $this->getMock('Sonata\\IntlBundle\\Locale\\LocaleDetectorInterface');
     $localeDetector->expects($this->any())->method('getLocale')->will($this->returnValue('fr'));
     $helper = new NumberHelper('UTF-8', $localeDetector);
     // currency
     $this->assertEquals('10,49 €', $helper->formatCurrency(10.49, 'EUR'));
     $this->assertEquals('10,50 €', $helper->formatCurrency(10.499, 'EUR'));
     $this->assertEquals('10 000,50 €', $helper->formatCurrency(10000.499, 'EUR'));
     $this->assertEquals('10,49 €', $helper->formatCurrency(10.49, 'EUR', array('fraction_digits' => 0)));
     // decimal
     $this->assertEquals('10', $helper->formatDecimal(10));
     $this->assertEquals('10,155', $helper->formatDecimal(10.15459));
     $this->assertEquals('1 000 000,155', $helper->formatDecimal(1000000.15459));
     // scientific
     $this->assertEquals('1E1', $helper->formatScientific(10));
     $this->assertEquals('1E3', $helper->formatScientific(1000));
     $this->assertEquals('1,0001E3', $helper->formatScientific(1000.1));
     $this->assertEquals('1,00000015459E6', $helper->formatScientific(1000000.15459));
     $this->assertEquals('1,00000015459E6', $helper->formatScientific(1000000.15459));
     // duration
     $this->assertEquals('1 000 000', $helper->formatDuration(1000000));
     // spell out
     $this->assertEquals('un', $helper->formatSpellout(1));
     $this->assertEquals('quarante-deux', $helper->formatSpellout(42));
     if (version_compare(NumberHelper::getICUDataVersion(), '52', '>=')) {
         $this->assertEquals('un million deux cent vingt-quatre mille cinq cent cinquante-sept virgule un deux cinq quatre', $helper->formatSpellout(1224557.1254));
     } else {
         $this->assertEquals('un million deux-cent-vingt-quatre-mille-cinq-cent-cinquante-sept virgule un deux cinq quatre', $helper->formatSpellout(1224557.1254));
     }
     // percent
     $this->assertEquals('10 %', $helper->formatPercent(0.1));
     $this->assertEquals('200 %', $helper->formatPercent(1.999));
     $this->assertEquals('99 %', $helper->formatPercent(0.99));
     // ordinal
     if (version_compare(NumberHelper::getICUDataVersion(), '4.8.0', '>=')) {
         $this->assertEquals('1er', $helper->formatOrdinal(1), 'ICU Version: ' . NumberHelper::getICUDataVersion());
         $this->assertEquals('100e', $helper->formatOrdinal(100), 'ICU Version: ' . NumberHelper::getICUDataVersion());
         $this->assertEquals('10 000e', $helper->formatOrdinal(10000), 'ICU Version: ' . NumberHelper::getICUDataVersion());
     } elseif (version_compare(NumberHelper::getICUDataVersion(), '4.1.0', '>=')) {
         $this->assertEquals('1ᵉʳ', $helper->formatOrdinal(1), 'ICU Version: ' . NumberHelper::getICUDataVersion());
         $this->assertEquals('100ᵉ', $helper->formatOrdinal(100), 'ICU Version: ' . NumberHelper::getICUDataVersion());
         $this->assertEquals('10 000ᵉ', $helper->formatOrdinal(10000), 'ICU Version: ' . NumberHelper::getICUDataVersion());
     } else {
         $this->markTestIncomplete(sprintf('Unknown ICU DATA Version, feel free to contribute ... (version: %s)', NumberHelper::getICUDataVersion()));
     }
 }
 /**
  * @param float  $number
  * @param string $currency
  * @param array  $attributes
  * @param array  $textAttributes
  * @param null   $locale
  *
  * @return string
  */
 public function formatCurrency($number, $currency, array $attributes = array(), array $textAttributes = array(), $locale = null)
 {
     return $this->helper->formatCurrency($number, $currency, $attributes, $textAttributes, $locale);
 }