In Magento 2.2.7 I have created a custom attribute (textarea, wysiwyg) for categories.
This is my InstallData
namespace MyVendor\Mods\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
/**
* Constructor
*
* @param \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* {@inheritdoc}
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'long_description',
[
'type' => 'text',
'label' => 'Long Description',
'input' => 'textarea',
'sort_order' => 5,
'global' => 0,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => null,
'group' => 'General Information',
'searchable' => true,
'is_html_allowed_on_front' => true,
'wysiwyg_enabled' => true
]
);
}
}
The setup works fine, the field shows up in the backend and it saves the data I enter.
There are only two issues here and I sense they are connected:
- There is no scope. I cannot save different values for different storeviews.
'global' => 0
behaves identical to\Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE
, I tried both. The value is always global, no matter what.
2. The value is not stored in the category flat tables. The field long_description
does not show up in the flat tables at all.
I copied the field's setup from the catalog module's config for the description field (CategorySetup.php):
'description' => [
'type' => 'text',
'label' => 'Description',
'input' => 'textarea',
'required' => false,
'sort_order' => 4,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'wysiwyg_enabled' => true,
'is_html_allowed_on_front' => true,
'group' => 'General Information',
],
What am I missing?
Thank you
EDIT: The attribute shows up in the flat tables after I forced a reindex. I thought the running cronjob would take care of it. Still the scope issue remains.