function it_normalizes_channel(ChannelInterface $channel, CategoryInterface $category, CurrencyInterface $currencyUSD, CurrencyInterface $currencyEUR)
 {
     $units = ['weight_attribute' => WeightFamilyInterface::GRAM, 'length_attribute' => LengthFamilyInterface::CENTIMETER];
     $channel->getCode()->willReturn('my_code');
     $channel->getLabel()->willReturn('my_label');
     $channel->getCurrencies()->willReturn([$currencyEUR, $currencyUSD]);
     $channel->getLocaleCodes()->willReturn(['fr_FR', 'en_US', 'de_DE', 'es_ES']);
     $channel->getCategory()->willReturn($category);
     $channel->getConversionUnits()->willReturn($units);
     $category->getCode()->willReturn('winter');
     $currencyEUR->getCode()->willReturn('EUR');
     $currencyUSD->getCode()->willReturn('USD');
     $this->normalize($channel, 'standard', [])->shouldReturn(['code' => 'my_code', 'label' => 'my_label', 'currencies' => ['EUR', 'USD'], 'locales' => ['fr_FR', 'en_US', 'de_DE', 'es_ES'], 'category_tree' => 'winter', 'conversion_units' => $units]);
 }
 function it_normalizes_channel(ChannelInterface $channel, CurrencyInterface $eur, CurrencyInterface $usd, LocaleInterface $en, LocaleInterface $fr, CategoryInterface $category)
 {
     $channel->getCode()->willReturn('ecommerce');
     $channel->getLabel()->willReturn('Ecommerce');
     $channel->getCurrencies()->willReturn([$eur, $usd]);
     $eur->getCode()->willReturn('EUR');
     $usd->getCode()->willReturn('USD');
     $channel->getLocales()->willReturn([$en, $fr]);
     $en->getCode()->willReturn('en_US');
     $fr->getCode()->willReturn('fr_FR');
     $channel->getCategory()->willReturn($category);
     $category->getCode()->willReturn('Master catalog');
     $channel->getConversionUnits()->willReturn(['Weight' => 'Kilogram', 'Size' => 'Centimeter']);
     $this->normalize($channel)->shouldReturn(['code' => 'ecommerce', 'label' => 'Ecommerce', 'currencies' => 'EUR,USD', 'locales' => 'en_US,fr_FR', 'category' => 'Master catalog', 'conversion_units' => 'Weight: Kilogram, Size: Centimeter']);
 }
 function it_does_not_convert_null_metric_values_in_the_channel($converter, ProductValueInterface $weightValue, AttributeInterface $weight, MetricInterface $weightMetric, ProductInterface $product, ChannelInterface $channel)
 {
     $weightValue->getAttribute()->willReturn($weight);
     $weightValue->getData()->willReturn($weightMetric);
     $weight->getCode()->willReturn('weight');
     $weightMetric->getFamily()->willReturn('Weight');
     $weightMetric->getUnit()->willReturn(null);
     $weightMetric->getData()->willReturn(null);
     $product->getValues()->willReturn(array($weightValue));
     $channel->getConversionUnits()->willReturn(array('weight' => 'GRAM'));
     $converter->setFamily('Weight')->shouldNotBeCalled();
     $converter->convert('KILOGRAM', 'GRAM', 1)->shouldNotBeCalled();
     $weightMetric->setData(null)->shouldNotBeCalled();
     $weightMetric->setUnit('GRAM')->shouldNotBeCalled();
     $this->convert($product, $channel);
 }
 /**
  * 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()])) {
             if (null === $data->getData()) {
                 return;
             }
             $channelUnit = $channelUnits[$attribute->getCode()];
             $this->converter->setFamily($data->getFamily());
             $data->setData($this->converter->convert($data->getUnit(), $channelUnit, $data->getData()));
             $data->setUnit($channelUnit);
         }
     }
 }
 function it_normalizes_channel(ChannelInterface $channel, CurrencyInterface $eur, CurrencyInterface $usd, LocaleInterface $en, LocaleInterface $fr, CategoryInterface $category, CategoryTranslationInterface $translation)
 {
     $channel->getCode()->willReturn('ecommerce');
     $channel->getLabel()->willReturn('Ecommerce');
     $channel->getCurrencies()->willReturn([$eur, $usd]);
     $eur->getCode()->willReturn('EUR');
     $usd->getCode()->willReturn('USD');
     $channel->getLocales()->willReturn([$en, $fr]);
     $en->getCode()->willReturn('en_US');
     $fr->getCode()->willReturn('fr_FR');
     $channel->getCategory()->willReturn($category);
     $category->getCode()->willReturn('master');
     $category->getId()->willReturn(42);
     $translation->getLabel()->willReturn('label');
     $translation->getLocale()->willReturn('en_US');
     $category->getTranslations()->willReturn([$translation]);
     $channel->getConversionUnits()->willReturn(['Weight' => 'Kilogram', 'Size' => 'Centimeter']);
     $this->normalize($channel)->shouldReturn(['code' => 'ecommerce', 'label' => 'Ecommerce', 'currencies' => ['EUR', 'USD'], 'locales' => ['en_US', 'fr_FR'], 'category' => ['id' => 42, 'code' => 'master', 'labels' => ['en_US' => 'label']], 'conversion_units' => 'Weight: Kilogram, Size: Centimeter']);
 }
 /**
  * Returns conversion units
  *
  * @param ChannelInterface $channel
  *
  * @return string
  */
 protected function normalizeConversionUnits(ChannelInterface $channel)
 {
     $result = [];
     foreach ($channel->getConversionUnits() as $family => $unit) {
         $result[] = sprintf('%s: %s', $family, $unit);
     }
     return implode(', ', $result);
 }