/** * Ensure deletion of a country. * * @param InputInterface $input The input interface * @param OutputInterface $output The output interface * * @return $this Self object */ protected function deleteCountry(InputInterface $input, OutputInterface $output, $countryCode) { $noInteraction = $input->getOption('no-interaction'); $country = $this->locationDirector->findOneBy(['code' => $countryCode]); if ($country instanceof LocationInterface) { if (!$noInteraction && !$this->confirmRemoval($input, $output, $countryCode, $output)) { return $this; } $this->dropCountry($country, $output); } else { $this->printMessage($output, 'Geo', 'Country ' . $countryCode . ' not found in your database'); } return $this; }
/** * Test that modifying a new root category the parent category should be * null. */ public function testEditRootCategoryIsSavedWithoutParent() { /** * @var $rootCategory CategoryInterface */ $rootCategory = $this->categoryDirector->findOneBy(['slug' => 'root-category']); /** * @var $anotherCategory CategoryInterface */ $anotherCategory = $this->categoryDirector->findOneBy(['slug' => 'category']); $rootCategory->setParent($anotherCategory); $this->categoryDirector->save($rootCategory); /** * @var $category CategoryInterface */ $category = $this->categoryDirector->findOneBy(['slug' => 'root-category']); $this->assertNull($category->getParent(), 'The parent for a root category should always be null'); }
/** * Remove Vote action * * @param CommentInterface $comment Comment * @param string $authorToken Author token * * @return $this VoteManager */ public function removeVote(CommentInterface $comment, $authorToken) { /** * @var VoteInterface $vote */ $vote = $this->commentVoteObjectDirector->findOneBy(['authorToken' => $authorToken, 'comment' => $comment]); if ($vote instanceof VoteInterface) { $this->commentVoteObjectDirector->remove($vote); } return $this; }
/** * Populates the exchange rates. * * @return $this Self object */ public function populate() { $currenciesCodes = []; $currencies = $this->currencyRepository->findAll(); /** * Create an array of all active currency codes. * * @var CurrencyInterface $currency */ foreach ($currencies as $currency) { if ($currency->getIso() != $this->defaultCurrency) { $currenciesCodes[] = $currency->getIso(); } } /** * Get rates for all of the enabled and active currencies. */ $rates = $this->currencyExchangeRatesAdapter->getExchangeRates($this->defaultCurrency, $currenciesCodes); /** * @var CurrencyInterface $sourceCurrency */ $sourceCurrency = $this->currencyRepository->findOneBy(['iso' => $this->defaultCurrency]); /** * [ * "EUR" => "1,378278", * "YEN" => "0,784937", * ]. */ foreach ($rates as $code => $rate) { /** * @var CurrencyInterface $targetCurrency */ $targetCurrency = $this->currencyRepository->findOneBy(['iso' => $code]); if (!$targetCurrency instanceof CurrencyInterface) { continue; } /** * check if this is a new exchange rate, or if we have to * create a new one. */ $exchangeRate = $this->currencyExchangeRateObjectDirector->findOneBy(['sourceCurrency' => $sourceCurrency, 'targetCurrency' => $targetCurrency]); if (!$exchangeRate instanceof CurrencyExchangeRateInterface) { $exchangeRate = $this->currencyExchangeRateObjectDirector->create(); } $exchangeRate->setExchangeRate($rate)->setSourceCurrency($sourceCurrency)->setTargetCurrency($targetCurrency); $this->currencyExchangeRateObjectDirector->save($exchangeRate); } return $this; }
/** * Test that the principal category is assigned as category when a product * is saved only with principal category. */ public function testProductIsSavedOnlyWithPrincipalCategory() { $category = $this->categoryRepository->findOneBy(['slug' => 'category']); /** * @var ProductInterface $product */ $product = $this->getNewProduct(); $product->setPrincipalCategory($category); $product->setSlug('new-product-2'); $product->setName('New product 2'); $this->productDirector->save($product); $product = $this->productDirector->findOneBy(['slug' => 'new-product-2']); $this->assertEquals(1, $product->getCategories()->count(), 'The product is expected to have one category'); $this->assertEquals($category, $product->getCategories()->first(), 'The returned category should be the principal category'); }
/** * Checks if a valid authorization exists for a given user * * @param UserResponseInterface $response Response of the ResourceOwner * * @return Authorization|null */ protected function findAuthorization(UserResponseInterface $response) { $resourceOwnerName = $response->getResourceOwner()->getName(); $username = $response->getUsername(); return $this->authorizationDirector->findOneBy(['resourceOwnerName' => $resourceOwnerName, 'username' => $username]); }