forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MC-20694: Admin: Delete attribute set
- Loading branch information
1 parent
5a82cc9
commit 94277ef
Showing
6 changed files
with
325 additions
and
17 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
dev/tests/integration/framework/Magento/TestFramework/Eav/Model/GetAttributeSetByName.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\TestFramework\Eav\Model; | ||
|
||
use Magento\Eav\Api\AttributeSetRepositoryInterface; | ||
use Magento\Eav\Api\Data\AttributeSetInterface; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
|
||
/** | ||
* Attribute set additional functions. | ||
*/ | ||
class GetAttributeSetByName | ||
{ | ||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @var AttributeSetRepositoryInterface | ||
*/ | ||
private $attributeSetRepository; | ||
|
||
/** | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @param AttributeSetRepositoryInterface $attributeSetRepository | ||
*/ | ||
public function __construct( | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
AttributeSetRepositoryInterface $attributeSetRepository | ||
) { | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
$this->attributeSetRepository = $attributeSetRepository; | ||
} | ||
|
||
/** | ||
* Search and return attribute set by name. | ||
* | ||
* @param string $attributeSetName | ||
* @return AttributeSetInterface|null | ||
*/ | ||
public function execute(string $attributeSetName): ?AttributeSetInterface | ||
{ | ||
$this->searchCriteriaBuilder->addFilter('attribute_set_name', $attributeSetName); | ||
$searchCriteria = $this->searchCriteriaBuilder->create(); | ||
$result = $this->attributeSetRepository->getList($searchCriteria); | ||
$items = $result->getItems(); | ||
|
||
return array_pop($items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ion/testsuite/Magento/Catalog/_files/attribute_set_based_on_default_with_custom_group.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Catalog\Api\Data\ProductAttributeInterface; | ||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Eav\Api\AttributeSetRepositoryInterface; | ||
use Magento\Eav\Api\Data\AttributeGroupInterface; | ||
use Magento\Eav\Api\Data\AttributeSetInterfaceFactory; | ||
use Magento\Eav\Model\Entity\Attribute\GroupFactory; | ||
use Magento\Eav\Model\Entity\Type; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var AttributeSetRepositoryInterface $attributeSetRepository */ | ||
$attributeSetRepository = $objectManager->get(AttributeSetRepositoryInterface::class); | ||
/** @var AttributeSetInterfaceFactory $attributeSetFactory */ | ||
$attributeSetFactory = $objectManager->get(AttributeSetInterfaceFactory::class); | ||
/** @var Type $entityType */ | ||
$entityType = $objectManager->create(Type::class)->loadByCode(ProductAttributeInterface::ENTITY_TYPE_CODE); | ||
/** @var ProductInterface $product */ | ||
$product = $objectManager->create(ProductInterface::class); | ||
$attributeSet = $attributeSetFactory->create( | ||
[ | ||
'data' => [ | ||
'id' => null, | ||
'attribute_set_name' => 'new_attribute_set', | ||
'entity_type_id' => $entityType->getId(), | ||
'sort_order' => 300, | ||
], | ||
] | ||
); | ||
$attributeSet->isObjectNew(true); | ||
$attributeSet->setHasDataChanges(true); | ||
$attributeSet->validate(); | ||
$attributeSetRepository->save($attributeSet); | ||
$attributeSet->initFromSkeleton($product->getDefaultAttributeSetid()); | ||
/** @var AttributeGroupInterface $newGroup */ | ||
$newGroup = $objectManager->get(GroupFactory::class)->create(); | ||
$newGroup->setId(null) | ||
->setAttributeGroupName('Test attribute group name') | ||
->setAttributeSetId($attributeSet->getAttributeSetId()) | ||
->setSortOrder(11) | ||
->setAttributes([]); | ||
/** @var AttributeGroupInterface[] $groups */ | ||
$groups = $attributeSet->getGroups(); | ||
array_push($groups, $newGroup); | ||
$attributeSet->setGroups($groups); | ||
$attributeSetRepository->save($attributeSet); |
21 changes: 21 additions & 0 deletions
21
...uite/Magento/Catalog/_files/attribute_set_based_on_default_with_custom_group_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Eav\Api\AttributeSetRepositoryInterface; | ||
use Magento\TestFramework\Eav\Model\GetAttributeSetByName; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var GetAttributeSetByName $getAttributeSetByName */ | ||
$getAttributeSetByName = $objectManager->get(GetAttributeSetByName::class); | ||
/** @var AttributeSetRepositoryInterface $attributeSetRepository */ | ||
$attributeSetRepository = $objectManager->get(AttributeSetRepositoryInterface::class); | ||
$attributeSet = $getAttributeSetByName->execute('new_attribute_set'); | ||
|
||
if ($attributeSet) { | ||
$attributeSetRepository->delete($attributeSet); | ||
} |
42 changes: 42 additions & 0 deletions
42
dev/tests/integration/testsuite/Magento/Catalog/_files/product_with_test_attribute_set.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/attribute_set_based_on_default_with_custom_group.php'; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product\Attribute\Source\Status; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\Catalog\Model\ProductFactory; | ||
use Magento\Store\Model\Store; | ||
use Magento\TestFramework\Eav\Model\GetAttributeSetByName; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = $objectManager->get(ProductRepositoryInterface::class); | ||
/** @var ProductFactory $productFactory */ | ||
$productFactory = $objectManager->get(ProductFactory::class); | ||
/** @var GetAttributeSetByName $attributeSet */ | ||
$attributeSet = $objectManager->get(GetAttributeSetByName::class); | ||
$customAttributeSet = $attributeSet->execute('new_attribute_set'); | ||
$product = $productFactory->create(); | ||
$product | ||
->setTypeId('simple') | ||
->setAttributeSetId($customAttributeSet->getAttributeSetId()) | ||
->setWebsiteIds([1]) | ||
->setStoreId(Store::DEFAULT_STORE_ID) | ||
->setName('Simple Product') | ||
->setSku('simple') | ||
->setPrice(10) | ||
->setMetaTitle('meta title') | ||
->setMetaKeyword('meta keyword') | ||
->setMetaDescription('meta description') | ||
->setVisibility(Visibility::VISIBILITY_BOTH) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 22, 'is_in_stock' => 1]) | ||
->setQty(22); | ||
$productRepository->save($product); |
33 changes: 33 additions & 0 deletions
33
...integration/testsuite/Magento/Catalog/_files/product_with_test_attribute_set_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\CatalogInventory\Model\StockRegistryStorage; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\Registry; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var Registry $registry */ | ||
$registry = $objectManager->get(Registry::class); | ||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = $objectManager->get(ProductRepositoryInterface::class); | ||
/** @var StockRegistryStorage $stockRegistryStorage */ | ||
$stockRegistryStorage = $objectManager->get(StockRegistryStorage::class); | ||
try { | ||
$product = $productRepository->get('simple'); | ||
$productRepository->delete($product); | ||
} catch (NoSuchEntityException $e) { | ||
//Product already deleted. | ||
} | ||
$stockRegistryStorage->clean(); | ||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); | ||
|
||
require __DIR__ . '/attribute_set_based_on_default_with_custom_group_rollback.php'; |