|
8 | 8 | use Magento\Catalog\Api\Data\ProductInterface;
|
9 | 9 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
10 | 10 | use Magento\Catalog\Model\Product;
|
| 11 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
11 | 12 | use Magento\CatalogInventory\Api\Data\StockItemInterface;
|
12 | 13 | use Magento\CatalogInventory\Api\StockConfigurationInterface;
|
13 | 14 | use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
|
| 15 | +use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture; |
| 16 | +use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture; |
14 | 17 | use Magento\Framework\App\Filesystem\DirectoryList;
|
15 | 18 | use Magento\Framework\EntityManager\EntityMetadata;
|
16 | 19 | use Magento\Framework\EntityManager\MetadataPool;
|
|
20 | 23 | use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
|
21 | 24 | use Magento\ImportExport\Model\Import\Adapter as ImportAdapter;
|
22 | 25 | use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory;
|
| 26 | +use Magento\ImportExport\Test\Fixture\CsvFile as CsvFileFixture; |
23 | 27 | use Magento\Store\Model\Store;
|
| 28 | +use Magento\TestFramework\Fixture\DataFixture; |
| 29 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
24 | 30 | use Magento\TestFramework\Helper\Bootstrap;
|
25 | 31 | use PHPUnit\Framework\TestCase;
|
26 | 32 |
|
@@ -252,6 +258,60 @@ private function getStockItem(int $productId): ?StockItemInterface
|
252 | 258 | return reset($stockItems);
|
253 | 259 | }
|
254 | 260 |
|
| 261 | + #[ |
| 262 | + DataFixture(ProductFixture::class, ['sku' => 'cp1-10,2cm'], as: 'p1'), |
| 263 | + DataFixture(ProductFixture::class, ['sku' => 'cp1-15,5cm'], as: 'p2'), |
| 264 | + DataFixture( |
| 265 | + AttributeFixture::class, |
| 266 | + [ |
| 267 | + 'attribute_code' => 'size', |
| 268 | + 'options' => [['label' => '10,2cm'], ['label' => '15,5cm']], |
| 269 | + ], |
| 270 | + as: 'attr' |
| 271 | + ), |
| 272 | + DataFixture( |
| 273 | + ConfigurableProductFixture::class, |
| 274 | + ['_options' => ['$attr$'], '_links' => ['$p1$', '$p2$']], |
| 275 | + 'cp1' |
| 276 | + ), |
| 277 | + DataFixture( |
| 278 | + CsvFileFixture::class, |
| 279 | + [ |
| 280 | + 'rows' => [ |
| 281 | + ['sku', 'configurable_variations'], |
| 282 | + ['$cp1.sku$', 'sku=cp1-10,2cm,size=10,2cm|sku=cp1-15,5cm,size=15,5cm'], |
| 283 | + ] |
| 284 | + ], |
| 285 | + 'file' |
| 286 | + ) |
| 287 | + ] |
| 288 | + public function testSpecialCharactersInConfigurableVariations(): void |
| 289 | + { |
| 290 | + $fixtures = DataFixtureStorageManager::getStorage(); |
| 291 | + $attrId = $fixtures->get('attr')->getId(); |
| 292 | + $sku = $fixtures->get('cp1')->getSku(); |
| 293 | + $p1Id = $fixtures->get('p1')->getId(); |
| 294 | + $p2Id = $fixtures->get('p2')->getId(); |
| 295 | + $pathToFile = $fixtures->get('file')->getAbsolutePath(); |
| 296 | + $errors = $this->doImport($pathToFile, Import::BEHAVIOR_APPEND); |
| 297 | + $this->assertEquals( |
| 298 | + 0, |
| 299 | + $errors->getErrorsCount(), |
| 300 | + implode(PHP_EOL, array_map(fn ($error) => $error->getErrorMessage(), $errors->getAllErrors())) |
| 301 | + ); |
| 302 | + /** @var ProductRepositoryInterface $productRepository */ |
| 303 | + $productRepository = $this->objectManager->get(ProductRepositoryInterface::class); |
| 304 | + /** @var ProductInterface $product */ |
| 305 | + $product = $productRepository->get($sku, forceReload: true); |
| 306 | + $options = $product->getExtensionAttributes()->getConfigurableProductOptions(); |
| 307 | + $this->assertCount(1, $options); |
| 308 | + $this->assertEquals($attrId, reset($options)->getAttributeId()); |
| 309 | + $childIds = $product->getExtensionAttributes()->getConfigurableProductLinks(); |
| 310 | + $this->assertCount(2, $childIds); |
| 311 | + $this->assertContains($p1Id, $childIds); |
| 312 | + $this->assertContains($p2Id, $childIds); |
| 313 | + } |
| 314 | + |
255 | 315 | /**
|
256 | 316 | * @param string $file
|
257 | 317 | * @param string $behavior
|
|
0 commit comments