I want to add "laba cena" (attribute) in catalog price rule dropdown I am using data patch but its not working

any tips?

now using

 <?php
 namespace Devall\SpecialPrice\Setup\Patch\Data;

  use Magento\Framework\Setup\Patch\DataPatchInterface;
  use Magento\Eav\Setup\EavSetup;

      class AddLabaCenaAttribute implements DataPatchInterface
     {
   protected $eavSetupFactory;

public function __construct( EavSetup $eavSetupFactory)
{
    $this->eavSetupFactory = $eavSetupFactory;
}

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

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

/**
 * @inheritDoc
 */
public function apply()
{
    $this->eavSetupFactory->updateAttribute(4,184,'is_used_for_promo_rules',1,null);
}

      }`

still no success .

有帮助吗?

解决方案 2

removed old data patch with same name from patch_list, then it worked.

其他提示

As per the your requirement you can use the following code. You need to update your file with the below code:

<?php
namespace Devall\SpecialPrice\Setup\Patch\Data;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;

class AddLabaCenaAttribute implements DataPatchInterface
{
    /** @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', 'laba_cena', [
            'type' => 'string',
            'label' => 'laba cena',
            'input' => 'select',
            'used_in_product_listing' => true,
            'user_defined' => true,
            'used_for_promo_rules' => true
        ]);
    }

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

    public static function getVersion()
    {
        return '1.0.1';
    }

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

Don't forget to delete the attribute from admin.

NOTE: Above is not tested but it should work.

许可以下: CC-BY-SA归因
scroll top