![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/app/code/Webkul/PrivateShop/Setup/Patch/Data/ |
<?php /** * Webkul Software * * @category Webkul * @package Webkul_PrivateShop * @author Webkul Software Private Limited * @copyright Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ namespace Webkul\PrivateShop\Setup\Patch\Data; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Eav\Setup\EavSetupFactory; use Magento\Customer\Model\Customer; use Magento\Catalog\Model\Category; use Magento\Catalog\Model\Product; use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; use Webkul\PrivateShop\Helper\Groups as HelperData; class NewCustomAttributes implements DataPatchInterface { /** * @var HelperData */ protected $helper; /** * @var \Magento\Framework\Setup\ModuleDataSetupInterface */ protected $moduleDataSetup; /** * @var \Magento\Customer\Setup\CustomerSetupFactory */ protected $customerSetupFactory; /** * @var \Magento\Eav\Setup\EavSetupFactory */ protected $eavSetupFactory; /** * @var \Magento\Framework\Module\Dir\Reader */ protected $moduleReader; /** * @var \Magento\Framework\Filesystem\DirectoryList */ protected $directoryList; /** * @var \Magento\Framework\Filesystem */ protected $fileSystem; /** * @var \Magento\Framework\Filesystem\Driver\File */ protected $fileDriver; /** * @var \Magento\Framework\Filesystem\Io\File */ protected $file; /** * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory * @param EavSetupFactory $eavSetupFactory * @param \Magento\Framework\Module\Dir\Reader $moduleReader * @param \Magento\Framework\Filesystem\DirectoryList $directoryList * @param \Magento\Framework\Filesystem $fileSystem * @param \Magento\Framework\Filesystem\Driver\File $fileDriver * @param \Magento\Framework\Filesystem\Io\File $file * @param HelperData $helper */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, CustomerSetupFactory $customerSetupFactory, EavSetupFactory $eavSetupFactory, \Magento\Framework\Module\Dir\Reader $moduleReader, \Magento\Framework\Filesystem\DirectoryList $directoryList, \Magento\Framework\Filesystem $fileSystem, \Magento\Framework\Filesystem\Driver\File $fileDriver, \Magento\Framework\Filesystem\Io\File $file, HelperData $helper ) { $this->moduleDataSetup = $moduleDataSetup; $this->customerSetupFactory = $customerSetupFactory; $this->eavSetupFactory = $eavSetupFactory; $this->moduleReader = $moduleReader; $this->directoryList = $directoryList; $this->fileSystem = $fileSystem; $this->fileDriver = $fileDriver; $this->file = $file; $this->helper = $helper; } /** * @inheritdoc */ public function apply() { $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerSetup->addAttribute(Customer::ENTITY, 'private_group', [ 'type' => 'varchar', 'label' => 'Private Group', 'input' => 'text', 'source' => '', 'required' => false, 'visible' => false, 'position' => 333, 'system' => false, 'backend' => '' ]); $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'private_group') ->addData(['used_in_forms' => [ 'adminhtml_customer' ], 'is_used_in_grid' => true, 'is_visible_in_grid' => false ]); $attribute->save(); $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->addAttribute(Category::ENTITY, 'private_group', [ 'type' => 'varchar', 'label' => 'Private Group', 'input' => 'text', 'sort_order' => 333, 'source' => '', 'global' => ScopedAttributeInterface::SCOPE_WEBSITE, 'visible' => false, 'required' => false, 'user_defined' => false, 'default' => null, 'group' => 'General Information', 'backend' => '' ]); $this->moveDirToMediaDir(); } /** * @inheritdoc */ public function getAliases() { return []; } /** * @inheritdoc */ public static function getDependencies() { return []; } /** * @inheritdoc */ private function moveDirToMediaDir() { $helper = $this->helper; try { $type = $this->directoryList->getPath('media'); $sampleFilePath = $type.'/privateshop/label/'; $viewDir = $this->moduleReader->getModuleDir( \Magento\Framework\Module\Dir::MODULE_VIEW_DIR, 'Webkul_PrivateShop' ); $mediaFile = $viewDir.'/base/web/images/dummy.png'; if (!$this->fileDriver->isExists($sampleFilePath)) { $this->file->mkdir($sampleFilePath, 0777, true); } $filePath = $sampleFilePath.'dummy.png'; if ($this->fileDriver->isExists($sampleFilePath)) { if ($this->fileDriver->isExists($mediaFile)) { $this->fileDriver->copy($mediaFile, $filePath); } } } catch (\Exception $e) { $helper->logDataInLogger( "Patch execute : ".$e->getMessage() ); } } }