Jump to content

Recommended Posts

You need to change the code in your categorycontroller.php file, from

 

$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);

 

to

 

$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay, false, true, true);

  • Like 1
Link to comment
Share on other sites

Just inspect the getProducts method, the best way to find it out :)

 

 

public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null)

Link to comment
Share on other sites

hi friend, thank you to your reply. about it:

 

You need to change the code in your categorycontroller.php file, from

 

$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);

 

to

 

$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay, false, true, true);

 

 

 

 

i done this, but now, my categories are showwing just one product per page. the products are random, but, just one per page. i did it in prestashop 1.5.4

Edited by lucasdemenezes (see edit history)
  • Like 1
Link to comment
Share on other sites

add another parameter for the number of random products you want then :)  like'

 

$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay, false, true, true, 10);

  • Like 2
Link to comment
Share on other sites

with solution like this one your customers can (while browsing category pages 1,2,3,4, etc.)

- see products twice (or more)

- dont see some products

 

let me explain, for example: we have category "t-shirts"

This category has got 10 products, let's say p1,p2,p3,p4,p5,p6,p7,p8,p9,p10

we display 5 products per page, so "t-shirts" category will have 2 pages

 

if our catalog displays products randomly, first page will show (example):

p1,p5,p6,p9,p10

 

second page will show:

p1,p2,p3,p9,p10

 

as you can see p4,p7,p8 will not appear and p1, p9, p10 appeared twice (on page 1 and page 2)

Link to comment
Share on other sites

Yes, but there is no other solution if they want products random, without doing some huge modifications to prevent the same ones being displayed again

 

also, since it really is random all products will be shown sooner or later, it's a matter of chance :)

Link to comment
Share on other sites

Hi Nemo1 and vekia,

this is a very interesting alternative for the shops, do you have any idea how to solve the problem about the duplicate and not appear products?

Thanks in advance.

Goyo.

Note: I test this code with 1.5.6.2, 1.6.0.9 and It's running fine but with 1.6.0.11 It isn't working.

Link to comment
Share on other sites

@Goyo

As I said it's all a matter or randomness. They will appear sooner or later, and the rate is equal for all as it's totally random, but of course it depends on how many products you want to display. The only way would be to cache the found ones into a cookie and exclude them for the search on other pages. But it's complicated really, and not very seo friendly at all

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
HI Guys,

 

No matter what I do and change in /classes/Category.php nothing changes on my front-end.  Cache disabled, cleared.  $random set true .. even modified the SQL statements and add order by clauses.. no matter what.. the products in the categories come up the same exact way.. is something overriding what I'm doing?  Does anybody have any clues as to why and where I should look?

 

Tried all changes from everybody's post here and still no change on the way the products come up.  Always in the same order.

 

Using PS V 1.5.6.2

 

Thanks!

Link to comment
Share on other sites

Hi Vekia,

 

Yes I did :)  Only files there are Cart / Dispacher / Index / Link / Product no category

 

Any other ideas?  I'm at a loss.. don't understand why when even when I modify SQL queries or any order by's still no change in the way the products are showing up in the categories.

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Hi NemoPS,

 

I fixed that problem and put the site back up.. by "any ideas now" I meant.. obviously it is that file being served / used because when I changed the name the site threw an error. So if that is the file being used then how come when I make the modifications you suggested, or any other modification.. clear all files / caches and the products in the categories still come up exactly the same way?

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Nemo,

 

Ok I tried it.  when I put die('test') inside where you've suggested the code change.. nothing happens.. so that whole condition isn't getting triggered.. when I put die('test') somewhere else.. in another block or condition.. it works.. dies..  to make things easier here's the code I have.. maybe it's different or something there you might be able to spot by seeing the whole thing!

 

/**
* Assign list of products template vars
*/
public function assignProductList()
{
$hookExecuted = false;
Hook::exec('actionProductListOverride', array(
'nbProducts' => &$this->nbProducts,
'catProducts' => &$this->cat_products,
'hookExecuted' => &$hookExecuted,
));
 
// The hook was not executed, standard working
if (!$hookExecuted)
{
$this->context->smarty->assign('categoryNameComplement', '');
$this->nbProducts = $this->category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
die('test');
}
// Hook executed, use the override
else
// Pagination must be call after "getProducts"
$this->pagination($this->nbProducts);
 
foreach ($this->cat_products as &$product)
{
if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity']))
$product['minimal_quantity'] = $product['product_attribute_minimal_quantity'];
}
 
$this->context->smarty->assign('nb_products', $this->nbProducts);
}
 
/**
* Get instance of current category
*/
public function getCategory()
{
return $this->category;
}
}
 
Thanks!
Link to comment
Share on other sites

  • 8 months later...

Hi,

 

What part of product-list.tpl did you put that?  I've tried several times to do this and it has never worked.. I've tried every suggestion listed in this tread.. and more.. nothing changes no matter what I do!

 

Also what version of PS are you using?

 

If you could please show the code where you added that specifically that would greatly help others.

 

Thanks

Link to comment
Share on other sites

Prestashop 1.6.1.6

So:

if you put in product-list.tpl, the sort menu won`t work

 

so i found solution:

 

in: product-sort.tpl put: (like so)

tell me if it's working

 

 

<option value="{if $page_name != 'best-sales'}{$orderbydefault|escape:'html':'UTF-8'}:{$orderwaydefault|escape:'html':'UTF-8'}{/if}"{if !in_array($orderby, array('price', 'name', 'quantity', 'reference')) && $orderby eq $orderbydefault} selected="selected" <div style="display:none">{shuffle($products)}</div> {/if}--</option>

Link to comment
Share on other sites

×
×
  • Create New...