Skip to content

Commit a22d447

Browse files
committed
AC-15054: Product Add to Cart issue in Rest API
1 parent 1df163e commit a22d447

File tree

3 files changed

+3
-98
lines changed

3 files changed

+3
-98
lines changed

app/code/Magento/Quote/Plugin/UpdateCartId.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public function beforeSave(
6363
/**
6464
* Validate product's website assignment for guest cart item
6565
*
66+
* @param CartItemInterface $cartItem
67+
* @return void
6668
* @throws LocalizedException
6769
*/
6870
private function validateProductWebsiteAssignment(CartItemInterface $cartItem): void

app/code/Magento/Quote/Test/Unit/Plugin/Webapi/ValidateProductWebsiteAssignmentTest.php

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -301,65 +301,6 @@ public function testBeforeSaveProductWebsiteIdsNotArray()
301301
$this->plugin->beforeSave($this->cartItemRepositoryMock, $this->cartItemMock);
302302
}
303303

304-
/**
305-
* Test validation when product is not found
306-
*/
307-
public function testBeforeSaveProductNotFound()
308-
{
309-
$sku = 'test-product';
310-
$quoteId = 1;
311-
$storeId = 1;
312-
$productId = 123;
313-
314-
$this->cartItemMock->expects($this->once())
315-
->method('getSku')
316-
->willReturn($sku);
317-
318-
$this->cartItemMock->expects($this->once())
319-
->method('getQuoteId')
320-
->willReturn($quoteId);
321-
322-
$this->cartRepositoryMock->expects($this->once())
323-
->method('getActive')
324-
->with($quoteId)
325-
->willReturn($this->quoteMock);
326-
327-
$this->quoteMock->expects($this->once())
328-
->method('getAllItems')
329-
->willReturn([$this->quoteItemMock]);
330-
331-
$this->quoteItemMock->expects($this->once())
332-
->method('getSku')
333-
->willReturn($sku);
334-
335-
$this->quoteItemMock->expects($this->once())
336-
->method('getStoreId')
337-
->willReturn($storeId);
338-
339-
$this->quoteItemMock->expects($this->once())
340-
->method('getProductId')
341-
->willReturn($productId);
342-
343-
$this->storeManagerMock->expects($this->once())
344-
->method('getStore')
345-
->with($storeId)
346-
->willReturn($this->storeMock);
347-
348-
$this->storeMock->expects($this->once())
349-
->method('getWebsiteId')
350-
->willReturn(1);
351-
352-
$this->productRepositoryMock->expects($this->once())
353-
->method('getById')
354-
->with($productId, false, $storeId)
355-
->willThrowException(new NoSuchEntityException(__('Product not found')));
356-
357-
$this->expectException(LocalizedException::class);
358-
$this->expectExceptionMessage('Product that you are trying to add is not available.');
359-
360-
$this->plugin->beforeSave($this->cartItemRepositoryMock, $this->cartItemMock);
361-
}
362-
363304
/**
364305
* Test validation skips when no SKU provided
365306
*/
@@ -590,42 +531,4 @@ public function testBeforeSaveWebsiteIdZero()
590531
// If we reach this point, validation passed
591532
$this->assertTrue(true);
592533
}
593-
594-
/**
595-
* Test validation when no matching quote item found for SKU
596-
*/
597-
public function testBeforeSaveNoMatchingQuoteItem()
598-
{
599-
$sku = 'test-product';
600-
$quoteId = 1;
601-
$differentSku = 'different-product';
602-
603-
$this->cartItemMock->expects($this->once())
604-
->method('getSku')
605-
->willReturn($sku);
606-
607-
$this->cartItemMock->expects($this->once())
608-
->method('getQuoteId')
609-
->willReturn($quoteId);
610-
611-
$this->cartRepositoryMock->expects($this->once())
612-
->method('getActive')
613-
->with($quoteId)
614-
->willReturn($this->quoteMock);
615-
616-
$this->quoteMock->expects($this->once())
617-
->method('getAllItems')
618-
->willReturn([$this->quoteItemMock]);
619-
620-
$this->quoteItemMock->expects($this->once())
621-
->method('getSku')
622-
->willReturn($differentSku); // Different SKU
623-
624-
// No further method calls expected since no matching item found
625-
// Method returns void, so we just verify no exception is thrown
626-
$this->plugin->beforeSave($this->cartItemRepositoryMock, $this->cartItemMock);
627-
628-
// If we reach this point, validation passed
629-
$this->assertTrue(true);
630-
}
631534
}

dev/tests/api-functional/testsuite/Magento/Quote/Api/ValidateProductWebsiteAssignmentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Quote\Test\Api;
8+
namespace Magento\Quote\Api;
99

1010
use Magento\Catalog\Test\Fixture\Product;
1111
use Magento\Customer\Test\Fixture\Customer;

0 commit comments

Comments
 (0)