Jump to content

Add sort by: new products


renneducas

Recommended Posts

Hello,

On prestashop 1.7.7.3, there is sorting in the backoffice to display products by date added. but if someone chooses to sort by price, there won't be an option to switch back to viewing by novelty.

so is there a solution to add a sort by date added.

and also how to remove sorting by price.

thanks for your help.

Link to comment
Share on other sites

  • 1 year later...
On 2/10/2022 at 3:22 AM, renneducas said:

Hello,

On prestashop 1.7.7.3, there is sorting in the backoffice to display products by date added. but if someone chooses to sort by price, there won't be an option to switch back to viewing by novelty.

so is there a solution to add a sort by date added.

and also how to remove sorting by price.

thanks for your help.

Is there any solution for this? im looking something like this.

Link to comment
Share on other sites

Hi,

The recommended way to make changes to PrestaShop's functionality is by creating a custom module

Within your custom module, you will need to override the ProductController class to add the sorting option for "Date Added." You'll need to modify the initContent method in your overridden controller to handle this sorting.

Here is an example of how you can add the sorting option for "Date Added":

public function initContent()
{
    parent::initContent();

    $this->orderBy = 'date_add'; // Set the default sorting to "Date Added"
    $this->orderWay = 'desc'; // Set the default order to descending

    $this->context->smarty->assign('orderby', $this->orderBy);
    $this->context->smarty->assign('orderway', $this->orderWay);

    // Load products with the selected sorting
    $this->productSort();

    $this->setTemplate('catalog/listing/product-list.tpl');
}

 

To remove the sorting by price, you'll need to modify the template file where the sorting options are displayed and remove the price-related option. The template file is usually located in your theme's directory, often under themes/your_theme/templates/catalog/listing.

Finally, hook your custom module into the PrestaShop back office where the product listing is displayed.

I hope it would help!

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...