【问题标题】:How to Hide or Show Custom attribute based on other custom attribute in Product detail/edit page from Adminpanel Magento 2.4?如何在 Adminpanel Magento 2.4 的产品详细信息/编辑页面中基于其他自定义属性隐藏或显示自定义属性?
【发布时间】:2021-12-31 06:03:12
【问题描述】:

我以编程方式创建了产品的自定义属性(Setup->Installdata.php)。

 $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'serial_code_use_customer',
            [
                'type' => 'int',
                'backend' => '',
                'frontend' => '',
                'label' => 'Issue By Customer Group',
                'input' => 'boolean',
                'class' => '',
                'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => '0',
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => false,
                'unique' => false,
                'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
                'group' => self::GROUP_LABEL,
                'sort_order' => 3,
                'note' => 'Enable automatic issuing of codes based on customer group.'
            ]
        );

        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'serial_code_customer_groups',
            [
                'type' => 'varchar',
                'backend' => '',
                'frontend' => '',
                'label' => 'Select Customer Groups',
                'input' => 'multiselect',
                'class' => '',
                'source' => \Magento\Customer\Model\Customer\Attribute\Source\Group::class,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => '0',
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => false,
                'unique' => false,
                'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
                'group' => self::GROUP_LABEL,
                'sort_order' => 4,
                'note' => 'Customers in selected groups will be issued codes automatically when product is ordered.'
            ]
        );

我想在 Adminpanel Magento 2.4.x 的产品详细信息/编辑页面中隐藏或显示基于其他自定义属性的自定义属性?

例如,有一个切换点击(是/否)客户组将隐藏/显示

【问题讨论】:

标签: magento2 magento2.4


【解决方案1】:

要在管理产品详细信息页面中隐藏自定义产品属性,您需要在 My/Catalog/Setup 目录中创建 UpgradeData.php。 代码:

$eavSetup->updateAttribute(Product::ENTITY, $attrCode, 'is_visible', '0');

【讨论】:

  • 对不起,这不是预期的。问题是关于依赖的。根据您的解决方案,将默认值设置为可见/隐藏。
猜你喜欢
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多