|
5 | 5 | */
|
6 | 6 | declare(strict_types=1);
|
7 | 7 |
|
| 8 | +use Magento\Framework\Exception\NoSuchEntityException; |
8 | 9 | use Magento\TestFramework\Helper\Bootstrap;
|
9 | 10 | use Magento\Eav\Api\AttributeRepositoryInterface;
|
10 | 11 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
|
22 | 23 | $registry->register('isSecureArea', true);
|
23 | 24 |
|
24 | 25 | $eavConfig = $objectManager->get(EavConfig::class);
|
25 |
| -$attributesToDelete = ['dropdown_without_default']; |
| 26 | +$eavConfig->clear(); |
26 | 27 | /** @var AttributeRepositoryInterface $attributeRepository */
|
27 | 28 | $attributeRepository = $objectManager->get(AttributeRepositoryInterface::class);
|
28 |
| -/** @var AttributeInterface $attribute */ |
29 |
| -$attribute = $attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, 'dropdown_without_default'); |
30 |
| -$attributeRepository->delete($attribute); |
31 |
| -$eavConfig->clear(); |
32 |
| - |
33 | 29 | /** @var ProductRepositoryInterface $productRepository */
|
34 | 30 | $productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
35 |
| -/** @var ProductInterface $product */ |
36 |
| -$product = $productRepository->get('test_attribute_dropdown_without_default'); |
37 |
| -if ($product->getId()) { |
| 31 | +try { |
| 32 | + /** @var AttributeInterface $attribute */ |
| 33 | + $attribute = $attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, 'dropdown_without_default'); |
| 34 | + $attributeRepository->delete($attribute); |
| 35 | +} catch (NoSuchEntityException $e) { |
| 36 | +} |
| 37 | +try { |
| 38 | + /** @var ProductInterface $product */ |
| 39 | + $product = $productRepository->get('test_attribute_dropdown_without_default'); |
38 | 40 | $productRepository->delete($product);
|
| 41 | +} catch (NoSuchEntityException $e) { |
39 | 42 | }
|
40 | 43 | $objectManager->get(ProductEav::class)->executeRow($product->getId());
|
41 | 44 |
|
|
0 commit comments