Created a custom short_description attribute following the exact ways to create as shown in module-catalog/Setup/CategorySetup.php and module-catalog/view/adminhtml/ui_component/category_form.xml
Install new category attribute following Magento's current category attribute array.
magento-bug2.txt
Add view/adminhtml/ui_component/category_form.xml for above attribute
magento-bug.txt
I am also getting this for a custom text and image attribute.
@maxxeh1, thank you for your report.
We've acknowledged the issue and added to our backlog.
Is there any movement on this or is there at least a workaround?
We need a solution for this too please.
Any update on this yet? I am facing the same issue after updating from 2.2.0 to 2.2.3
Can confirm this also exists in 2.2.3 enterprise.
@magento-engcom-team should I be reporting this to core enterprise support?
any further feedback on this, or a temporary work around? it's a big issue for a project we're working on
Hello,
I have got below solution and it worked for me. Please add below code into your module's di.xml
<preference for="Magento\Catalog\Model\Category\DataProvider" type="Mynamespace\Mymodule\Model\Category\DataProvider" />
Here, we need to override DataProvider.php file to add 'Use Default Value' checkbox for custom attributes. There is a function named 'getFieldsMap', we need to do changes in that function. So our
DataProvider class will be as below,
namespace Mynamespace\Mymodule\Model\Category;
use Magento\Catalog\Model\Category\DataProvider as CategoryDataProvider;
class DataProvider extends CategoryDataProvider
{
protected function getFieldsMap()
{
$parentFieldMap = parent::getFieldsMap();
array_push($parentFieldMap['display_settings'],'my_cat_desc');
return $parentFieldMap;
}
}
Here, 'my_cat_desc' = name of custom attribute and
'display_settings' = group of attribute, which we defined while creating attribute (or the section in admin panel form, where attribute is displayed).
After this, run upgrade command and clean cache, you will be able to set store specific values for custom attributes.
Hope this helps!
@viral-wagento Which version of Magento you are using for this solution?
It's not working in Magento Version 2.2.3
@parthaccorin
I am using Magento Version 2.2.3 and I checked it with multiple store views.
Also please find below.
I have added below code in my category_form.xml
/Mynamespace/Mymodule/view/adminhtml/ui_component/category_form.xml
<fieldset name="display_settings">
<container>
<field name="my_cat_desc" sortOrder="130" formElement="input">
<settings>
<dataType>varchar</dataType>
<label translate="true">My Cat Description</label>
<scopeLabel>[STORE VIEW]</scopeLabel>
</settings>
</field>
</container>
</fieldset>
@viral-wagento
@stevekarwacki
@pixiemediaweb
When we override using preferance in more than one module then only 1st one will execute and other will does not take any effect. and that's the reason it's not showing the default selection checkbox
to solve use after plugin of PrepareMeta() from \Magento\Catalog\Model\Category\DataProvider.php
Below is the solution which works perfect for me.
Di file > Mynamespace\Mymodule\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Category\DataProvider">
<plugin name="category_color_data_mapping" type="Mynamespace\Mymodule\Model\Category\DataProvider" sortOrder="1" disabled="false"/>
</type>
</config>
Plugin File > Mynamespace\Mymodule\Plugin\Category\DataProvider.php
<?php
namespace Mynamespace\Mymodule\Plugin\Category;
class DataProvider extends \Magento\Catalog\Model\Category\DataProvider
{
public function __construct(
Config $eavConfig
) {
$this->eavConfig = $eavConfig;
}
public function afterPrepareMeta(\Magento\Catalog\Model\Category\DataProvider $subject, $result)
{
$meta = $result;
$meta = array_replace_recursive($meta, $this->prepareFieldsMeta(
$this->getFieldsMap(),
$subject->getAttributesMeta($this->eavConfig->getEntityType('catalog_category'))
));
return $meta;
}
private function prepareFieldsMeta($fieldsMap, $fieldsMeta)
{
$result = [];
foreach ($fieldsMap as $fieldSet => $fields) {
foreach ($fields as $field) {
if (isset($fieldsMeta[$field])) {
$result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $fieldsMeta[$field];
}
}
}
return $result;
}
protected function getFieldsMap()
{
$fields = '';
$fields['display_settings'][] = 'category_color';
return $fields;
}
}
Here, 'category_color' = name of custom attribute and
'display_settings' = group of attribute, which we defined while creating attribute (or the section in admin panel form, where attribute is displayed).
Let me know if that works for anyone.
@parthaccorin
Yes correct, it worked for me using preference because i am working on fresh magento installation.
and the function (from DataProvider.php) , which i wanted to change was protected. So i selected to override using preference.
Thanks for your suggestion.
Hi there ! Parthaccorin's solution didn't work out of the box for me, but it has been a great help.
Maybe this can help someone one day, fresh install over there (2.2.6 community) :
app/code/Mynamespace/Mymodule/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Category\DataProvider">
<plugin name="categoryCustomAttributes" type="Mynamespace\Mymodule\Plugin\Model\Category\DataProvider" sortOrder="1" disabled="false"/>
</type>
</config>
app/code/Mynamespace/Mymodule/Plugin/Model/Category/DataProvider.php
<?php
namespace Mynamespace\Mymodule\Plugin\Model\Category;
class DataProvider extends \Magento\Catalog\Model\Category\DataProvider {
public function __construct(\Magento\Eav\Model\Config $eavConfig) {
$this->eavConfig = $eavConfig;
}
public function afterPrepareMeta(\Magento\Catalog\Model\Category\DataProvider $subject, $result) {
$meta = array_replace_recursive($result, $this->_prepareFieldsMeta(
$this->_getFieldsMap(),
$subject->getAttributesMeta($this->eavConfig->getEntityType('catalog_category'))
));
return $meta;
}
public function _prepareFieldsMeta($fieldsMap, $fieldsMeta) {
$result = [];
foreach ($fieldsMap as $fieldSet => $fields) {
foreach ($fields as $field) {
if (isset($fieldsMeta[$field])) {
$result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $fieldsMeta[$field];
}
}
}
return $result;
}
public function _getFieldsMap() {
$fields = parent::getFieldsMap();
$fields['general'][] = 'guid';
$fields['general'][] = 'title';
$fields['general'][] = 'baseline';
$fields['content'][] = 'short_description';
$fields['content'][] = 'thumbnail';
return $fields;
}
}
Regards
@rou9e solution works in 2.2.4 CE
Note: this bug wasn't fixed in 2.3.0.
Can confirm this still exists in 2.3
@rou9e thanks for your solution. It works. However, for boolean or select attributes it shows the options twice, with same values. Any suggestion for this?
@hypershopbv
I don't have this kind of problem but I experienced a duplicated text attribute one time.
It was due to a simple mistake : I definied an attribute in a specific group in _getFieldsMap() method, but I was calling it in another group (because I changed my mind) in the form.xml.
Hope that it could help you.. (bool / select attributes works fine for me).
How is it we still don't have an official fix for this 1.5 years later? I am confused -- seems like fixing a bug like this would have been a higher priority than adding new features for 2.3. Thanks @rou9e and @parthaccorin for the solutions -- wish I had found this github issue report before debugging through the whole component system, lol.
Any update on this? Can't believe this is still not working in Magento 2.3.x …
The patch doesn't seem to work on Magento 2.3.0 (Exception triggered missing required $name argument in constructor, even though I added the full constructor's definition..)
Also, for WYSIWYG fields that remain disabled, view issue #20154.
I have follow the code to create category attribute and added the code as shared above by @parthaccorin but not able to compile the code. due to some error, So please any oone share the complete working for for this issue to fix in
Hi there ! Parthaccorin's solution didn't work out of the box for me, but it has been a great help.
Maybe this can help someone one day, fresh install over there (2.2.6 community) :app/code/Mynamespace/Mymodule/etc/di.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Model\Category\DataProvider"> <plugin name="categoryCustomAttributes" type="Mynamespace\Mymodule\Plugin\Model\Category\DataProvider" sortOrder="1" disabled="false"/> </type> </config>
app/code/Mynamespace/Mymodule/Plugin/Model/Category/DataProvider.php
<?php namespace Mynamespace\Mymodule\Plugin\Model\Category; class DataProvider extends \Magento\Catalog\Model\Category\DataProvider { public function __construct(\Magento\Eav\Model\Config $eavConfig) { $this->eavConfig = $eavConfig; } public function afterPrepareMeta(\Magento\Catalog\Model\Category\DataProvider $subject, $result) { $meta = array_replace_recursive($result, $this->_prepareFieldsMeta( $this->_getFieldsMap(), $subject->getAttributesMeta($this->eavConfig->getEntityType('catalog_category')) )); return $meta; } public function _prepareFieldsMeta($fieldsMap, $fieldsMeta) { $result = []; foreach ($fieldsMap as $fieldSet => $fields) { foreach ($fields as $field) { if (isset($fieldsMeta[$field])) { $result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $fieldsMeta[$field]; } } } return $result; } public function _getFieldsMap() { $fields = parent::getFieldsMap(); $fields['general'][] = 'guid'; $fields['general'][] = 'title'; $fields['general'][] = 'baseline'; $fields['content'][] = 'short_description'; $fields['content'][] = 'thumbnail'; return $fields; } }
Regards
what is the custom attribute code here in the code?
I am still facing the same issue in magento 2..2.6, Can anyone please share the complete working code for this issue. I am using this code to create a category attribute and after that i follow the @rou9e solution, but still attribute not working as expected.
I am still facing the same issue in magento 2..2.6, Can anyone please share the complete working code for this issue. I am using this code to create a category attribute and after that i follow the @rou9e solution, but still attribute not working as expected.
@Puru2016 I didn't actually try his solution but my guess is that it is due to the wrong use of the constructor.
The Plugin class extends \Magento\Catalog\Model\Category\DataProvider
, but the parent constructor not only isn't called, but also missing parameters.
I recommand using a simple preference instead of plugin, this way will work (did for me).
Hi there ! Parthaccorin's solution didn't work out of the box for me, but it has been a great help.
Maybe this can help someone one day, fresh install over there (2.2.6 community) :app/code/Mynamespace/Mymodule/etc/di.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Model\Category\DataProvider"> <plugin name="categoryCustomAttributes" type="Mynamespace\Mymodule\Plugin\Model\Category\DataProvider" sortOrder="1" disabled="false"/> </type> </config>
app/code/Mynamespace/Mymodule/Plugin/Model/Category/DataProvider.php
<?php namespace Mynamespace\Mymodule\Plugin\Model\Category; class DataProvider extends \Magento\Catalog\Model\Category\DataProvider { public function __construct(\Magento\Eav\Model\Config $eavConfig) { $this->eavConfig = $eavConfig; } public function afterPrepareMeta(\Magento\Catalog\Model\Category\DataProvider $subject, $result) { $meta = array_replace_recursive($result, $this->_prepareFieldsMeta( $this->_getFieldsMap(), $subject->getAttributesMeta($this->eavConfig->getEntityType('catalog_category')) )); return $meta; } public function _prepareFieldsMeta($fieldsMap, $fieldsMeta) { $result = []; foreach ($fieldsMap as $fieldSet => $fields) { foreach ($fields as $field) { if (isset($fieldsMeta[$field])) { $result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $fieldsMeta[$field]; } } } return $result; } public function _getFieldsMap() { $fields = parent::getFieldsMap(); $fields['general'][] = 'guid'; $fields['general'][] = 'title'; $fields['general'][] = 'baseline'; $fields['content'][] = 'short_description'; $fields['content'][] = 'thumbnail'; return $fields; } }
Regards
Confirm this works on Magento 2.3.1
You should make the __construct method compatible with the parent.
It's not good for Plugin to extend the class itself but it can work if you copy the __construct method from \Magento\Catalog\Model\Category\DataProvider
import all classes at the top
use Magento\Catalog\Model\CategoryFactory;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
use Magento\Eav\Model\Config;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Registry;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\DataProvider\EavValidationRules;
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
EavValidationRules $eavValidationRules,
CategoryCollectionFactory $categoryCollectionFactory,
StoreManagerInterface $storeManager,
Registry $registry,
Config $eavConfig,
RequestInterface $request,
CategoryFactory $categoryFactory,
array $meta = [],
array $data = []
) {
parent::__construct($name,
$primaryFieldName,
$requestFieldName,
$eavValidationRules,
$categoryCollectionFactory,
$storeManager,
$registry,
$eavConfig,
$request,
$categoryFactory,
$meta,
$data
);
$this->eavConfig = $eavConfig;
}
public function _getFieldsMap() {
$fields = parent::getFieldsMap();
$fields['general'][] = 'guid';
$fields['general'][] = 'title';
$fields['general'][] = 'baseline';
$fields['content'][] = 'short_description';
$fields['content'][] = 'short_description';
$fields['display_settings'][] = 'my_cat_desc';
return $fields;
}
add my_cat_desc in _getFieldsMap() with the tab you want. display_settings is for this one.
then php bin/magento setup:di:compile will compile everything without errors like:
Incompatible argument type: Required type: \Magento\Ui\DataProvider\EavValidationRules. Actual type: array; File:
You should make the __construct method compatible with the parent.
It's not good for Plugin to extend the class itself but it can work if you copy the __construct method from \Magento\Catalog\Model\Category\DataProviderimport all classes at the top
use Magento\Catalog\Model\CategoryFactory; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory; use Magento\Eav\Model\Config; use Magento\Framework\App\RequestInterface; use Magento\Framework\Registry; use Magento\Store\Model\StoreManagerInterface; use Magento\Ui\DataProvider\EavValidationRules;
public function __construct( $name, $primaryFieldName, $requestFieldName, EavValidationRules $eavValidationRules, CategoryCollectionFactory $categoryCollectionFactory, StoreManagerInterface $storeManager, Registry $registry, Config $eavConfig, RequestInterface $request, CategoryFactory $categoryFactory, array $meta = [], array $data = [] ) { parent::__construct($name, $primaryFieldName, $requestFieldName, $eavValidationRules, $categoryCollectionFactory, $storeManager, $registry, $eavConfig, $request, $categoryFactory, $meta, $data ); $this->eavConfig = $eavConfig; } public function _getFieldsMap() { $fields = parent::getFieldsMap(); $fields['general'][] = 'guid'; $fields['general'][] = 'title'; $fields['general'][] = 'baseline'; $fields['content'][] = 'short_description'; $fields['content'][] = 'short_description'; $fields['display_settings'][] = 'my_cat_desc'; return $fields; }
add my_cat_desc in _getFieldsMap() with the tab you want. display_settings is for this one.
then php bin/magento setup:di:compile will compile everything without errors like:
Incompatible argument type: Required type: \Magento\Ui\DataProvider\EavValidationRules. Actual type: array; File:
Agreed, but a simple preference would be better in that particular case in my opinion :)
Reproduced on 2.4.x as well.
Currenty the method getFieldsMap()
returns a predefined associative array containing the attribute_group_name
as index and then containing an array of the attribute_code
s associated with that group. All custom defined attributes should be dynamicly added to this list to make this work right?
Easier said than done, but if people agree in this I take a look into this approach
getFieldsMap()
in Magento\Catalog\Model\Catagory\DataProdiver
:
protected function getFieldsMap()
{
return [
'general' => [
'parent',
'path',
'is_active',
'include_in_menu',
'name',
],
'content' => [
'image',
'description',
'landing_page',
],
'display_settings' => [
'display_mode',
'is_anchor',
'available_sort_by',
'use_config.available_sort_by',
'default_sort_by',
'use_config.default_sort_by',
'filter_price_range',
'use_config.filter_price_range',
],
'search_engine_optimization' => [
'url_key',
'url_key_create_redirect',
'url_key_group',
'meta_title',
'meta_keywords',
'meta_description',
],
'assign_products' => [
],
'design' => [
'custom_use_parent_settings',
'custom_apply_to_products',
'custom_design',
'page_layout',
'custom_layout_update',
'custom_layout_update_file'
],
'schedule_design_update' => [
'custom_design_from',
'custom_design_to',
],
'category_view_optimization' => [
],
'category_permissions' => [
],
];
}
`
Hi @engcom-Echo. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.[ ] 2. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.
:white_check_mark: Confirmed by @engcom-Echo
Thank you for verifying the issue. Based on the provided information internal tickets MC-30511
were created
Issue Available: @engcom-Echo, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._
Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
:white_check_mark: Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-30511
were created
Issue Available: @engcom-Charlie, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._
@balathangam thank you for joining. Please accept team invitation here and self-assign the issue.
Hi @balathangam. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.[ ] 2. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.
What is the status of the fix?
@fredden Remark, in case it's not already known: We applied the PR Patch, but it seems that is causes other issues (checkbox Create Permanent Redirect for old URL on categories no longer clickable). Please keep that in mind when regression testing.
@amenk Thanks for the feedback. I'd not noticed that before your message, so thanks for raising. What version of Magento did you apply the patch to? I've done a little testing just now and get the same behaviour with & without the patch on my development branch (which is up-to-date with 2.4-develop
at time of writing).
@fredden actually we are a bit outdated (2.3.3-p1)
the same behaviour with & without the patch on my development
That means you are not seeing the issue with the "Create Permanent Redirect for old URL", right?
I am attaching our exact patch for reference. I think it might be outdated and I possibly have to try your most recent version, in case did not notice the regression.
Thanks, that's helpful. I can definitely see that the checkbox does nothing with this patch applied, but it also seemed to do nothing when I returned the old hard-coded values. I'll investigate further.
I don't expect recent changes to the patch to behave any differently. The initial code was a 95% solution, with one bug fixed for 'containers' later. Recent changes are cosmetic only and won't affect functionality.
Hi @maxxeh1. Thank you for your report.
The issue has been fixed in magento/magento2#28216 by @fredden in 2.4-develop branch
Related commit(s):
The fix will be available with the upcoming 2.4.2 release.
Most helpful comment
How is it we still don't have an official fix for this 1.5 years later? I am confused -- seems like fixing a bug like this would have been a higher priority than adding new features for 2.3. Thanks @rou9e and @parthaccorin for the solutions -- wish I had found this github issue report before debugging through the whole component system, lol.