0

I add attribute to special product like this

$eavSetup->addAttribute(
        Product::ENTITY,
        'dynamic_price',
        [
            'group' => 'Gift Card Information',
            'label' => 'Dynamic Price',
            'type' => 'boolean',
            'input' => 'checkbox',
            'prefer' => 'toggle',
            'frontend' => '',
            'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
            'class' => '',
            'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
            'default' => '0',
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            'visible' => true,
            'required' => false,
            'user_defined' => false,
            'searchable' => false,
            'filterable' => false,
            'comparable' => false,
            'visible_on_front' => false,
            'used_in_product_listing' => false,
            'unique' => false,
            'apply_to'=> GiftCard::TYPE_ID,
        ]
    );

But 'prefer' => 'toggle' not working like using modifier. How to set checkbox toggle?

enter image description here

enter image description here

1 Answer 1

1

You can create a form modifier similar to Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\General and change your attribute rendering mode similar to the customizeStatusField method in the class mentioned above,

or... (and I recommend this because it saves a lot of head-aches)

just change your attribute to be a yes/no dropdown instead of a toggle checkbox. You achieve a similar result without the hastle of working with checkboxes.

2
  • okay i will follow your way. thank you!! Jun 15, 2023 at 10:03
  • It's not my way. It's just a recommendation that might save you some time so you can focus on other problems :)
    – Marius
    Jun 15, 2023 at 10:12

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