|
15 | 15 | use Commercetools\Core\Model\Product\ProductDraft; |
16 | 16 | use Commercetools\Core\Model\Product\ProductProjection; |
17 | 17 | use Commercetools\Core\Model\Product\ProductVariantDraft; |
| 18 | +use Commercetools\Core\Model\Product\ProductVariantDraftCollection; |
18 | 19 | use Commercetools\Core\Request\Products\ProductByIdGetRequest; |
19 | 20 | use Commercetools\Core\Request\Products\ProductByKeyGetRequest; |
20 | 21 | use Commercetools\Core\Request\Products\ProductCreateRequest; |
@@ -60,7 +61,8 @@ public function testQuery() |
60 | 61 | $draft = $this->getDraft(); |
61 | 62 | $product = $this->createProduct($draft); |
62 | 63 |
|
63 | | - $request = ProductQueryRequest::of()->where('masterData(current(name(en="' . $draft->getName()->en . '")))'); |
| 64 | + $request = ProductQueryRequest::of()->where('masterData(current(name(en=:name)))', ['name' => $draft->getName()->en]); |
| 65 | + |
64 | 66 | $response = $request->executeWithClient($this->getClient()); |
65 | 67 | $result = $request->mapResponse($response); |
66 | 68 |
|
@@ -125,7 +127,7 @@ public function testPriceSelectProductQuery() |
125 | 127 | $this->createProduct($draft); |
126 | 128 |
|
127 | 129 | $request = ProductQueryRequest::of() |
128 | | - ->where('masterData(current(name(en="' . $draft->getName()->en . '")))') |
| 130 | + ->where('masterData(current(name(en=:name)))', ['name' => $draft->getName()->en]) |
129 | 131 | ->currency('EUR') |
130 | 132 | ; |
131 | 133 | $response = $request->executeWithClient($this->getClient()); |
@@ -197,6 +199,33 @@ public function testPriceSelectProductProjectionQuery() |
197 | 199 | $this->assertSame(100, $result->current()->getMasterVariant()->getPrice()->getValue()->getCentAmount()); |
198 | 200 | } |
199 | 201 |
|
| 202 | + public function testSkuParametrized() |
| 203 | + { |
| 204 | + $draft = $this->getDraft(); |
| 205 | + $sku1 = 'sku1' . uniqid(); |
| 206 | + $sku2 = 'sku2' . uniqid(); |
| 207 | + $draft->setMasterVariant(ProductVariantDraft::of()->setSku($sku1)); |
| 208 | + $draft->setVariants(ProductVariantDraftCollection::of()->add(ProductVariantDraft::of()->setSku($sku2))); |
| 209 | + $this->createProduct($draft); |
| 210 | + |
| 211 | + $request = ProductProjectionQueryRequest::of() |
| 212 | + ->where( |
| 213 | + 'masterVariant(sku in (:skus1, :skus2)) or variants(sku in (:skus1, :skus2))', |
| 214 | + [ |
| 215 | + 'skus1' => 'whatever', |
| 216 | + 'skus2' => $sku2 |
| 217 | + ] |
| 218 | + ) |
| 219 | + ->staged(true) |
| 220 | + ; |
| 221 | + $response = $request->executeWithClient($this->getClient()); |
| 222 | + $result = $request->mapResponse($response); |
| 223 | + $this->assertCount(1, $result); |
| 224 | + $this->assertInstanceOf(ProductProjection::class, $result->getAt(0)); |
| 225 | + $this->assertSame($sku1, $result->current()->getMasterVariant()->getSku()); |
| 226 | + $this->assertSame($sku2, $result->current()->getVariants()->current()->getSku()); |
| 227 | + } |
| 228 | + |
200 | 229 | public function testPriceSelectProductProjectionById() |
201 | 230 | { |
202 | 231 | $draft = $this->getDraft(); |
|
0 commit comments