diff --git a/app/code/Magento/Quote/Model/Webapi/SaveCartItemWithCartId.php b/app/code/Magento/Quote/Model/Webapi/SaveCartItemWithCartId.php
new file mode 100644
index 0000000000000..e19723ea56eb2
--- /dev/null
+++ b/app/code/Magento/Quote/Model/Webapi/SaveCartItemWithCartId.php
@@ -0,0 +1,41 @@
+cartItemRepository = $cartItemRepository;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function saveForCart($cartId, CartItemInterface $cartItem)
+ {
+ $cartItem->setQuoteId($cartId);
+
+ return $this->cartItemRepository->save($cartItem);
+ }
+}
diff --git a/app/code/Magento/Quote/Model/Webapi/SaveCartItemWithCartIdInterface.php b/app/code/Magento/Quote/Model/Webapi/SaveCartItemWithCartIdInterface.php
new file mode 100644
index 0000000000000..c5b1e0732d70f
--- /dev/null
+++ b/app/code/Magento/Quote/Model/Webapi/SaveCartItemWithCartIdInterface.php
@@ -0,0 +1,24 @@
+guestCartItemRepo = $guestCartItemRepo;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function saveForCart($cartId, CartItemInterface $cartItem)
+ {
+ $cartItem->setQuoteId($cartId);
+
+ return $this->guestCartItemRepo->save($cartItem);
+ }
+}
diff --git a/app/code/Magento/Quote/Model/Webapi/SaveGuestCartItemWithCartIdInterface.php b/app/code/Magento/Quote/Model/Webapi/SaveGuestCartItemWithCartIdInterface.php
new file mode 100644
index 0000000000000..286810da13661
--- /dev/null
+++ b/app/code/Magento/Quote/Model/Webapi/SaveGuestCartItemWithCartIdInterface.php
@@ -0,0 +1,24 @@
+cartItemRepository = $this->getMockBuilder(CartItemRepositoryInterface::class)
+ ->getMockForAbstractClass();
+
+ $this->model = (new ObjectManager($this))->getObject(
+ SaveCartItemWithCartId::class,
+ [
+ 'cartItemRepository' => $this->cartItemRepository
+ ]
+ );
+ }
+
+ public function testQuoteIdIsCorrectlySet()
+ {
+ $cartId = 44;
+
+ /** @var CartItemInterface $cartItem */
+ $cartItem = $this->getMockBuilder(CartItemInterface::class)->getMockForAbstractClass();
+ $cartItem->expects($this->once())
+ ->method('setQuoteId')
+ ->with($cartId)
+ ->willReturnSelf();
+
+ $this->model->saveForCart($cartId, $cartItem);
+ }
+
+ public function testQuoteItemIsCorrectlySaved()
+ {
+ $cartId = 44;
+
+ /** @var CartItemInterface $cartItem */
+ $cartItem = $this->getMockBuilder(CartItemInterface::class)->getMockForAbstractClass();
+ $cartItem->expects($this->once())
+ ->method('setQuoteId')
+ ->with($cartId)
+ ->willReturnSelf();
+
+ $this->cartItemRepository->expects($this->once())
+ ->method('save')
+ ->with($cartItem)
+ ->willReturn($cartItem);
+
+ $this->model->saveForCart($cartId, $cartItem);
+ }
+}
diff --git a/app/code/Magento/Quote/Test/Unit/Model/Webapi/SaveGuestCartItemWithCartIdTest.php b/app/code/Magento/Quote/Test/Unit/Model/Webapi/SaveGuestCartItemWithCartIdTest.php
new file mode 100644
index 0000000000000..6c4d7032cb146
--- /dev/null
+++ b/app/code/Magento/Quote/Test/Unit/Model/Webapi/SaveGuestCartItemWithCartIdTest.php
@@ -0,0 +1,74 @@
+guestCartItemRepo = $this->getMockBuilder(GuestCartItemRepositoryInterface::class)
+ ->getMockForAbstractClass();
+
+ $this->model = (new ObjectManager($this))->getObject(
+ SaveGuestCartItemWithCartId::class,
+ [
+ 'guestCartItemRepo' => $this->guestCartItemRepo
+ ]
+ );
+ }
+
+ public function testQuoteIdIsCorrectlySet()
+ {
+ $cartId = '298047a8923470823';
+
+ /** @var CartItemInterface $cartItem */
+ $cartItem = $this->getMockBuilder(CartItemInterface::class)->getMockForAbstractClass();
+ $cartItem->expects($this->once())
+ ->method('setQuoteId')
+ ->with($cartId)
+ ->willReturnSelf();
+
+ $this->model->saveForCart($cartId, $cartItem);
+ }
+
+ public function testQuoteItemIsCorrectlySaved()
+ {
+ $cartId = '298047a8923470823';
+
+ /** @var CartItemInterface $cartItem */
+ $cartItem = $this->getMockBuilder(CartItemInterface::class)->getMockForAbstractClass();
+ $cartItem->expects($this->once())
+ ->method('setQuoteId')
+ ->with($cartId)
+ ->willReturnSelf();
+
+ $this->guestCartItemRepo->expects($this->once())
+ ->method('save')
+ ->with($cartItem)
+ ->willReturn($cartItem);
+
+ $this->model->saveForCart($cartId, $cartItem);
+ }
+}
diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml
index 674e0eea46e97..60a1ecb954573 100644
--- a/app/code/Magento/Quote/etc/di.xml
+++ b/app/code/Magento/Quote/etc/di.xml
@@ -15,6 +15,7 @@
+
@@ -30,6 +31,7 @@
+
diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml
index 686bdce07de5f..d376eab36e5e5 100644
--- a/app/code/Magento/Quote/etc/webapi.xml
+++ b/app/code/Magento/Quote/etc/webapi.xml
@@ -176,14 +176,14 @@
-
-
+
+
-
+
@@ -203,13 +203,13 @@
-
+
-
+
@@ -232,7 +232,7 @@
-
+
@@ -241,7 +241,7 @@
-
+