/** * Test getter/add/remove for currency property */ public function testGetAddRemoveCurrency() { $this->assertCount(0, $this->channel->getCurrencies()); // assert adding the right entity $expectedCurrencyEUR = $this->createCurrency('EUR'); $this->assertEntity($this->channel->addCurrency($expectedCurrencyEUR)); $this->assertCount(1, $this->channel->getCurrencies()); $currency = $this->channel->getCurrencies()->first(); $this->assertEquals($expectedCurrencyEUR, $currency); // assert removing the right entity $expectedCurrencyUSD = $this->createCurrency('USD'); $this->channel->addCurrency($expectedCurrencyUSD); $this->assertCount(2, $this->channel->getCurrencies()); $this->assertEntity($this->channel->removeCurrency($expectedCurrencyEUR)); $this->assertCount(1, $this->channel->getCurrencies()); $currency = $this->channel->getCurrencies()->first(); $this->assertEquals($expectedCurrencyUSD, $currency); }
/** * {@inheritdoc} * * @return Channel */ protected function createEntity(array $data) { $channel = new Channel(); $channel->setCode($data['code']); $channel->setLabel($data['label']); foreach ($data['currencies'] as $currencyCode) { $currency = $this->createCurrency($currencyCode); $channel->addCurrency($currency); } foreach ($data['locales'] as $localeCode) { $locale = $this->createLocale($localeCode); $channel->addLocale($locale); } $category = $this->createCategory($data['category']); $channel->setCategory($category); $channel->setConversionUnits(array('weight' => 'KILOGRAM', 'washing_temperature' => null)); return $channel; }
/** * @param array $data * * @return Channel */ protected function createChannel($data) { if (is_string($data)) { $data = [['code' => $data]]; } $data = array_merge(['label' => null, 'color' => null, 'currencies' => null, 'locales' => null, 'tree' => null], $data); $channel = new Channel(); $channel->setCode($data['code']); $channel->setLabel($data['label']); if ($data['color']) { $channel->setColor($data['color']); } foreach ($this->listToArray($data['currencies']) as $currencyCode) { $channel->addCurrency($this->getCurrency($currencyCode)); } foreach ($this->listToArray($data['locales']) as $localeCode) { $channel->addLocale($this->getLocale($localeCode)); } if ($data['tree']) { $channel->setCategory($this->getCategory($data['tree'])); } $this->validate($channel); $this->persist($channel); }
function getChannel() { $channel = new Channel(); $channel->setCode('catalog'); $currency = new Currency(); $currency->setCode('EUR'); $channel->addCurrency($currency); return $channel; }
/** * @param array $data * * @return Channel */ protected function createChannel($data) { if (is_string($data)) { $data = [['code' => $data]]; } $data = array_merge(['label' => null, 'currencies' => null, 'locales' => null, 'tree' => null], $data); $channel = new Channel(); $channel->setCode($data['code']); $channel->setLabel($data['label']); foreach ($this->listToArray($data['currencies']) as $currencyCode) { $channel->addCurrency($this->getCurrency(['code' => explode(',', $currencyCode)])); } foreach ($this->listToArray($data['locales']) as $localeCode) { $channel->addLocale($this->getLocale(['code' => explode(',', $localeCode)])); } if ($data['tree']) { $channel->setCategory($this->getCategory($data['tree'])); } $this->validate($channel); $this->getContainer()->get('pim_catalog.saver.channel')->save($channel); }
/** * {@inheritDoc} */ public function addCurrency(\Pim\Bundle\CatalogBundle\Model\CurrencyInterface $currency) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'addCurrency', array($currency)); return parent::addCurrency($currency); }