|
23 | 23 | */
|
24 | 24 | class ConfigurableVariantsTest extends StorefrontTestsAbstract
|
25 | 25 | {
|
| 26 | + /** |
| 27 | + * Simple product skus from Magento/ConfigurableProduct/_files/configurable_product_nine_simples.php |
| 28 | + */ |
| 29 | + private const SIMPLE_SKUS = [ |
| 30 | + 'simple_0', |
| 31 | + 'simple_1', |
| 32 | + 'simple_2', |
| 33 | + 'simple_3', |
| 34 | + 'simple_4', |
| 35 | + 'simple_5', |
| 36 | + 'simple_6', |
| 37 | + 'simple_7', |
| 38 | + 'simple_8' |
| 39 | + ]; |
| 40 | + |
26 | 41 | /**
|
27 | 42 | * @var VariantService
|
28 | 43 | */
|
@@ -78,21 +93,10 @@ public function testConfigurableProductVariants(): void
|
78 | 93 | //This sleep ensures that the elastic index has sufficient time to refresh
|
79 | 94 | //See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html#docs-refresh
|
80 | 95 | sleep(1);
|
81 |
| - $simpleSkus = [ |
82 |
| - 'simple_0', |
83 |
| - 'simple_1', |
84 |
| - 'simple_2', |
85 |
| - 'simple_3', |
86 |
| - 'simple_4', |
87 |
| - 'simple_5', |
88 |
| - 'simple_6', |
89 |
| - 'simple_7', |
90 |
| - 'simple_8' |
91 |
| - ]; |
92 | 96 | /** @var $configurable Product */
|
93 | 97 | $configurable = $this->productRepository->get('configurable');
|
94 | 98 | $simples = [];
|
95 |
| - foreach ($simpleSkus as $sku) { |
| 99 | + foreach (self::SIMPLE_SKUS as $sku) { |
96 | 100 | $simples[] = $this->productRepository->get($sku);
|
97 | 101 | }
|
98 | 102 |
|
@@ -132,33 +136,22 @@ public function testProductVariantsDisabledProduct(): void
|
132 | 136 | }
|
133 | 137 |
|
134 | 138 | /**
|
135 |
| - * Validate matching of variants by option values |
| 139 | + * Validate matching of variants by option values using getVariantsMatch |
136 | 140 | *
|
137 | 141 | * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_nine_simples.php
|
138 | 142 | * @magentoDbIsolation disabled
|
139 | 143 | * @throws NoSuchEntityException
|
140 | 144 | * @throws \Throwable
|
141 | 145 | */
|
142 |
| - public function testVariantsMatch(): void |
| 146 | + public function testGetVariantsMatch(): void |
143 | 147 | {
|
144 | 148 | //This sleep ensures that the elastic index has sufficient time to refresh
|
145 | 149 | //See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html#docs-refresh
|
146 | 150 | sleep(1);
|
147 |
| - $simpleSkus = [ |
148 |
| - 'simple_0', |
149 |
| - 'simple_1', |
150 |
| - 'simple_2', |
151 |
| - 'simple_3', |
152 |
| - 'simple_4', |
153 |
| - 'simple_5', |
154 |
| - 'simple_6', |
155 |
| - 'simple_7', |
156 |
| - 'simple_8' |
157 |
| - ]; |
158 | 151 | /** @var $configurable Product */
|
159 | 152 | $configurable = $this->productRepository->get('configurable');
|
160 | 153 | $simples = [];
|
161 |
| - foreach ($simpleSkus as $sku) { |
| 154 | + foreach (self::SIMPLE_SKUS as $sku) { |
162 | 155 | $simples[] = $this->productRepository->get($sku);
|
163 | 156 | }
|
164 | 157 | $availableVariants = $this->getExpectedProductVariants($configurable, $simples);
|
@@ -187,6 +180,90 @@ public function testVariantsMatch(): void
|
187 | 180 | $this->compare($expected, $actual);
|
188 | 181 | }
|
189 | 182 |
|
| 183 | + /** |
| 184 | + * Validate matching of variants by option values using getVariantsExactlyMatch |
| 185 | + * |
| 186 | + * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_nine_simples.php |
| 187 | + * @magentoDbIsolation disabled |
| 188 | + * @throws NoSuchEntityException |
| 189 | + * @throws \Throwable |
| 190 | + */ |
| 191 | + public function testGetVariantsExactlyMatch(): void |
| 192 | + { |
| 193 | + //This sleep ensures that the elastic index has sufficient time to refresh |
| 194 | + //See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html#docs-refresh |
| 195 | + sleep(1); |
| 196 | + /** @var $configurable Product */ |
| 197 | + $configurable = $this->productRepository->get('configurable'); |
| 198 | + $simples = []; |
| 199 | + foreach (self::SIMPLE_SKUS as $sku) { |
| 200 | + $simples[] = $this->productRepository->get($sku); |
| 201 | + } |
| 202 | + $availableVariants = $this->getExpectedProductVariants($configurable, $simples); |
| 203 | + |
| 204 | + // Use exact match using two option values. Expect 1 simple product. |
| 205 | + $optionValues = $availableVariants[0]['option_values']; |
| 206 | + $this->optionSelectionRequestInterface->setStore('default'); |
| 207 | + $this->optionSelectionRequestInterface->setValues($optionValues); |
| 208 | + /** @var $variantServiceItem ProductVariantResponse */ |
| 209 | + $variantServiceItem = $this->variantService->getVariantsExactlyMatch($this->optionSelectionRequestInterface); |
| 210 | + $actual = $this->responseArrayMapper->convertToArray($variantServiceItem)['matched_variants']; |
| 211 | + $expected = [$availableVariants[0]]; |
| 212 | + self::assertCount(1, $actual); |
| 213 | + $this->compare($expected, $actual); |
| 214 | + |
| 215 | + // Use exact match using one option value. Expect 0 simple products. |
| 216 | + $optionValues = [$availableVariants[0]['option_values'][0]]; |
| 217 | + $this->optionSelectionRequestInterface->setValues($optionValues); |
| 218 | + /** @var $variantServiceItem ProductVariantResponse */ |
| 219 | + $variantServiceItem = $this->variantService->getVariantsExactlyMatch($this->optionSelectionRequestInterface); |
| 220 | + $actual = $this->responseArrayMapper->convertToArray($variantServiceItem)['matched_variants']; |
| 221 | + self::assertEmpty($actual); |
| 222 | + } |
| 223 | + |
| 224 | + /** |
| 225 | + * Validate matching of variants by option values using getVariantsInclude |
| 226 | + * |
| 227 | + * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_nine_simples.php |
| 228 | + * @magentoDbIsolation disabled |
| 229 | + * @throws NoSuchEntityException |
| 230 | + * @throws \Throwable |
| 231 | + */ |
| 232 | + public function testGetVariantsInclude(): void |
| 233 | + { |
| 234 | + //This sleep ensures that the elastic index has sufficient time to refresh |
| 235 | + //See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html#docs-refresh |
| 236 | + sleep(1); |
| 237 | + /** @var $configurable Product */ |
| 238 | + $configurable = $this->productRepository->get('configurable'); |
| 239 | + $simples = []; |
| 240 | + foreach (self::SIMPLE_SKUS as $sku) { |
| 241 | + $simples[] = $this->productRepository->get($sku); |
| 242 | + } |
| 243 | + $availableVariants = $this->getExpectedProductVariants($configurable, $simples); |
| 244 | + |
| 245 | + // Use include match using two option values. Expect 6 simple products. |
| 246 | + $optionValues = [ |
| 247 | + $availableVariants[0]['option_values'][0], |
| 248 | + $availableVariants[1]['option_values'][0] |
| 249 | + ]; |
| 250 | + $this->optionSelectionRequestInterface->setStore('default'); |
| 251 | + $this->optionSelectionRequestInterface->setValues($optionValues); |
| 252 | + /** @var $variantServiceItem ProductVariantResponse */ |
| 253 | + $variantServiceItem = $this->variantService->getVariantsInclude($this->optionSelectionRequestInterface); |
| 254 | + $actual = $this->responseArrayMapper->convertToArray($variantServiceItem)['matched_variants']; |
| 255 | + $expected = \array_values(\array_filter($availableVariants, function ($variant) use ($optionValues) { |
| 256 | + foreach ($optionValues as $optionValue) { |
| 257 | + if (\in_array($optionValue, $variant['option_values'])) { |
| 258 | + return true; |
| 259 | + } |
| 260 | + } |
| 261 | + return false; |
| 262 | + })); |
| 263 | + self::assertCount(6, $actual); |
| 264 | + $this->compare($expected, $actual); |
| 265 | + } |
| 266 | + |
190 | 267 | /**
|
191 | 268 | * Get the expected variants for configurable products.
|
192 | 269 | *
|
|
0 commit comments