Question

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
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top