Skip to content

Commit 9c9ca87

Browse files
ACQE-8324: Using rest api update guest cart of configurable product
- Fixed documentation issues
1 parent 2611ffe commit 9c9ca87

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@
1010

1111
use Magento\Catalog\Api\Data\ProductInterface;
1212
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
13+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1314
use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture;
1415
use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture;
1516
use Magento\Framework\Exception\NoSuchEntityException;
1617
use Magento\Framework\Webapi\Rest\Request;
1718
use Magento\Integration\Api\AdminTokenServiceInterface;
18-
use Magento\Integration\Model\AdminTokenService;
1919
use Magento\Integration\Model\Oauth\Token as TokenModel;
2020
use Magento\TestFramework\Fixture\DataFixture;
2121
use Magento\TestFramework\Fixture\DataFixtureStorage;
2222
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
2323
use Magento\TestFramework\Helper\Bootstrap;
2424
use Magento\TestFramework\TestCase\WebapiAbstract;
25-
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
26-
use Magento\User\Model\User;
2725
use Magento\User\Model\User as UserModel;
2826

2927
/**
@@ -42,21 +40,6 @@ class GuestCartConfigurableItemRepositoryTest extends WebapiAbstract
4240

4341
private const SERVICE_VERSION_GUEST_CART_ITEM = 'V1';
4442

45-
/**
46-
* @var AdminTokenServiceInterface
47-
*/
48-
private $tokenService;
49-
50-
/**
51-
* @var TokenModel
52-
*/
53-
private $tokenModel;
54-
55-
/**
56-
* @var UserModel
57-
*/
58-
private $userModel;
59-
6043
/**
6144
* @var array
6245
*/
@@ -73,9 +56,6 @@ class GuestCartConfigurableItemRepositoryTest extends WebapiAbstract
7356
protected function setUp(): void
7457
{
7558
parent::setUp();
76-
$this->tokenService = Bootstrap::getObjectManager()->get(AdminTokenService::class);
77-
$this->tokenModel = Bootstrap::getObjectManager()->get(TokenModel::class);
78-
$this->userModel = Bootstrap::getObjectManager()->get(User::class);
7959
$this->fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
8060
}
8161

@@ -106,6 +86,8 @@ public function testGuestCartUpdateConfigurableItem()
10686
}
10787

10888
/**
89+
* Create a guest cart and return its ID.
90+
*
10991
* @return string
11092
*/
11193
private function createGuestCart(): string
@@ -129,8 +111,11 @@ private function createGuestCart(): string
129111
}
130112

131113
/**
114+
* Add a configurable product to the guest cart.
115+
*
132116
* @param string $guestCartId
133117
* @return array
118+
* @throws NoSuchEntityException
134119
*/
135120
private function addConfigurableProductToCart(string $guestCartId): array
136121
{
@@ -159,6 +144,8 @@ private function addConfigurableProductToCart(string $guestCartId): array
159144
}
160145

161146
/**
147+
* Verify that the cart contains the expected items.
148+
*
162149
* @param string $guestCartId
163150
* @param int $expectedItemId
164151
* @return void
@@ -189,9 +176,12 @@ private function verifyCartItems(string $guestCartId, int $expectedItemId): void
189176
}
190177

191178
/**
179+
* Update a configurable product in the guest cart.
180+
*
192181
* @param string $guestCartId
193182
* @param int $itemId
194183
* @return void
184+
* @throws NoSuchEntityException
195185
*/
196186
private function updateConfigurableProductInCart(string $guestCartId, int $itemId): void
197187
{
@@ -233,16 +223,18 @@ private function getConfigurableProduct(): ProductInterface
233223
}
234224

235225
/**
236-
* @param $configurableProduct
237-
* @param $selectedOption
226+
* Get configurable option data for a configurable product.
227+
*
228+
* @param ProductInterface $configurableProduct
238229
* @return array
239230
*/
240-
private function getConfigurableOptionData($configurableProduct, $selectedOption = null): array
231+
private function getConfigurableOptionData(ProductInterface $configurableProduct): array
241232
{
233+
$selectedOption = null;
242234
$configOptions = $configurableProduct->getExtensionAttributes()->getConfigurableProductOptions();
243235

244236
$options = $configOptions[0]->getOptions();
245-
$optionKey = (isset($selectedOption) && isset($options[$selectedOption])) ? $selectedOption : 0;
237+
$optionKey = (isset($selectedOption) && isset($options[null])) ? null : 0;
246238

247239
return [
248240
'attribute_id' => $configOptions[0]->getAttributeId(),
@@ -251,6 +243,8 @@ private function getConfigurableOptionData($configurableProduct, $selectedOption
251243
}
252244

253245
/**
246+
* Build the request data for adding or updating a cart item.
247+
*
254248
* @param string $cartId
255249
* @param string $sku
256250
* @param string $attributeId
@@ -279,6 +273,8 @@ private function buildCartItemRequestData(string $cartId, string $sku, string $a
279273
}
280274

281275
/**
276+
* Get the service information for the cart operations.
277+
*
282278
* @param string $cartId
283279
* @param string $action
284280
* @param int|null $itemId

0 commit comments

Comments
 (0)