2

I am working through http://www.mohannatarajan.com/magento/magento2-get-product-attribute-value

Here is my catalog_product_view.xml page-

<?xml version="1.0"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
    <css src="mage/gallery/gallery.css"/>
</head>
<update handle="catalog_product_opengraph" />
<update handle="page_calendar"/>
<body>
    <attribute name="itemtype" value="http://schema.org/Product" />
    <attribute name="itemscope" value="itemscope"/>
    <referenceBlock name="head.components">
        <block class="Magento\Framework\View\Element\Js\Components" name="checkout_page_head_components" template="Magento_Catalog::js/components.phtml"/>
    </referenceBlock>
    <referenceBlock name="page.main.title">
        <arguments>
            <argument name="css_class" xsi:type="string">product</argument>
            <argument name="add_base_attribute" xsi:type="string">itemprop="name"</argument>
        </arguments>
    </referenceBlock>
    <referenceBlock name="root">
        <arguments>
            <argument name="add_attribute" xsi:type="string">itemscope itemtype="http://schema.org/Product"</argument>
        </arguments>
    </referenceBlock>
    <referenceContainer name="content">
        <container name="product.info.main" htmlTag="div" htmlClass="product-info-main" before="-">
            <container name="product.info.price" label="Product info auxiliary container" htmlTag="div" htmlClass="product-info-price" after="product.info.review">
                <container name="product.info.stock.sku" label="Product auxiliary info" htmlTag="div" htmlClass="product-info-stock-sku">
                    <container name="product.info.type" before="-"/>
                    <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.sku" template="product/view/attribute.phtml" after="product.info.type">
                        <arguments>
                            <argument name="at_call" xsi:type="string">getSku</argument>
                            <argument name="at_code" xsi:type="string">sku</argument>
                            <argument name="css_class" xsi:type="string">sku</argument>
                            <argument name="at_label" xsi:type="string">default</argument>
                            <argument name="add_attribute" xsi:type="string">itemprop="sku"</argument>
                        </arguments>
                    </block>
                    <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.AlternatePart" template="product/view/AlternatePart.phtml" after="-">
                    <arguments>
                        <argument name="at_call" xsi:type="string">getAlternatePartNumber</argument>
                        <argument name="at_code" xsi:type="string">alternate_part_number</argument>
                        <argument name="css_class" xsi:type="string">alternate part number </argument>
                        <argument name="at_label" xsi:type="string">alternate_part_number </argument>
                        <argument name="add_attribute" xsi:type="string">itemprop="alternate_part_number"</argument>
                    </arguments>
                    </block>
                </container>
                <block class="Magento\Catalog\Block\Product\View" name="product.info.review" template="product/view/review.phtml" after="product.info.stock.sku" />
                <block class="Magento\Catalog\Pricing\Render" name="product.price.final" after="product.info.sku">
                    <arguments>
                        <argument name="price_render" xsi:type="string">product.price.render.default</argument>
                        <argument name="price_type_code" xsi:type="string">final_price</argument>
                        <argument name="zone" xsi:type="string">item_view</argument>
                    </arguments>
                </block>
            </container>
            <block class="Magento\Catalog\Pricing\Render" name="product.price.tier" after="product.info.price">
                <arguments>
                    <argument name="price_render" xsi:type="string">product.price.render.default</argument>
                    <argument name="price_type_code" xsi:type="string">tier_price</argument>
                    <argument name="zone" xsi:type="string">item_view</argument>
                </arguments>
            </block>
            <container name="alert.urls" as="alert_urls" label="Alert Urls" after="product.price.tier"/>
            <block class="Magento\Catalog\Block\Product\View" name="product.info" template="product/view/form.phtml" after="alert.urls">
                <container name="product.info.form.content" as="product_info_form_content">
                    <block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart" as="addtocart" template="product/view/addtocart.phtml"/>
                </container>
                <block class="Magento\Framework\View\Element\Template" name="product.info.form.options" as="options_container">
                    <block class="Magento\Catalog\Block\Product\View" name="product.info.options.wrapper" as="product_options_wrapper" template="product/view/options/wrapper.phtml">
                        <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>
                        <block class="Magento\Framework\View\Element\Html\Calendar" name="html_calendar" as="html_calendar" template="Magento_Theme::js/calendar.phtml"/>
                    </block>
                    <block class="Magento\Catalog\Block\Product\View" name="product.info.options.wrapper.bottom" as="product_options_wrapper_bottom" template="product/view/options/wrapper/bottom.phtml">
                        <block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart.additional" as="product.info.addtocart" template="product/view/addtocart.phtml"/>
                    </block>
                </block>
            </block>
            <container name="product.info.extrahint" as="extrahint" label="Product View Extra Hint">
                <container name="product.info.social" label="Product social links container" htmlTag="div" htmlClass="product-social-links" after="product.info.overview">
                    <block class="Magento\Catalog\Block\Product\View" name="product.info.addto" as="addto" template="product/view/addto.phtml">
                        <block class="Magento\Catalog\Block\Product\View\AddTo\Compare" name="view.addto.compare" after="view.addto.wishlist"
                               template="Magento_Catalog::product/view/addto/compare.phtml" />
                    </block>
                    <block class="Magento\Catalog\Block\Product\View" name="product.info.mailto" template="product/view/mailto.phtml"/>
                </container>
            </container>
            <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.overview" template="product/view/attribute.phtml" group="detailed_info" after="product.info.extrahint">
                <arguments>
                    <argument name="at_call" xsi:type="string">getShortDescription</argument>
                    <argument name="at_code" xsi:type="string">short_description</argument>
                    <argument name="css_class" xsi:type="string">overview</argument>
                    <argument name="at_label" translate="true" xsi:type="string">none</argument>
                    <argument name="title" translate="true" xsi:type="string">Overview</argument>
                    <argument name="add_attribute" xsi:type="string">itemprop="description"</argument>
                </arguments>
            </block>
        </container>
        <container name="product.info.media" htmlTag="div" htmlClass="product media" after="product.info.main">
            <block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" template="product/view/gallery.phtml"/>
        </container>
        <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.details" template="product/view/details.phtml" after="product.info.media">
            <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.description" template="product/view/attribute.phtml" group="detailed_info">
                <arguments>
                    <argument name="at_call" xsi:type="string">getDescription</argument>
                    <argument name="at_code" xsi:type="string">description</argument>
                    <argument name="css_class" xsi:type="string">description</argument>
                    <argument name="at_label" xsi:type="string">none</argument>
                    <argument name="title" translate="true" xsi:type="string">Details</argument>
                </arguments>
            </block>
            <block class="Magento\Catalog\Block\Product\View\Attributes" name="product.attributes" as="additional" template="product/view/attributes.phtml" group="detailed_info">
                <arguments>
                    <argument translate="true" name="title" xsi:type="string">More Information</argument>
                </arguments>
            </block>
        </block>
        <block class="Magento\Cookie\Block\RequireCookie" name="require-cookie" template="Magento_Cookie::require_cookie.phtml">
            <arguments>
                <argument name="triggers" xsi:type="array">
                    <item name="compareProductLink" xsi:type="string">.action.tocompare</item>
                </argument>
            </arguments>
        </block>
    </referenceContainer>
    <referenceContainer name="content.aside">
        <block class="Magento\Catalog\Block\Product\ProductList\Related" name="catalog.product.related" template="Magento_Catalog::product/list/items.phtml">
            <arguments>
                <argument name="type" xsi:type="string">related</argument>
            </arguments>
            <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="related.product.addto" as="addto">
                <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                       name="related.product.addto.compare" as="compare"
                       template="Magento_Catalog::product/list/addto/compare.phtml"/>
            </block>
        </block>
        <block class="Magento\Catalog\Block\Product\ProductList\Upsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml">
            <arguments>
                <argument name="type" xsi:type="string">upsell</argument>
            </arguments>
            <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="upsell.product.addto" as="addto">
                <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                       name="upsell.product.addto.compare" as="compare"
                       template="Magento_Catalog::product/list/addto/compare.phtml"/>
            </block>
        </block>
        <block class="Magento\Catalog\Block\Product\View\Additional" name="product.info.additional" as="product_additional_data"/>
    </referenceContainer>
    <referenceBlock name="product.info.addtocart">
        <block class="Magento\Catalog\Block\ShortcutButtons\InCatalog" name="addtocart.shortcut.buttons"/>
    </referenceBlock>
    <referenceBlock name="product.info.addtocart.additional">
        <block class="Magento\Catalog\Block\ShortcutButtons\InCatalog" name="addtocart.shortcut.buttons.additional"/>
    </referenceBlock>
</body>
</page>

When that file is in this filepath- /vendor/magento/module-catalog/view/frontend/layout everything works great.

When it is moved to- app/design/frontend/example/examplechild/Magento_Catalog/layout

It does not work. Is my child theme path wrong? Or is there another step I am missing?

6
  • can you please tell me how did you created your theme and is it workinf properly? did you set that theme from Admin ? Commented Sep 28, 2017 at 20:36
  • Everything else in the child theme works fine.
    – tjjen
    Commented Sep 28, 2017 at 20:41
  • static-content:deploy did you try after moving XML file ? Commented Sep 28, 2017 at 20:48
  • Yes doesn't help
    – tjjen
    Commented Sep 28, 2017 at 21:14
  • Check your file name again. I find that if you copy and paste file names from a tutorial, it will sometimes add special characters to that file name that might not show up in your ftp program or file system. from what you have posted, you have the correct file names and path.
    – circlesix
    Commented Sep 28, 2017 at 21:26

1 Answer 1

1

I took the code that you have posted there and i think you have an issue in the xml itself. When i remove all the code down to just a test call to a css file that i know doesn't exist:

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="test.css"/>
    </head>
</page>

The file loads and i get a console error that "test.css can't be found" which is what you would expect. When i added the code you have posted in it's full, that error goes away, i would assume because there is an error in there that is stopping the execution of the rest of the file.

I would take out section of the file until you get that test.css to load and then you know where in the xml the error is and can address that issue.

Some other notes about working with this stuff. Changes in xml files don't require you to recompile, there are picked up automatically after you save the file and refresh the page when you are in developer mode. But if you have cache enabled (which i do to make the dev process faster) you do need to clear cache. Also, i have ran into this all the time in magento 2, the theme being set to virtual. you can read more here:

Magento 2 custom theme layout xml and css not working

7
  • I thought the same thing but if I do have an issue in the xml file why would it work fine if it is in the original folder? If I am reading your response correct I should remove bits of code until it starts working then look at the code? Should I remove it by block, reference container, or something else? I got in the database and checked, all themes are set to physical. I appreciate the help I am really stuck on this one.
    – tjjen
    Commented Oct 2, 2017 at 21:46
  • I thought the same thing, as the file (minus the little bit of added code from the tutorial) is the same. I can only guess right now, but it might be redeclaring something that is causing an issue. That technically shouldn't happen in xml, so this could also point to a Magento bug. Let me keep digging, but i'm going to just remove block by block till i find the part that is kicking the error. I'll get back here when i find something.
    – circlesix
    Commented Oct 3, 2017 at 2:16
  • Thank you, I appreciate the help. I don't know what to do. I worked on this for a few more hours today but keep running into the same issue. I wish was getting some sort of error but nothing makes sense.
    – tjjen
    Commented Oct 3, 2017 at 21:10
  • I have always left the catalog_product_view in its original folder. I changed the file name and flushed the cache and now I get this error- 1 exception(s): Exception #0 (Exception): Notice: Undefined index: class in /www/sites/www.example.com/files/magento2/project-community-edition/vendor/magento/framework/View/Layout/Generator/Block.php on line 213 Not sure if this is normal or not.
    – tjjen
    Commented Oct 4, 2017 at 15:50
  • Still not solved but close. The issue is that when it is in the child theme it is not pulling the correct details.phtml file. When it is working correctly it is pulling -app/design/frontend/Infortis/base/Infortis_Base/templates/product/view/details.phtml When it is not working correctly it is pulling- vendor/magento/module-catalog/view/frontend/templates/product/view/details.phtml The xml code is the same it is just different locations.
    – tjjen
    Commented Oct 4, 2017 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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