-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
I'm not sure if this is a bug or a feature, but I just bumped into this little gem today. Appearantly, when you create a product attribute of the type 'Fixed Product Tax' and the code starts with the string container_, Magento throws an error.
I was not sure how or why it happened, but I was able to reproduce it like this:
Preconditions
- Magento 2.1.7
Steps to reproduce
- Create a product attribute of the type 'Fixed Product Tax'.
- Give it a name that starts with
container_. - Add it to the default attribute set (for example).
- Create a new product (or edit an existing one with the same attribute set)
Expected result
- I should be able to create a new product.
Actual result
Magento gives me the following error:
1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException):
The requested component ("weee") is not found. Before using, you must add the implementation.
Bug or feature?
Trying to narrow it down, I found the following code in \Magento\Weee\Ui\DataProvider\Product\Form\Modifier\Weee:
/**
* Modification of group config
*
* @param array $metaConfig
* @return array
*/
protected function modifyMetaConfig(array $metaConfig)
{
if (isset($metaConfig['children'])) {
foreach ($metaConfig['children'] as $attributeCode => $attributeConfig) {
if ($this->startsWith($attributeCode, self::CONTAINER_PREFIX)) {
$metaConfig['children'][$attributeCode] = $this->modifyMetaConfig($attributeConfig);
} elseif (
!empty($attributeConfig['arguments']['data']['config']['formElement']) &&
$attributeConfig['arguments']['data']['config']['formElement'] === static::FORM_ELEMENT_WEEE
) {
$metaConfig['children'][$attributeCode] =
$this->modifyAttributeConfig($attributeCode, $attributeConfig);
}
}
}
return $metaConfig;
}
It's the if ($this->startsWith($attributeCode, self::CONTAINER_PREFIX)) { that does 'the magic' here. As you can guess, the self::CONTAINER_PREFIX is set to container_. So yeah... it's definitely a feature (my best guess is that the Weee module uses the container_-prefix as a reserved keyword for some internal functionality).
But in my opinion it's a bug that I am able to create a FPT attribute that starts with container_ in the first place. If it's a reserved keyword Magento should give me a notice upon creating the attribute. Just like that an attribute is not allowed to be larger than 30 characters or is not allowed to start with a number etc.