/** * Set Cart in session * * @param CartInterface $cart Cart * * @return $this Self object */ public function set(CartInterface $cart) { if (!$this->saveInSession) { return $this; } $this->session->set($this->sessionFieldName, $cart->getId()); return $this; }
/** * Get cart coupon objects. * * @param CartInterface $cart Cart * * @return CouponInterface[] Coupons */ public function getCoupons(CartInterface $cart) { /** * If Cart id is null means that this cart has been generated from * scratch. This also means that it cannot have any Coupon associated. * If is this case, we avoid this lookup. */ if ($cart->getId() === null) { return []; } return $this->cartCouponRepository->findCouponsByCart($cart); }
/** * Common asserts for a test that empties lines. * * @param CartLineInterface $line The CartLineInterface needed */ private function assertRemovedLine(CartLineInterface $line) { $this->assertEmpty($this->cart->getCartLines()); $this->assertNotNull($this->cart->getId()); $this->assertEquals(UnitOfWork::STATE_NEW, $this->get('elcodi.object_manager.cart_line')->getUnitOfWork()->getEntityState($line)); }
/** * Get cart coupon objects * * @param CartInterface $cart Cart * * @return Collection Coupons */ public function getCoupons(CartInterface $cart) { /** * If Cart id is null means that this cart has been generated from * the scratch. This also means that cannot have any Coupon associated. * If is this case, we avoid this lookup. */ if ($cart->getId() == null) { return new ArrayCollection(); } $cartCoupons = $this->cartCouponRepository->createQueryBuilder('cc')->select(['c', 'cc'])->innerJoin('cc.coupon', 'c')->where('cc.cart = :cart')->setParameter('cart', $cart)->getQuery()->getResult(); $coupons = array_map(function (CartCouponInterface $cartCoupon) { return $cartCoupon->getCoupon(); }, $cartCoupons); return new ArrayCollection($coupons); }