/** * Convert all the products metric values into the channel configured conversion units * * @param ProductInterface $product * @param ChannelInterface $channel */ public function convert(ProductInterface $product, ChannelInterface $channel) { $channelUnits = $channel->getConversionUnits(); foreach ($product->getValues() as $value) { $data = $value->getData(); $attribute = $value->getAttribute(); if ($data instanceof MetricInterface && isset($channelUnits[$attribute->getCode()])) { $channelUnit = $channelUnits[$attribute->getCode()]; $this->converter->setFamily($data->getFamily()); $data->setData($this->converter->convert($data->getUnit(), $channelUnit, $data->getData())); $data->setUnit($channelUnit); } } }
/** * Test related exception in standard to final method * @expectedException Akeneo\Bundle\MeasureBundle\Exception\UnknownMeasureException */ public function testUnknownMeasureExceptionStandardToFinal() { $this->converter->setFamily(WeightFamilyInterface::FAMILY); $this->converter->convert(WeightFamilyInterface::GRAM, 'test-unit', 50); }