Spamworldpro Mini Shell
Spamworldpro


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/old/app/code/Cnc/Setup/Setup/Patch/Data/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/Setup/Setup/Patch/Data/CreateAttributeSets.php
<?php

declare(strict_types=1);

namespace Cnc\Setup\Setup\Patch\Data;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Setup\CategorySetup;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\File\Csv;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\SampleData\FixtureManager;

class CreateAttributeSets implements DataPatchInterface
{
    const FIXTURE_ATTRIBUTESETS_FILE_PATH = 'Cnc_Setup::fixtures/attributesets.csv';
    /**
     * @var FixtureManager
     */
    private $fixtureManager;
    /**
     * @var ModuleDataSetupInterface
     */
    private $setup;
    /**
     * @var Csv
     */
    private $csv;
    /**
     * @var AttributeSetFactory
     */
    private $attributeSetFactory;
    /**
     * @var CategorySetup
     */
    private $categorySetup;

    /**
     * CreateAttributeSets constructor.
     *
     * @param ModuleDataSetupInterface $setup
     * @param FixtureManager $fixtureManager
     * @param Csv $csv
     * @param AttributeSetFactory $attributeSetFactory
     * @param CategorySetup $categorySetup
     */
    public function __construct(
        ModuleDataSetupInterface $setup,
        FixtureManager $fixtureManager,
        Csv $csv,
        AttributeSetFactory $attributeSetFactory,
        CategorySetup $categorySetup
    ) {
        $this->setup = $setup;
        $this->fixtureManager = $fixtureManager;
        $this->csv = $csv;
        $this->attributeSetFactory = $attributeSetFactory;
        $this->categorySetup = $categorySetup;
    }

    public static function getDependencies(): array
    {
        return [];
    }

    public function apply(): void
    {
        $fileName = $this->fixtureManager->getFixture(self::FIXTURE_ATTRIBUTESETS_FILE_PATH);
        $rows = $this->csv->getData($fileName);

        $entityTypeId = $this->categorySetup->getEntityTypeId(Product::ENTITY);
        $attributeSetId = $this->categorySetup->getDefaultAttributeSetId($entityTypeId);

        $x = 10;
        foreach ($rows as $key => $attributeset) {
            $attributeSet = $this->attributeSetFactory->create();
            $attributeSet->setData([
                'attribute_set_name' => $attributeset[0],
                'entity_type_id' => $entityTypeId,
                'sort_order' => $x,
            ]);
            $attributeSet->validate();
            $attributeSet->save();

            $attributeSet->initFromSkeleton($attributeSetId);
            $attributeSet->save();
            $x++;
        }
    }

    public function getAliases(): array
    {
        return [];
    }
}

Spamworldpro Mini