public function testCreate() { $cartItem = $this->dummyData->getCartItem(); $coupon = $this->dummyData->getCoupon(); $shipmentRate = $this->dummyData->getShipmentRate(); $orderAddress = $this->dummyData->getOrderAddress(); $taxRate = $this->dummyData->getTaxRate(); $cart = new Cart(); $cart->setSessionId('6is7ujb3crb5ja85gf91g9en62'); $cart->setIp4('10.0.0.1'); $cart->addCartItem($cartItem); $cart->addCoupon($coupon); $cart->setShipmentRate($shipmentRate); $cart->setShippingAddress($orderAddress); $cart->setTaxRate($taxRate); $this->assertEntityValid($cart); $this->assertTrue($cart instanceof Cart); $this->assertSame('10.0.0.1', $cart->getIp4()); $this->assertSame('6is7ujb3crb5ja85gf91g9en62', $cart->getSessionId()); $this->assertSame($cartItem, $cart->getCartItems()[0]); $this->assertSame($coupon, $cart->getCoupons()[0]); $this->assertSame($shipmentRate, $cart->getShipmentRate()); $this->assertSame($orderAddress, $cart->getShippingAddress()); $this->assertSame($taxRate, $cart->getTaxRate()); }
/** * @param CartItem[] $cartItems * @return Cart */ public function getCart(array $cartItems = []) { $cart = new Cart(); $cart->setIp4('10.0.0.1'); $cart->setShippingAddress($this->getOrderAddress()); foreach ($cartItems as $cartItem) { $cart->addCartItem($cartItem); } return $cart; }
/** * @param UuidInterface $cartId * @param string $ip4 * @param UuidInterface|null $userId * @param string|null $sessionId * @return Cart * @throws InvalidArgumentException */ public function create(UuidInterface $cartId, $ip4, UuidInterface $userId = null, $sessionId = null) { if (empty($userId) && empty($sessionId)) { throw new InvalidArgumentException('User or session id required.'); } $cart = new Cart($cartId); $cart->setIp4($ip4); $cart->setSessionId($sessionId); $cart->setUpdated(); $this->addUserToCartIfExists($cart, $userId); $this->cartRepository->create($cart); return $cart; }