Answer the question
In order to leave comments, you need to log in
Displaying random products in OpenCart promotions?
Hello! Please tell me how to make on the promotions (special) page in OpenCart 3 so that the products are constantly random when the page is reloaded. In random order.
I have done this in categories and it works:
$filter_data = array(
'filter_category_id' => $category_id,
'filter_filter' => $filter,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit * 10
);
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
srand((float)microtime() * 1000000);
shuffle($results);
$results = array_slice($results, 0, $limit);
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question