98 lines
2.8 KiB
PHP
98 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Lts\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 AddNetsuiteStatusAttribute implements DataPatchInterface, PatchRevertableInterface
|
|
{
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param ModuleDataSetupInterface $moduleDataSetup
|
|
* @param CustomerSetupFactory $customerSetupFactory
|
|
* @param SetFactory $attributeSetFactory
|
|
*/
|
|
public function __construct(
|
|
private ModuleDataSetupInterface $moduleDataSetup,
|
|
private CustomerSetupFactory $customerSetupFactory,
|
|
private SetFactory $attributeSetFactory
|
|
) {
|
|
$this->moduleDataSetup = $moduleDataSetup;
|
|
$this->customerSetupFactory = $customerSetupFactory;
|
|
$this->attributeSetFactory = $attributeSetFactory;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
* @throws \Magento\Framework\Exception\LocalizedException
|
|
* @throws \Magento\Framework\Validator\ValidateException
|
|
*/
|
|
public function apply(): void
|
|
{
|
|
$this->moduleDataSetup->getConnection()->startSetup();
|
|
/** @var CustomerSetup $customerSetup */
|
|
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
|
|
|
$customerSetup->addAttribute(
|
|
Customer::ENTITY,
|
|
'netsuite_status',
|
|
[
|
|
'label' => 'Netsuite Status',
|
|
'input' => 'text',
|
|
'type' => 'static',
|
|
'source' => '',
|
|
'required' => false,
|
|
'position' => 334,
|
|
'visible' => false,
|
|
'system' => false,
|
|
'backend' => ''
|
|
]
|
|
);
|
|
|
|
$this->moduleDataSetup->getConnection()->endSetup();
|
|
}
|
|
|
|
public function revert(): void
|
|
{
|
|
$this->moduleDataSetup->getConnection()->startSetup();
|
|
/** @var CustomerSetup $customerSetup */
|
|
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
|
$customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'netsuite_status');
|
|
|
|
$this->moduleDataSetup->getConnection()->endSetup();
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getAliases(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public static function getDependencies(): array
|
|
{
|
|
return [
|
|
|
|
];
|
|
}
|
|
}
|
|
|