This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Eav\Model\Entity\Type $entityType */
$entityType = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)
->loadByCode('catalog_product');
$data = $entityType->getData();
$entityTypeId = $entityType->getId();
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
$attributeSet->setData(
[
'attribute_set_name' => 'test_attribute_set',
'entity_type_id' => $entityTypeId,
'sort_order' => 100
]
);
$attributeSet->validate();
$attributeSet->save();
$attributeData = [
[
'attribute_code' => 'foo',
'entity_type_id' => $entityTypeId,
'backend_type' => 'varchar',
'is_required' => 1,
'is_user_defined' => 1,
'is_unique' => 0,
'frontend_label' => ['foo'],
'attribute_set_id' => $entityType->getDefaultAttributeSetId()
]
];
foreach ($attributeData as $data) {
/** @var \Magento\Eav\Model\Entity\Attribute $attribute */
$attribute = $objectManager->create(\Magento\Eav\Model\Entity\Attribute::class);
$attribute->setData($data);
$attribute->save();
}
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Eav\Model\Entity\Attribute\Set;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\Registry;
$objectManager = Bootstrap::getObjectManager();
$registry = $objectManager->get(Registry::class);
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);
/** @var Attribute $attribute */
$attribute = $objectManager->create(Attribute::class);
$attribute->loadByCode(4, 'foo');
if ($attribute->getId()) {
$attribute->delete();
}
/** @var Set $attributeSet */
$attributeSet = $objectManager->create(Set::class)->load('test_attribute_set', 'attribute_set_name');
if ($attributeSet->getId()) {
$attributeSet->delete();
}
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
@@ -0,0 +1,97 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Eav\Model\Entity\Type $entityType */
$entityType = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)
->loadByCode('order');
$data = $entityType->getData();
$data['entity_type_code'] = 'test';
unset($data['entity_type_id']);
/** @var \Magento\Eav\Model\Entity\Type $testEntityType */
$testEntityType = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)
->setData($data)
->save();
$entityTypeId = $testEntityType->getId();
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
$attributeSet->setData([
'attribute_set_name' => 'test_attribute_set',
'entity_type_id' => $entityTypeId,
'sort_order' => 100,
]);
$attributeSet->validate();
$attributeSet->save();
/** @var \Magento\Eav\Model\Entity\Attribute\Group $attributeGroup */
$attributeGroup = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Group::class);
$attributeGroup->setData(
[
'attribute_set_id' => $attributeSet->getAttributeSetId(),
'sort_order' => 30,
'attribute_group_code' => 'test_attribute_group',
'default_id' => 0,
]
);
$attributeGroup->save();
$attributeData = [
[
'attribute_code' => 'attribute_for_search_1',
'entity_type_id' => $entityTypeId,
'backend_type' => 'varchar',
'is_required' => 1,
'is_user_defined' => 1,
'is_unique' => 0,
'attribute_set_id' => $testEntityType->getDefaultAttributeSetId(),
'attribute_group_id' => $attributeSet->getDefaultGroupId($testEntityType->getDefaultAttributeSetId()),
],
[
'attribute_code' => 'attribute_for_search_2',
'entity_type_id' => $entityTypeId,
'backend_type' => 'varchar',
'is_required' => 1,
'is_user_defined' => 1,
'is_unique' => 0,
'attribute_set_id' => $testEntityType->getDefaultAttributeSetId(),
'attribute_group_id' => $attributeSet->getDefaultGroupId($testEntityType->getDefaultAttributeSetId()),
],
[
'attribute_code' => 'attribute_for_search_3',
'entity_type_id' => $entityTypeId,
'backend_type' => 'varchar',
'is_required' => 1,
'is_user_defined' => 1,
'is_unique' => 0,
'attribute_set_id' => $attributeSet->getAttributeSetId(),
'attribute_group_id' => $attributeGroup->getAttributeGroupId(),
],
[
'attribute_code' => 'attribute_for_search_4',
'entity_type_id' => $entityTypeId,
'backend_type' => 'int',
'is_required' => 0,
'is_user_defined' => 1,
'is_unique' => 0,
],
[
'attribute_code' => 'attribute_for_search_5',
'entity_type_id' => $entityTypeId,
'backend_type' => 'varchar',
'is_required' => 0,
'is_user_defined' => 1,
'is_unique' => 0,
],
];
foreach ($attributeData as $data) {
/** @var \Magento\Eav\Model\Entity\Attribute $attribute */
$attribute = $objectManager->create(\Magento\Eav\Model\Entity\Attribute::class);
$attribute->setData($data);
$attribute->save();
}
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/**
* Create attribute set
*/
$entityTypeId = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)
->loadByCode('catalog_product')
->getId();
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
$attributeSet->setData([
'attribute_set_name' => 'attribute_set_1_for_search',
'entity_type_id' => $entityTypeId,
'sort_order' => 100,
]);
$attributeSet->validate();
$attributeSet->save();
/**
* Create attribute groups
*/
$attributeGroupData = [
[
'attribute_set_id' => $attributeSet->getAttributeSetId(),
'sort_order' => 10,
'attribute_group_code' => 'attribute_group_1_for_search',
'default_id' => 1,
],
[
'attribute_set_id' => $attributeSet->getAttributeSetId(),
'sort_order' => 20,
'attribute_group_code' => 'attribute_group_2_for_search',
'default_id' => 0,
],
[
'attribute_set_id' => $attributeSet->getAttributeSetId(),
'sort_order' => 30,
'attribute_group_code' => 'attribute_group_3_for_search',
'default_id' => 0,
],
];
foreach ($attributeGroupData as $data) {
/** @var \Magento\Eav\Model\Entity\Attribute\Group $attributeGroup */
$attributeGroup = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Group::class);
$attributeGroup->setData($data);
$attributeGroup->save();
}
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$entityTypeId = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)
->loadByCode('catalog_product')
->getId();
$attributeSetData = [
[
'attribute_set_name' => 'attribute_set_1_for_search',
'entity_type_id' => $entityTypeId,
'sort_order' => 100,
],
[
'attribute_set_name' => 'attribute_set_2_for_search',
'entity_type_id' => $entityTypeId,
'sort_order' => 200,
],
[
'attribute_set_name' => 'attribute_set_3_for_search',
'entity_type_id' => $entityTypeId,
'sort_order' => 300,
],
[
'attribute_set_name' => 'attribute_set_4_for_search',
'entity_type_id' => $entityTypeId,
'sort_order' => 400,
],
];
foreach ($attributeSetData as $data) {
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
$attributeSet->setData($data);
$attributeSet->validate();
$attributeSet->save();
}
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$attributeSetData = [
'attribute_set_1_for_search',
'attribute_set_2_for_search',
'attribute_set_3_for_search',
'attribute_set_4_for_search',
];
foreach ($attributeSetData as $attributeSetName) {
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class)
->load($attributeSetName, 'attribute_set_name');
if ($attributeSet->getId()) {
$attributeSet->delete();
}
}
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\TestFramework\Helper\Bootstrap;
$objectManager = Bootstrap::getObjectManager();
$setup = $objectManager->get(ModuleDataSetupInterface::class);
/** @var EavSetup $eavSetup */
$eavSetup = $objectManager->get(EavSetupFactory::class)
->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'zzz',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'zzz',
'input' => 'select',
'class' => '',
'source' => '',
'global' => 1,
'visible' => true,
'required' => true,
'user_defined' => true,
'default' => null,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => true,
'apply_to' => '',
'system' => 1,
'group' => 'General',
'option' => ['values' => ["Black", "White", "Red", "Brown", "zzz", "Metallic"]]
]
);
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
use Magento\Catalog\Model\Product;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\TestFramework\Helper\Bootstrap;
$objectManager = Bootstrap::getObjectManager();
$setup = $objectManager->get(ModuleDataSetupInterface::class);
/** @var EavSetup $eavSetup */
$eavSetup = $objectManager->get(EavSetupFactory::class)
->create(['setup' => $setup]);
$eavSetup->removeAttribute(Product::ENTITY, 'zzz');
@@ -0,0 +1,16 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
$entityTypeId = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)->loadByCode('catalog_product')->getId();
$attributeSet->setData([
'attribute_set_name' => 'empty_attribute_set',
'entity_type_id' => $entityTypeId,
'sort_order' => 200,
]);
$attributeSet->validate();
$attributeSet->save();
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class)
->load('empty_attribute_set', 'attribute_set_name');
if ($attributeSet->getId()) {
$attributeSet->delete();
}
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
use Magento\Eav\Setup\EavSetup;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation;
$objectManager = Bootstrap::getObjectManager();
/** @var AttributeFactory $attributeFactory */
$attributeFactory = $objectManager->get(AttributeFactory::class);
/** @var ProductAttributeRepositoryInterface $productAttributeRepository */
$productAttributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
$attribute = $attributeFactory->create()->loadByCode(Product::ENTITY, 'text_editor_attribute');
if (!$attribute->getId()) {
/** @var Presentation $presentation */
$presentation = $objectManager->get(Presentation::class);
/** @var EavSetup $installer */
$installer = $objectManager->create(EavSetup::class);
$attributeData = [
'attribute_code' => 'text_editor_attribute',
'is_global' => 1,
'is_user_defined' => 1,
'frontend_input' => 'texteditor',
'is_unique' => 0,
'is_required' => 0,
'is_searchable' => 0,
'is_visible_in_advanced_search' => 0,
'is_comparable' => 0,
'is_filterable' => 0,
'is_filterable_in_search' => 0,
'is_used_for_promo_rules' => 0,
'is_html_allowed_on_front' => 1,
'is_visible_on_front' => 0,
'used_in_product_listing' => 0,
'used_for_sort_by' => 0,
'frontend_label' => ['Text editor attribute'],
'backend_type' => 'text',
];
$attribute->setData($presentation->convertPresentationDataToInputType($attributeData));
$productAttributeRepository->save($attribute);
$attribute = $productAttributeRepository->get('text_editor_attribute');
/* Assign attribute to attribute set */
$installer->addAttributeToGroup(Product::ENTITY, 'Default', 'Attributes', $attribute->getId());
}
@@ -0,0 +1,27 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Registry;
use Magento\TestFramework\Helper\Bootstrap;
$objectManager = Bootstrap::getObjectManager();
/** @var ProductAttributeRepositoryInterface $productAttributeRepository */
$productAttributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
/** @var Registry $registry */
$registry = $objectManager->get(Registry::class);
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);
try {
$attribute = $productAttributeRepository->get('text_editor_attribute');
$productAttributeRepository->delete($attribute);
} catch (NoSuchEntityException $e) {
//Attribute already deleted.
}
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);