Jump to content

[SOLVED] How do i modify following: best-sales.php , new-products.php and product-list to fit my specifikations?


Joachim Tranberg

Recommended Posts

Hey Guys.

How are you?

I am finishing my new template, but i have a few things that i cant figure out how to change.

Best-sales.php:
are currently showing ALL sold products, how do i limit it to 36 products?
I also need to sort it after how many sold, not just random. Most sold first.

New-products.php:
How do i modify so it is showing the latest product FIRST!?

Product-list:
How do i force this to show products A-Z ?

Please note that i have removed the "Sort after" drop-down menu in my Presta Theme.

I would appreciate your help, thanks

Best Regards

Joachim

Link to comment
Share on other sites

Try going to the Preferences > Products tab and changing "Default order by" to "Position in category" and "Default order way" to "Decreasing".

The reason I say this is that on the best sellers page, "Position in category" is converted to "Number of sales" and on the new products page, "Position in category" is converted to "Date added", so after making this change, your best sellers should be sorted from highest sales to lowest sales and your new products page from newest date to oldest date.

The only problem then is that the product listings will be sorted by the position you specify on the Catalog tab. I can't see any way to automatically sort them by name without modifying PrestaShop's code. You'll need to change line 60 of category.php (in PrestaShop v1.3.1) from:

$cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);



to:

$orderBy = 'name';
$orderWay = 'ASC';
$cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);



and if you want search results sorted by name too, you'll need to change line 22 of search.php (in PrestaShop v1.3.1) from:

$search = Search::find(intval($cookie->id_lang), $query, $p, $n, $orderBy, $orderWay);



to:

$orderBy = 'name';
$orderWay = 'ASC';
$search = Search::find(intval($cookie->id_lang), $query, $p, $n, $orderBy, $orderWay);



This will override the default 'position' and 'DESC' with 'name' and 'ASC' just for the product and search listings.

Link to comment
Share on other sites

I forgot about that part. To fix that, change line 7 of best-sales.php from:

$nbProducts = intval(ProductSale::getNbSales());



to:

$nbProducts = intval(ProductSale::getNbSales());
if ($nbProducts > 36) $nbProducts = 36;



and change line 10 from:

$products = ProductSale::getBestSales(intval($cookie->id_lang), intval($p) - 1, intval($n), $orderBy, $orderWay);



to:

$products = ProductSale::getBestSales(intval($cookie->id_lang), /*intval($p) - */1, /*intval($n)*/ 36, $orderBy, $orderWay);



After making this change, whenever you go to best-sales.php, you will get a single page with 36 products.

Link to comment
Share on other sites

  • 5 years later...

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...