Skip to content

M2.1.7 : Magento throws an error when a FPT attribute starts with the string 'container_'. #10155

@kanduvisla

Description

@kanduvisla

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

  1. Magento 2.1.7

Steps to reproduce

  1. Create a product attribute of the type 'Fixed Product Tax'.
  2. Give it a name that starts with container_.
  3. Add it to the default attribute set (for example).
  4. Create a new product (or edit an existing one with the same attribute set)

Expected result

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CatalogIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentbug reporttriage wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions