0

Patch File: Bedard/CustomGloves/Setup/Patch/Data

<?php

namespace Bedard\CustomGloves\Setup\Patch\Data;

use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;

class SetupCustomGloveProductAttribute implements DataPatchInterface, PatchVersionInterface
{
    /** @var ModuleDataSetupInterface */
    private $moduleDataSetup;

    /** @var EavSetupFactory */
    private $eavSetupFactory;

    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     * @param EavSetupFactory $eavSetupFactory
     */
    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
    }

    /**
     * {@inheritdoc}
     */
    public function apply()
    {
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

        $eavSetup->addAttribute('catalog_product', 'alternative_color', [
            'type' => 'int',
            'label' => 'Alternative Color',
            'input' => 'select',
            'used_in_product_listing' => true,
            'user_defined' => true,
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public static function getDependencies()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public function getAliases()
    {
        return [];
    }
}

Getting this error on setup:upgrade

Warning: call_user_func() expects parameter 1 to be a valid callback, class 'Bedard\CustomGloves\Setup\Patch\Data\SetupCustomGloveProductAttribute' not found in /home/customer/www/dom2sandbox.com/public_html/vendor/magento/framework/Setup/Patch/PatchRegistry.php on line 141

PatchRegistry:

    /**
    * Get patch dependencies.
    *
    * @param string $patch
    * @return string[]
    */
   private function getDependencies(string $patch)
   {
       $depInstances = [];
       $deps = call_user_func([$patch, 'getDependencies']);
       $this->cyclomaticStack[$patch] = true;

       foreach ($deps as $dep) {
           if (isset($this->cyclomaticStack[$dep])) {
               throw new \LogicException("Cyclomatic dependency during patch installation");
           }

           $depInstance = $this->registerPatch($dep);
           /**
            * If a patch already have applied dependency - then we definitely know
            * that all other dependencies in dependency chain are applied too, so we can skip this dep
            */
           if (!$depInstance) {
               continue;
           }

           $depInstances = array_replace($depInstances, $this->getDependencies($this->patches[$dep]));
           $depInstances[$depInstance] = $depInstance;
       }

       unset($this->cyclomaticStack[$patch]);
       return $depInstances;
   }              

2.3.3 Community Edition

2
  • PatchVersionInterface is deprecated. Also in your patch is missing the getVersion method implementation. Try to remove the implementation of PatchVersionInterface Apr 14, 2020 at 11:00
  • 1
    Check the namespace is correct. In my case, this error came up because the path's namespace was Vendor\Module\Setup\Patch\. Note the different, the way right is Vendor\Module\Setup\Patch\Data\ Aug 18, 2020 at 7:04

1 Answer 1

0

Seems like issue with not implemented Interface method. If the issue persist after implementation is fixed then the next possible issue is file name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.