How to change the default catalog ordering direction Date Added on the frontend product lists from ascending to descending?
-
15-04-2021 - |
質問
I am having trouble changing the default arrow from ascending to descending. I have 'Set Product as New to Date' Set as Default, which is what I want. However, I want newer products showing first so I want arrow to be set default as descending when clicking on category links. Want arrow to be pointing down.
I tried following this answer but it is still not working for me. Magento2: Default to sort by price descending not ascending
In my Theme File app/design/frontend/Smartwave/porto/Magento_Catelog/layout/catalog_category_view.xml
. I tried changing the file to this code to below. But it is not working.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
<action method="setDefaultDirection">
<argument name="dir" xsi:type="string">desc</argument>
</action>
<container name="category.product.list.additional" as="additional" />
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
<!--<block class="Magento\Framework\View\Element\Template" as="default"/>-->
</block>
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
name="category.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
<block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName">
<argument name="name" xsi:type="string">product_list_toolbar</argument>
</action>
</block>
</referenceContainer>
<move element="category.products.list" as="product_list" destination="category.products"/>
<referenceContainer name="sidebar.main">
<block class="Smartwave\Porto\Block\Template" name="category_view_custom_block" after="-" template="Magento_Catalog::category/custom_block.phtml"/>
</referenceContainer>
</body>
</page>
Any help would be much appreciated. I want the arrow to point down into descending order.
解決
You can Change it in Core Magento Files I figured out.
/httpdocs/vendor/magento/module-catalog/Helper/Product/ProductList.php
, you can set asc or desc.
Proper way is to do it via extension/plugin.