в ..catalogmodelcatalogproduct.php
добавим функцию
public function getProductsRandom() { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1' ORDER BY RAND() LIMIT 2"); return $query->rows;}
в ..catalogcontrollercommonheader.php
$this->load->model('catalog/product');$results = $this->model_catalog_product->getProductsRandom();foreach ($results AS $result) { if ($result['image']) { $image = $result['image']; } else { $image = 'no_image.jpg'; } $this->data['products'][] = array( 'name' => $result['name'], 'model' => $result['model'], 'thumb' => $this->model_tool_image->resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')), 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']), );}
в ..catalogviewthemedefaulttemplatecommonheader.tpl
<div class="div7"> <?php if ($products) { ?> <table class="list"> <?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?> <tr> <?php for ($j = $i; $j < ($i + 4); $j++) { ?> <td width="25%"><?php if (isset($products[$j])) { ?> <a href="<?php echo $products[$j]['href']; ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" /></a> <a href="<?php echo $products[$j]['href']; ?>"><?php echo $products[$j]['name']; ?></a> [color= #999; font-size: 11px;]<?php echo $products[$j]['model']; ?>[/color] <?php } ?></td> <?php } ?> </tr> <?php } ?> </table> <?php } ?> </div>
для рандомной выборки используется ORDER BY RAND() , что при большом количестве товара (4-5 тысяч) будет, достаточно жестоко, напрягать базу данных, как оптимизировать можно найти кучу статей в интернете, но основной принцип работает =)