2

I have searched for how to change the default sort order by descending and found this answer here Magento2: Default to sort by price descending not ascending, but when i load my category pages, i get an error.

I changed my

app/design/frontend/{{Vender_Namespace}}/{{Theme_Name}}/Magento_Catalog/layout/catalog_category_view.xml

<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="head.additional">
        <block class="Magento\Framework\View\Element\Template" name="script.sharethis" template="MGS_Mpanel::sharethis/sharethis_script.phtml" ifconfig="mpanel/share_config/share_product_catalog"/>
    </referenceBlock>
    <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="product.catalog.sharethis" before="category.products" template="MGS_Mpanel::sharethis/sharethis.phtml" ifconfig="mpanel/share_config/share_product_catalog"/>
    </referenceContainer>

</body>
</page>

to

    <?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="head.additional">
        <block class="Magento\Framework\View\Element\Template" name="script.sharethis" template="MGS_Mpanel::sharethis/sharethis_script.phtml" ifconfig="mpanel/share_config/share_product_catalog"/>
    </referenceBlock>
    <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="product.catalog.sharethis" before="category.products" template="MGS_Mpanel::sharethis/sharethis.phtml" ifconfig="mpanel/share_config/share_product_catalog"/>

    <referenceBlock name="category.products.list">
        <action method="setDefaultDirection">
            <argument name="dir" xsi:type="string">desc</argument>
        </action>
    </referenceBlock>

    </referenceContainer>

</body>
</page>

then I get the error

1 exception(s):
Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 
'referenceBlock', attribute 'class': The attribute 'class' is not allowed.
Line: 1043

Element 'referenceBlock', attribute 'as': The attribute 'as' is not allowed.
Line: 1043


Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 
'referenceBlock', attribute 'class': The attribute 'class' is not allowed.
Line: 1043

Element 'referenceBlock', attribute 'as': The attribute 'as' is not allowed.
Line: 1043
  • I checked out my original post, and you are right, there was some invalid xml in there, a referenceBlock can only have the name of the block in there. For some reason i had the class and as in there as well. But this was in the Magento 2.0 days, so i think there have since been updates to enforce xml standards. I have now updated my original post and it should be correct now. – circlesix Apr 27 '18 at 15:32
  • But here is the odd thing, the code you are using is correct. It's diff from my original post in the right ways. I ran your code in a xml validator and everything looks right. The error message that you post comes from the incorrect use of the class and as in xml that i did, so i'm wondering if this is just a cache thing, that you updated the code to be correct but the xml is just cached. – circlesix Apr 27 '18 at 15:34
  • 1
    I will try it and see, if it works, then you can add it as an answer and i will mark it as correct – winfred adrah May 2 '18 at 11:44
  • 1
    Hi, it worked, you can add that as and answer and i will mark it as correct – winfred adrah May 7 '18 at 8:53
0

I checked against the code that you have posted, and the issue is the code in the original post that you reference. There were some syntax mistakes in the xml that were trigging the error.

For any element that has a referenceBlock you can only include the name="" where in the original post i had an as and class. Removing those will clear up the issue. Remember to clear cache as the block xml is stored there if you are working with cache on.

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.