init
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Setup\Patch\Data;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Setup\CustomerSetup;
|
||||
use Magento\Customer\Setup\CustomerSetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\Set;
|
||||
use Magento\Eav\Model\Entity\Attribute\SetFactory;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
|
||||
|
||||
class AddMobileCustomerAttribute implements DataPatchInterface, PatchRevertableInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
/**
|
||||
* @var CustomerSetup
|
||||
*/
|
||||
private $customerSetupFactory;
|
||||
/**
|
||||
* @var SetFactory
|
||||
*/
|
||||
private $attributeSetFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ModuleDataSetupInterface $moduleDataSetup
|
||||
* @param CustomerSetupFactory $customerSetupFactory
|
||||
* @param SetFactory $attributeSetFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CustomerSetupFactory $customerSetupFactory,
|
||||
SetFactory $attributeSetFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->customerSetupFactory = $customerSetupFactory;
|
||||
$this->attributeSetFactory = $attributeSetFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
|
||||
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
|
||||
|
||||
/** @var $attributeSet Set */
|
||||
$attributeSet = $this->attributeSetFactory->create();
|
||||
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
|
||||
|
||||
$customerSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'mobile',
|
||||
[
|
||||
'label' => 'Mobile',
|
||||
'input' => 'text',
|
||||
'type' => 'static',
|
||||
'source' => '',
|
||||
'required' => true,
|
||||
'position' => 333,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false,
|
||||
'backend' => '',
|
||||
'unique' => true
|
||||
]
|
||||
);
|
||||
|
||||
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mobile');
|
||||
$attribute->addData([
|
||||
'used_in_forms' => [
|
||||
'adminhtml_customer',
|
||||
'customer_account_create',
|
||||
'customer_account_edit'
|
||||
]
|
||||
]);
|
||||
$attribute->addData([
|
||||
'attribute_set_id' => $attributeSetId,
|
||||
'attribute_group_id' => $attributeGroupId
|
||||
|
||||
]);
|
||||
$attribute->save();
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
public function revert()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'mobile');
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Setup\Patch\Data;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Setup\CustomerSetup;
|
||||
use Magento\Customer\Setup\CustomerSetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\SetFactory;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
|
||||
|
||||
class UpdateCustomerNameToNotRequired implements DataPatchInterface, PatchRevertableInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
/**
|
||||
* @var CustomerSetup
|
||||
*/
|
||||
private $customerSetupFactory;
|
||||
/**
|
||||
* @var SetFactory
|
||||
*/
|
||||
private $attributeSetFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ModuleDataSetupInterface $moduleDataSetup
|
||||
* @param CustomerSetupFactory $customerSetupFactory
|
||||
* @param SetFactory $attributeSetFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CustomerSetupFactory $customerSetupFactory,
|
||||
SetFactory $attributeSetFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->customerSetupFactory = $customerSetupFactory;
|
||||
$this->attributeSetFactory = $attributeSetFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
|
||||
$customerSetup->updateAttribute(Customer::ENTITY,'firstname','is_required',0);
|
||||
$customerSetup->updateAttribute(Customer::ENTITY,'lastname','is_required',0);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
public function revert()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$customerSetup->updateAttribute(Customer::ENTITY,'firstname','is_required',1);
|
||||
$customerSetup->updateAttribute(Customer::ENTITY,'lastname','is_required',1);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Setup\Patch\Schema;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Model\Indexer\Address\AttributeProvider;
|
||||
use Magento\Customer\Setup\CustomerSetup;
|
||||
use Magento\Customer\Setup\CustomerSetupFactory;
|
||||
use Magento\Eav\Model\AttributeRepository;
|
||||
use Magento\Eav\Model\Entity\Attribute\Set;
|
||||
use Magento\Eav\Model\Entity\Attribute\SetFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
use Magento\Framework\Validator\ValidateException;
|
||||
|
||||
class AddCustomerAbbrAttribute implements SchemaPatchInterface
|
||||
{
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
/**
|
||||
* @var CustomerSetup
|
||||
*/
|
||||
private $customerSetupFactory;
|
||||
/**
|
||||
* @var SetFactory
|
||||
*/
|
||||
private $attributeSetFactory;
|
||||
private AttributeRepository $repository;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ModuleDataSetupInterface $moduleDataSetup
|
||||
* @param CustomerSetupFactory $customerSetupFactory
|
||||
* @param SetFactory $attributeSetFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CustomerSetupFactory $customerSetupFactory,
|
||||
SetFactory $attributeSetFactory,
|
||||
AttributeRepository $repository
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->customerSetupFactory = $customerSetupFactory;
|
||||
$this->attributeSetFactory = $attributeSetFactory;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
* @throws ValidateException
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
|
||||
$customerSetup->addAttribute(Customer::ENTITY, 'customer_abbr', [
|
||||
'type' => 'varchar',
|
||||
'label' => 'Customer Abbr',
|
||||
'input' => 'text',
|
||||
'source' => '',
|
||||
'required' => true,
|
||||
'visible' => false,
|
||||
'position' => 330,
|
||||
'is_user_defined' => true,
|
||||
'is_used_in_grid' => true,
|
||||
]);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Setup;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Framework\Setup\InstallDataInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
use Magento\Framework\Setup\UpgradeSchemaInterface;
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Stemcell\Customer\Model\Attribute\Source\CustomerType;
|
||||
use Stemcell\Customer\Model\Attribute\Source\ResearchFields;
|
||||
|
||||
class RegistryInstallData implements UpgradeSchemaInterface
|
||||
{
|
||||
protected $eavSetupFactory;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
|
||||
){
|
||||
$this->eavSetupFactory = $eavSetupFactory;
|
||||
}
|
||||
|
||||
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
|
||||
{
|
||||
$eavSetup = $this->eavSetupFactory->create();
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'customer_type',
|
||||
[
|
||||
'label' => 'Customer Type',
|
||||
'input' => 'select',
|
||||
'type' => 'static',
|
||||
'source' => CustomerType::class,
|
||||
'required' => false,
|
||||
'position' => 333,
|
||||
'visible' => false,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false,
|
||||
]
|
||||
);
|
||||
//公司或单位名称
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'company_name',
|
||||
[
|
||||
'label' => 'Company Name',
|
||||
'input' => 'text',
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'position' => 334,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false
|
||||
]
|
||||
);
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'company_address',
|
||||
[
|
||||
'label' => 'Company Address',
|
||||
'input' => 'text',
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'position' => 335,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false
|
||||
]
|
||||
);
|
||||
//课题组、部门
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'department',
|
||||
[
|
||||
'label' => 'Department',
|
||||
'input' => 'text',
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'position' => 335,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false
|
||||
]
|
||||
);
|
||||
//研究方向
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'research_fields',
|
||||
[
|
||||
'label' => 'Research Fields',
|
||||
'input' => 'multiselect',
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'position' => 335,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false,
|
||||
'source' => ResearchFields::class
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user