init
This commit is contained in:
+122
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\ChineseDirectory\Setup\Patch\Schema;
|
||||
|
||||
use Magento\Customer\Model\Indexer\Address\AttributeProvider;
|
||||
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\SchemaPatchInterface;
|
||||
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
|
||||
|
||||
class UpdateCustomerNameToNotRequired implements SchemaPatchInterface, 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]);
|
||||
|
||||
$entityAttributes = [
|
||||
'customer_address' => [
|
||||
'lastname' => [
|
||||
'is_visible' => false,
|
||||
'is_required' => false,
|
||||
'is_system' => false,
|
||||
'is_user_defined' => true
|
||||
],
|
||||
'street' => [
|
||||
'sort_order' => 355,
|
||||
'position' => 355,
|
||||
],
|
||||
'postcode' => [
|
||||
'is_visible' => false,
|
||||
'is_required' => false
|
||||
],
|
||||
'company' => [
|
||||
'is_visible' => false
|
||||
],
|
||||
'telephone' => [
|
||||
'sort_order' => 79,
|
||||
'validate_rules' => '{"max_text_length":11,"min_text_length":1}',
|
||||
'position' => 79,
|
||||
],
|
||||
'city' => [
|
||||
'backend_model' => \Stemcell\ChineseDirectory\Model\Entity\Attribute\Backend\City::class
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$customerSetup->upgradeAttributes($entityAttributes);
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
public function revert()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$customerSetup->updateAttribute(AttributeProvider::ENTITY,'lastname','is_required',1);
|
||||
$customerSetup->updateAttribute(AttributeProvider::ENTITY,'city','backend');
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user