/** * Get comment votes * * @param CommentInterface $comment Comment * * @return VotePackage Vote package */ public function getCommentVotes(CommentInterface $comment) { /** * @var VoteInterface[] $votes */ $votes = $this->commentVoteObjectDirector->findBy(['comment' => $comment]); return VotePackage::create($votes); }
/** * Removes a Coupon from a Cart, and recalculates Cart Totals. * * @param CartInterface $cart Cart * @param CouponInterface $coupon The coupon to remove * * @return bool Coupon has been removed from cart */ public function removeCoupon(CartInterface $cart, CouponInterface $coupon) { $cartCoupons = $this->cartCouponDirector->findBy(['cart' => $cart, 'coupon' => $coupon]); if (empty($cartCoupons)) { return false; } foreach ($cartCoupons as $cartCoupon) { $this->cartCouponEventDispatcher->dispatchCartCouponOnRemoveEvent($cartCoupon); } return true; }
/** * Test add coupon by code * * @covers removeCouponByCode * @covers removeCoupon */ public function testRemoveExistingCouponByCodeExistingCartCoupons() { $cart = $this->prophesize('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartInterface'); $coupon = $this->prophesize('Elcodi\\Component\\Coupon\\Entity\\Interfaces\\CouponInterface'); $cartCoupon1 = $this->prophesize('Elcodi\\Component\\CartCoupon\\Entity\\Interfaces\\CartCouponInterface'); $cartCoupon2 = $this->prophesize('Elcodi\\Component\\CartCoupon\\Entity\\Interfaces\\CartCouponInterface'); $cartCoupons = [$cartCoupon1->reveal(), $cartCoupon2->reveal()]; $this->cartCouponEventDispatcher->dispatchCartCouponOnRemoveEvent(Argument::any(), Argument::any())->shouldBeCalledTimes(2); $this->couponRepository->findOneBy(Argument::any())->willReturn($coupon->reveal())->shouldBeCalled(); $this->cartCouponDirector->findBy(Argument::any())->willReturn($cartCoupons)->shouldBeCalled(); $cartCouponManager = $this->createCartCouponManagerInstance(); $result = $cartCouponManager->removeCouponByCode($cart->reveal(), 1); $this->assertTrue($result); }