0

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 Answers 2

0

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.

2
  • is_used_for_promo_rules field is created already in database I think this $this->eavSetupFactory->updateAttribute(4,184,'is_used_for_promo_rules',1,null); should work but it does not , I just need to update and change value from 0 to 1 . Commented Jan 8, 2020 at 14:28
  • I must update it , must not delete. Commented Jan 8, 2020 at 14:30
0

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

Your Answer

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

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