|
9 | 9 | use Commercetools\Core\Model\CustomField\CustomFieldObject; |
10 | 10 | use Commercetools\Core\Model\Inventory\InventoryDraft; |
11 | 11 | use Commercetools\Core\Model\Message\InventoryEntryDeletedMessage; |
| 12 | +use Commercetools\Core\Model\Product\ProductProjection; |
| 13 | +use Commercetools\Core\Model\Product\Search\Filter; |
12 | 14 | use Commercetools\Core\Model\Type\TypeReference; |
13 | 15 | use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction; |
14 | 16 | use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction; |
|
22 | 24 | use Commercetools\Core\Request\Inventory\InventoryDeleteRequest; |
23 | 25 | use Commercetools\Core\Request\Inventory\InventoryUpdateRequest; |
24 | 26 | use Commercetools\Core\Request\Messages\MessageQueryRequest; |
| 27 | +use Commercetools\Core\Request\Products\ProductProjectionSearchRequest; |
25 | 28 |
|
26 | 29 | class InventoryUpdateRequestTest extends ApiTestCase |
27 | 30 | { |
@@ -180,6 +183,45 @@ public function testSetSupplyChannel() |
180 | 183 | $this->deleteRequest->setVersion($result->getVersion()); |
181 | 184 | } |
182 | 185 |
|
| 186 | + public function testQueryChannels() |
| 187 | + { |
| 188 | + $channel = $this->getChannel(); |
| 189 | + $draft = $this->getDraft('sku'); |
| 190 | + $draft = $draft->setQuantityOnStock(1); |
| 191 | + $draft->setSupplyChannel($channel->getReference()); |
| 192 | + $this->createInventory($draft); |
| 193 | + |
| 194 | + $product = $this->getProduct(); |
| 195 | + |
| 196 | + $retries = 0; |
| 197 | + do { |
| 198 | + $retries++; |
| 199 | + sleep(1); |
| 200 | + $request = ProductProjectionSearchRequest::of() |
| 201 | + ->addFilterQuery(Filter::ofName('id')->setValue($product->getId())) |
| 202 | + ->limit(1); |
| 203 | + $response = $request->executeWithClient($this->getClient()); |
| 204 | + $result = $request->mapResponse($response); |
| 205 | + } while ($result->count() > 0 && $retries <= 9); |
| 206 | + |
| 207 | + $request = ProductProjectionSearchRequest::of() |
| 208 | + ->addFilterQuery( |
| 209 | + Filter::ofName('variants.availability.isOnStockInChannels')->setValue([$channel->getId()]) |
| 210 | + ) |
| 211 | + ->limit(1); |
| 212 | + $response = $request->executeWithClient($this->getClient()); |
| 213 | + $result = $request->mapResponse($response); |
| 214 | + |
| 215 | + $this->assertSame( |
| 216 | + $product->getId(), |
| 217 | + $result->current()->getId() |
| 218 | + ); |
| 219 | + $this->assertSame( |
| 220 | + $channel->getId(), |
| 221 | + $result->current()->getMasterVariant()->getAvailability()->getChannels()->key() |
| 222 | + ); |
| 223 | + } |
| 224 | + |
183 | 225 | /** |
184 | 226 | * @large |
185 | 227 | */ |
|
0 commit comments