/** * @param ChannelInterface $channel * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData(ChannelInterface $channel, $field, $data) { if ('code' === $field) { $channel->setCode($data); } elseif ('tree' === $field) { $category = $this->findCategory($data); if (null !== $category) { $channel->setCategory($category); } else { throw new \InvalidArgumentException(sprintf('Category with "%s" code does not exist', $data)); } } elseif ('locales' === $field) { foreach ($data as $localeCode) { $locale = $this->findLocale($localeCode); if (null !== $locale) { $channel->addLocale($locale); } else { throw new \InvalidArgumentException(sprintf('Locale with "%s" code does not exist', $localeCode)); } } } elseif ('currencies' === $field) { foreach ($data as $currencyCode) { $currency = $this->findCurrency($currencyCode); if (null !== $currency) { $channel->addCurrency($currency); } else { throw new \InvalidArgumentException(sprintf('Currency with "%s" code does not exist', $currencyCode)); } } } elseif ('label' === $field) { $channel->setLabel($data); } elseif ('color' === $field) { $channel->setColor($data); } }
function it_updates_a_channel($categoryRepository, $localeRepository, $currencyRepository, ChannelInterface $channel, CategoryInterface $tree, LocaleInterface $enUS, LocaleInterface $frFR, CurrencyInterface $usd, CurrencyInterface $eur) { $values = ['code' => 'ecommerce', 'label' => 'Ecommerce', 'locales' => ['en_US', 'fr_FR'], 'currencies' => ['EUR', 'USD'], 'tree' => 'master_catalog', 'conversion_units' => ['weight' => 'GRAM']]; $channel->setCode('ecommerce')->shouldBeCalled(); $channel->setLabel('Ecommerce')->shouldBeCalled(); $categoryRepository->findOneByIdentifier('master_catalog')->willReturn($tree); $channel->setCategory($tree)->shouldBeCalled(); $localeRepository->findOneByIdentifier('en_US')->willReturn($enUS); $localeRepository->findOneByIdentifier('fr_FR')->willReturn($frFR); $channel->setLocales([$enUS, $frFR])->shouldBeCalled(); $currencyRepository->findOneByIdentifier('EUR')->willReturn($eur); $currencyRepository->findOneByIdentifier('USD')->willReturn($usd); $channel->setCurrencies([$eur, $usd])->shouldBeCalled(); $channel->setConversionUnits(['weight' => 'GRAM'])->shouldBeCalled(); $this->update($channel, $values, []); }
/** * @param ChannelInterface $channel * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData(ChannelInterface $channel, $field, $data) { switch ($field) { case 'code': $channel->setCode($data); break; case 'tree': $this->setTree($channel, $data); break; case 'locales': $this->setLocales($channel, $data); break; case 'currencies': $this->setCurrencies($channel, $data); break; case 'label': $channel->setLabel($data); break; case 'conversion_units': $channel->setConversionUnits($data); break; } }