0

this is related to several qestions that I have found on Stackexchange, including one I posted myself, as well as what I have read in the Magento 2.1 docs. But I'm a bit worried about consequences.

I have employed the use of a theme in my Magento 2.1.2 store. The Magento_Catalog module in the theme extends the catalog_product_view.xml file from the base Magento theme. There are snippets of code in the extending file that are the exact pieces of code from the Magento core files, and are causing my site to throw exceptions over and over and over. Below the is the code:

Magento Core:

<block class="Magento\Catalog\Block\Product\View\Options" name="product.info.options" as="product_options" template="product/view/options.phtml">
    <block class="Magento\Catalog\Block\Product\View\Options\Type\DefaultType" as="default" template="product/view/options/type/default.phtml"/>
    <block class="Magento\Catalog\Block\Product\View\Options\Type\Text" as="text" template="product/view/options/type/text.phtml"/>
    <block class="Magento\Catalog\Block\Product\View\Options\Type\File" as="file" template="product/view/options/type/file.phtml"/>
    <block class="Magento\Catalog\Block\Product\View\Options\Type\Select" as="select" template="product/view/options/type/select.phtml"/>
    <block class="Magento\Catalog\Block\Product\View\Options\Type\Date" as="date" template="product/view/options/type/date.phtml"/>
</block>

Theme code:

<block class="Magento\Catalog\Block\Product\View\Options" name="product.info.options" as="product_options" template="product/view/options.phtml">
    <block class="Magento\Catalog\Block\Product\View\Options\Type\DefaultType" as="default" template="product/view/options/type/default.phtml"/>
    <block class="Magento\Catalog\Block\Product\View\Options\Type\Text" as="text" template="product/view/options/type/text.phtml"/>
    <block class="Magento\Catalog\Block\Product\View\Options\Type\File" as="file" template="product/view/options/type/file.phtml"/>
    <block class="Magento\Catalog\Block\Product\View\Options\Type\Select" as="select" template="product/view/options/type/select.phtml"/>
    <block class="Magento\Catalog\Block\Product\View\Options\Type\Date" as="date" template="product/view/options/type/date.phtml"/>
</block>

There are other snippets of code that are the exact same as well, but this block is the only area that is throwing the exception. Exception is:

[2017-02-07 22:17:38] main.CRITICAL: Magento\Framework\Exception\LocalizedException: The element 'product.info.options' already has a child with alias 'file' in /home/{username}/public_html/vendor/magento/framework/Data/Structure.php:611

...with exceptions for each of the alias (as="") names "default", "text", "file", "select", "date". The other alias names in the extending file code are not throwing exceptions for some reason.

  1. Why are these alias names ("default", "text", "file", "select", "date") throwing exceptions, but the others alias names that are also in the core code do not?
  2. Can I remove this code from the extending file safely? I tried changing the alias names, but I was worried that it may be called somewhere that I don't know and mess up the storefront.

I have found a few questions regarding alias name and some say that the alias name can be "anything" but IF it is called somewhere by getChildHtml then won't there be a problem?

I have also read the Docs about extending and I have a feeling the theme code writer is not correct in re-writing the same block code (but, why did they do it?)

Thanks in advance

2

The issue with these blocks specifically is that they don't have a name specified. The name is what Magento uses to uniquely identify blocks in the layout.

In this case, when you're extending it, Magento doesn't know to overwrite the parent block and tries to add another block with the same alias.

There is nothing wrong with the theme code. This is an issue with Magento's code. Name is a required attribute for all blocks and containers.

I've opened a pull request to fix the issue: https://github.com/magento/magento2/pull/8514/files

  • Andrew, thanks for your response. I completely overlooked the missing names in the core code. Thanks for submitting the request. I'll do my best to follow the github pull request. – Jason Feb 12 '17 at 4:18
  • Andrew, I'm following the pull request, has it been approved? Can I add the code? Thanks! – Jason Feb 20 '17 at 22:33
  • Hey Jason, yes it's been approved and was merged yesterday. It should be in the next release of Magento, so you can safely add the code. – Andrew Noble Feb 20 '17 at 22:40
  • Andrew, so...I updated the code in the core file under vendor/magento/module-catalog/view/frontend/layout/catagory_product_view.xml. Making sure that your added code, pulled from Github with the names added, have replaced the old code. And I'm getting the exceptions again. The same exceptions that were being thrown previous to making the adjustment. Any ideas? The theme code is the same as stated in the original question (without names, just aliases). Do I also need to edit the them code with names, and not just aliases? This is a third party theme. – Jason Feb 21 '17 at 3:43
  • 1
    Andrew, just an update, with the addition of your code, I also fixed the theme code and added the names of the blocks (product.info.option.default, product.info.options.file...etc.) to the them code as well and this stopped the exceptions. The names were crucial to both the core and the them code. I guess my theme writer isn't very on it. – Jason Feb 21 '17 at 4:03

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.