/** * Add comment into source * * @param string $source Source * @param string $context Context * @param string $content Content * @param string $authorToken Author token * @param string $authorName Author name * @param string $authorEmail Author email * @param CommentInterface|null $parent Parent * * @return CommentInterface Commend added */ public function addComment($source, $context, $content, $authorToken, $authorName, $authorEmail, CommentInterface $parent = null) { $comment = $this->commentDirector->create()->setId(round(microtime(true) * 1000))->setParent($parent)->setSource($source)->setAuthorToken($authorToken)->setAuthorName($authorName)->setAuthorEmail($authorEmail)->setContent($content)->setContext($context); $this->commentDirector->save($comment); $this->commentEventDispatcher->dispatchCommentOnAddEvent($comment); return $comment; }
/** * Test create and save * * @covers createAndSaveCartCoupon */ public function testCreateAndSaveCartCoupon() { $cart = $this->prophesize('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartInterface'); $coupon = $this->prophesize('Elcodi\\Component\\Coupon\\Entity\\Interfaces\\CouponInterface'); $cartCoupon = $this->prophesize('Elcodi\\Component\\CartCoupon\\Entity\\Interfaces\\CartCouponInterface')->reveal(); $this->cartCouponDirector->create(Argument::any())->willReturn($cartCoupon)->shouldBeCalled(); $this->cartCouponDirector->save($cartCoupon)->shouldBeCalled(); $cartCouponManager = $this->createCartCouponManagerInstance(); $cartCouponManager->createAndSaveCartCoupon($cart->reveal(), $coupon->reveal()); }
/** * Vote action * * @param CommentInterface $comment Comment * @param string $authorToken Author token * @param boolean $type Vote type * * @return VoteInterface Vote */ public function vote(CommentInterface $comment, $authorToken, $type) { /** * @var VoteInterface $vote */ $vote = $this->commentVoteObjectDirector->findOneBy(['authorToken' => $authorToken, 'comment' => $comment]); $edited = true; if (!$vote instanceof VoteInterface) { $vote = $this->commentVoteObjectDirector->create()->setAuthorToken($authorToken)->setComment($comment); $edited = false; } $vote->setType($type); $this->commentVoteObjectDirector->save($vote); $this->commentEventDispatcher->dispatchCommentOnVotedEvent($comment, $vote, $edited); return $vote; }
/** * Test that creating a new root category the parent category should be null. */ public function testNewRootCategoryIsSavedWithoutParent() { /** * @var $rootCategory CategoryInterface */ $rootCategory = $this->categoryDirector->findOneBy(['slug' => 'root-category']); $category = $this->categoryDirector->create(); $category->setRoot(true); $category->setParent($rootCategory); $category->setName('New root category'); $category->setSlug('new-root-category'); $this->categoryDirector->save($category); /** * @var $category CategoryInterface */ $category = $this->categoryDirector->findOneBy(['slug' => 'new-root-category']); $this->assertNull($category->getParent(), 'The parent for a root category should always be null'); }
/** * Create a new user from a response * * @param UserResponseInterface $response * * @return UserInterface */ protected function createUser(UserResponseInterface $response) { /** * @var CustomerInterface $customer */ $customer = $this->customerDirector->create(); $customer->setEmail($response->getEmail())->setFirstname($response->getRealName()); $this->customerDirector->save($customer); $this->userEventDispatcher->dispatchOnCustomerRegisteredEvent($customer); return $customer; }
/** * Create a cart coupon given a cart and a coupon. * * @param CartInterface $cart Cart * @param CouponInterface $coupon Coupon * * @return CartCouponInterface Cart Coupon created */ public function createAndSaveCartCoupon(CartInterface $cart, CouponInterface $coupon) { /** * We create a new instance of CartCoupon. * We also persist and flush relation. */ $cartCoupon = $this->cartCouponDirector->create(); $cartCoupon->setCart($cart); $cartCoupon->setCoupon($coupon); $this->cartCouponDirector->save($cartCoupon); return $cartCoupon; }
/** * 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; }
/** * Gets a new product entity. * * @return ProductInterface */ public function getNewProduct() { return $this->productDirector->create(); }