0

I added a wysiwyg as category eav attribute and all works correctly, but I want that the content of my wysiwyg is different for each store view. If I switch store view in category page, my wysiwyg field is disable, it turns enable only when I select "All Store Views". How can I fix it?

Setup/Patch/Data/AddCategorySizeChartAttribute.php

<?php
declare(strict_types=1);

namespace Lampoo\SizeChart\Setup\Patch\Data;

use Lampoo\SizeChart\Model\CategoryAttributes;
use Magento\Catalog\Model\Category;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;

class AddCategorySizeChartAttribute implements DataPatchInterface
{
    /**
     * @var ModuleDataSetupInterface
     */
    private $moduleDataSetup;

    /**
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    /**
     * AddCategorySizeChartAttribute constructor.
     * @param ModuleDataSetupInterface $moduleDataSetup
     * @param EavSetupFactory $eavSetupFactory
     */
    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
    }

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

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

    /**
     * {@inheritDoc}
     */
    public function apply()
    {
        $categorySetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

        $categorySetup->addAttribute(
            Category::ENTITY,
            CategoryAttributes::SIZE_CHART_ATTRIBUTE,
            [
                'type' => 'text',
                'label' => 'Size Chart',
                'input' => 'textarea',
                'required' => false,
                'sort_order' => 999,
                'global' => ScopedAttributeInterface::SCOPE_STORE,
                'wysiwyg_enabled' => true,
                'is_html_allowed_on_front' => true,
                'group' => 'General Information',
            ]
        );

        return $this;
    }
}

view/adminhtml/ui_component/category_form.xml

<?xml version="1.0"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="general">
        <field name="size_chart" template="ui/form/field" sortOrder="70" formElement="wysiwyg">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="wysiwygConfigData" xsi:type="array">
                        <item name="height" xsi:type="string">300px</item>
                        <item name="add_variables" xsi:type="boolean">true</item>
                        <item name="add_widgets" xsi:type="boolean">true</item>
                        <item name="add_images" xsi:type="boolean">true</item>
                        <item name="add_directives" xsi:type="boolean">true</item>
                    </item>
                    <item name="source" xsi:type="string">category</item>
                </item>
            </argument>
            <settings>
                <label translate="true">Size Chart</label>
                <scopeLabel>[STORE VIEW]</scopeLabel>
                <dataScope>size_chart</dataScope>
            </settings>
            <formElements>
                <wysiwyg class="Magento\Catalog\Ui\Component\Category\Form\Element\Wysiwyg">
                    <settings>
                        <rows>8</rows>
                        <wysiwyg>true</wysiwyg>
                    </settings>
                </wysiwyg>
            </formElements>
        </field>
    </fieldset>
</form>

When I select "All Store Views": https://nimb.ws/bTiIo6

When I select specific store view: https://nimb.ws/GK37JU

0

Field is disabled, because this is the default functionality of the magento. On store view, editor will be disabled and we can enable it after uncheck the use default value checkbox. Please check if this checkbox is missing at your end. Check my screenshots: enter image description here enter image description here

  • Yes, I don't have that checkbox. How can I add it? – Mirko Rapisarda Jun 14 at 9:25
  • Can you please try to create one attribute of product from admin and then compare each value of both the attributes(one created from script and second created from the admin), there must be some value which is not set causing issue. – nishu Jun 14 at 13:27
  • Please check "is_global" property in the database table catalog_eav_attribute and make sure it is having value as 0. then that checkbox will appear in the admin after the editor – nishu Jun 14 at 13:28
  • I compare all attribute with another one of same type (the field Description is a wysiwyg) and are the same. – Mirko Rapisarda Jun 14 at 18:01
  • Did you checked this "Please check "is_global" property in the database table catalog_eav_attribute and make sure it is having value as 0. then that checkbox will appear in the admin after the editor at store view level" – nishu Jun 17 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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