function it_returns_data_if_it_is_not_a_numeric(MetricInterface $metric, ProductValueInterface $productValue, AttributeInterface $attribute)
 {
     $metric->getValue()->willReturn($productValue);
     $productValue->getAttribute()->willReturn($attribute);
     $attribute->isDecimalsAllowed()->willReturn(false);
     $metric->getUnit()->willReturn('KILOGRAM');
     $metric->getData()->willReturn('a_metric_data');
     $this->normalize($metric, 'standard', ['is_decimals_allowed' => false])->shouldReturn(['amount' => 'a_metric_data', 'unit' => 'KILOGRAM']);
 }
 function it_normalizes_metric_when_has_data(MetricInterface $metric)
 {
     $metric->getData()->willReturn(42.55);
     $metric->getUnit()->willReturn('GRAM');
     $metric->getBaseData()->willReturn(0.04255);
     $metric->getBaseUnit()->willReturn('KILOGRAM');
     $metric->getFamily()->willReturn('Weight');
     $this->normalize($metric, 'mongodb_json', [])->shouldReturn(['data' => 42.55, 'unit' => 'GRAM', 'baseData' => 0.04255, 'baseUnit' => 'KILOGRAM', 'family' => 'Weight']);
 }
 /**
  * Allow to create convert data in standard unit for metrics
  *
  * @param MetricInterface $metric
  */
 protected function createMetricBaseValues(MetricInterface $metric)
 {
     $baseUnit = $this->manager->getStandardUnitForFamily($metric->getFamily());
     if (is_numeric($metric->getData())) {
         $baseData = $this->converter->setFamily($metric->getFamily())->convertBaseToStandard($metric->getUnit(), $metric->getData());
     } else {
         $baseData = null;
     }
     $metric->setBaseData($baseData)->setBaseUnit($baseUnit);
 }
 /**
  * Get the data stored in the metric
  *
  * @param MetricInterface $metric
  * @param bool            $withUnit
  * @param bool            $decimalsAllowed
  *
  * @return string
  */
 public function getMetricData(MetricInterface $metric, $withUnit, $decimalsAllowed = true)
 {
     $data = $metric->getData();
     if (null === $data || '' === $data) {
         return '';
     }
     $pattern = $decimalsAllowed ? '%.4F' : '%d';
     if ($withUnit) {
         $data = sprintf($pattern . ' %s', $metric->getData(), $metric->getUnit());
     } else {
         $data = sprintf($pattern, $metric->getData());
     }
     return $data;
 }
 function it_normalizes_metric_with_float_data_with_decimals_not_allowed(MetricInterface $metric)
 {
     $metric->getData()->willReturn('72.0000');
     $metric->getUnit()->willReturn('KILOGRAM');
     $this->normalize($metric, null, ['field_name' => 'weight', 'decimals_allowed' => false])->shouldReturn(['weight' => '72', 'weight-unit' => 'KILOGRAM']);
 }
 function it_returns_flat_data_with_french_attribute($channelManager, $serializer, ChannelInterface $channel, ProductInterface $product, ProductValueInterface $number, AttributeInterface $attribute, MetricInterface $metric, ProductValueInterface $metricValue, ProductPriceInterface $price, ProductValueInterface $priceValue)
 {
     $this->setLocale('fr_FR');
     $attribute->getAttributeType()->willReturn('pim_catalog_number');
     $number->getDecimal('10.50');
     $number->getAttribute()->willReturn($attribute);
     $attribute->getAttributeType()->willReturn('pim_catalog_metric');
     $metric->getData()->willReturn('10.00');
     $metric->getUnit()->willReturn('GRAM');
     $metricValue->getAttribute()->willReturn($attribute);
     $metricValue->getData()->willReturn($metric);
     $attribute->getAttributeType()->willReturn('pim_catalog_price_collection');
     $price->getData()->willReturn('10');
     $price->getCurrency()->willReturn('EUR');
     $priceValue->getAttribute()->willReturn($attribute);
     $priceValue->getData()->willReturn($price);
     $product->getValues()->willReturn([$number, $metricValue, $priceValue]);
     $serializer->normalize($product, 'flat', ['scopeCode' => 'mobile', 'localeCodes' => '', 'locale' => 'fr_FR'])->willReturn(['10,50', '10,00 GRAM', '10,00 EUR', '25/10/2015']);
     $channelManager->getChannelByCode('mobile')->willReturn($channel);
     $this->setChannelCode('mobile');
     $this->process($product)->shouldReturn(['media' => [], 'product' => ['10,50', '10,00 GRAM', '10,00 EUR', '25/10/2015']]);
 }