96 lines
2.6 KiB
PHP
96 lines
2.6 KiB
PHP
<?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 [
|
|
|
|
];
|
|
}
|
|
}
|
|
|